0

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

behelit
  • 1,765
  • 2
  • 20
  • 34
  • 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 user will swipe down right from the top edge of the screen it would work – Konstantin Volkov Oct 01 '18 at 11:59
  • Thanks for the suggestion but it's not really suitable for this application unfortunately. The canvas requires as much space as possible, and touch events need to be able to go to the full height of the screen. – behelit Oct 01 '18 at 12:07

1 Answers1

0

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.

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
  • Thanks for the suggestion but it's not really suitable for this application unfortunately. The canvas requires as much space as possible, and touch events need to be able to go to the full height of the screen. – behelit Oct 04 '18 at 07:09