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
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 think10dp
will be enough) then return false (this will disable handling the event inSurfaceView
).So if a user will
swipe down
right from the top edge of the screen it would workProbably you will need to set up some bool variable and set it to true on
ACTION DOWN
inside that special area and release it onACTION_UP
and ACTION_CANCEL, then inside ofACTION_MOVE
if thisflag == true
then you need to return true because the special gesture is not finished yet.