How to detect edges on the screen of an Android phone to control touch?

I implement GestureDetector.OnGestureListenerin an Activity whose overridden onTouchEvent is:

public boolean onTouchEvent(MotionEvent event) {
       //gestureDetector is new GestureDetector(this,this) in Activity onCreate()
       this.gestureDetector.onTouchEvent(event);
       return super.onTouchEvent(event);
    }

Using getEdgeFlags from the MotionEvent class to detect an edge as follows:

 @Override
public boolean onDown(MotionEvent e) {
    final int edgeInfo = e.getEdgeFlags();
    return ((edgeInfo == MotionEvent.EDGE_LEFT) || (edgeInfo == MotionEvent.EDGE_RIGHT)) ||
            (edgeInfo == MotionEvent.EDGE_BOTTOM);
}

But onDown always returns false. I also tried to change

final int edgeInfo = e.getEdgeFlags(); to
 final int edgeInfo = e.getAction() & e.getEdgeFlags();

as well as final int edgeInfo = e.getActionMasked() & e.getEdgeFlags();in the case.

But take advantage of no advantage.

I saw this question and this one more relevant to me , but I found that only

  • Only some old phones return a non-zero value
  • I have to do it myself.

Am I using the API incorrectly?

Is there a better alternative to getEdgeFlags ()?

Even if onDown returns false, in logcat, I still see how other methods are started GestureDetector.OnGestureListener, Why?

, .

+4

Source: https://habr.com/ru/post/1619841/


All Articles