Swipe to exit immersive mode is picked up by canvas touch events

251 views Asked by At

I have a SurfaceView that uses a canvas to render based on touch events. The activity also uses immersive mode to make it full screen.

The problem is that when the user swipes from the top of the screen to exit immersive mode, the swipe is picked up by the canvas.

How do I avoid these touch events from being processed in the canvas?

SurfaceView class

public class PEQSurfaceView extends SurfaceView implements 
SurfaceHolder.Callback
{

   @Override
   public void surfaceCreated(SurfaceHolder holder)
   {
       // make the GamePanel focusable so it can handle events
       requestFocus();
       setFocusable(true);
       setFocusableInTouchMode(true);
   }

   @Override
   public boolean onTouchEvent(MotionEvent event)
   {...}

The layout also has some standard controls on the side, and I noticed that these are also affected in the same way. I.e. the progress bars will progress if the swipe down touches them

1

There are 1 answers

1
Konstantin Volkov On

Not sure will it fits your expectations, but as a suggestion, I would do it that way:
1) leave some top area of the screen for out of immerse move gesture.
2) then in onTouchEvent method check Y coordinate if it is inside of that top area (I think 10dp will be enough) then return false (this will disable handling the event in SurfaceView).

So if a user will swipe down right from the top edge of the screen it would work

Probably you will need to set up some bool variable and set it to true on ACTION DOWN inside that special area and release it on ACTION_UP and ACTION_CANCEL, then inside of ACTION_MOVE if this flag == true then you need to return true because the special gesture is not finished yet.