Skip to content Skip to sidebar Skip to footer

Lock Ontouch Listener

I want to lock the ontouch listener when the animation is being played. this is my code. public class MainActivity extends Activity implements OnTouchListener { boolean gifIsPl

Solution 1:

You can try the following if you know the GIF's running time:

Declare a global boolean variable:

boolean gifIsPlaying;
longPLAYING_TIME_OF_GIF= ???;

After creating and adding GIFWebView to your activity's view, set gifIsPlaying to true. Delayed-post a Runnable to set gifIsPlaying to false after PLAYING_TIME_OF_GIF:

gifIsPlaying = true;

new Handler().postDelayed(new Runnable() {
    publicvoidrun() {
        gifIsPlaying = false;
    }
}, PLAYING_TIME_OF_GIF);

PLAYING_TIME_OF_GIF will be a long variable.

Inside your onTouch(View, MotionEvent):

publicbooleanonTouch(View v, MotionEvent event) {
    if (gifIsPlaying) {
        // No response to touch events
    } else {
        // Respond to touch eventsGIFWebView view1 = newGIFWebView
                (this, "file:///android_asset/imageedit_ball.gif");

        gifIsPlaying = true;

        newHandler().postDelayed(newRunnable() {
            publicvoidrun() {
                gifIsPlaying = false;
            }
        }, PLAYING_TIME_OF_GIF);

        setContentView(view1);
    }

    // Consume touch eventreturntrue;
}

If this approach works for you, consider creating a Handler once and reusing it. Same goes for the Runnable.

I don't think there's any other way to solve this problem. There certainly isn't a callback method to inform you that the GIF has run its course.

Post a Comment for "Lock Ontouch Listener"