Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving past events after clear FLAG_NOT_TOUCHABLE

Tags:

android

I have an activity in which I want to avoid the user touch buttons during a time.

I make this:

WindowManager.LayoutParams params = getWindow().getAttributes();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().setAttributes(params);

It works great, but when I come back to receive touch events with:

WindowManager.LayoutParams params = getWindow().getAttributes();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(params);

I receive all the events relatives to the user touchs during the period not touchable.

Any idea how to discard this events?

like image 841
jegumi Avatar asked Jan 27 '12 09:01

jegumi


1 Answers

I face the same problem but I come up with a workaround without messing up with window flag. Try this:

@Override
public boolean dispatchTouchEvent (MotionEvent ev){
    if(activityTouchable == false)return true;
    else return super.dispatchTouchEvent(ev);
}

@Override
public boolean dispatchKeyEvent (KeyEvent event){
    if(activityTouchable == false)return true;
    else return super.dispatchKeyEvent(event);
}
like image 130
Yeung Avatar answered Oct 05 '22 23:10

Yeung