4

Why can't I get getEdgeFlags() to ever detect edge touches?

I extended DrawerLayout, and then did:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
    int edgeFlags = ev.getEdgeFlags();
    Log.d(TAG,String.valueOf(edgeFlags));

    if ((MotionEvent.EDGE_LEFT&edgeFlags)!=0 || (MotionEvent.EDGE_RIGHT&edgeFlags)!=0)
        Log.d(TAG,"BEZEL intercept.");
    else
        Log.d(TAG,"Regular intercept.");
    return super.onInterceptTouchEvent(ev);
}

I never get any edge detected, edgeFlags is always 0.

Tested on G2 with 4.4.2, S3 with 4.3.1 and emulated S4 with 4.2.2. I am aware that only ACTION_DOWN touches get edge detection, but I don't get any detected, ever. Still, the drawer layout obviously manages to detect it since it opens the drawer on edge swipe just fine. I get the same (lack of) results with subclassing ViewPager too. Overriding onTouchEvent() method doesn't help either.

What am I doing wrong?

7
  • 1
    Not really helpful (also, note that forum post is over 4 years old). 'Edges' are defined as 1/10th of screen width or 16dp (whichever is smaller). I can initiate touch that close on the emulator with no problem, and still get no edge detect.
    – jpop
    Mar 4, 2014 at 9:42
  • read Dianne's answer again, this can help too code.google.com/p/android/issues/detail?id=13931
    – pskink
    Mar 4, 2014 at 9:49
  • 1
    I have found and read that article before posting here, and it isn't helpful. Again, it refers to digitizers not being able to detect touches near the edge, which is not an issue here (I can click the very first pixel on the emulator). And, also, it is a bug apparently present only on pre-4.0 devices. I tested on 4.2, 4.3 and 4.4 Androids.
    – jpop
    Mar 4, 2014 at 10:06
  • 1
    it clearly states that edge flags are only set for some historic, ancient devices whose touch screens had problems with accurate event detecting when touched close to the edge
    – pskink
    Mar 4, 2014 at 10:12

1 Answer 1

0

With some hardware it is too difficult to detect a touch at the edge of the display so Android is supposed to set the appropriate flag for you. This does not always happen so you should not rely on the edge flags being set properly. One option is to use the actual screen pixel height and width and the x,y coordinates returned from the MotionEvent. See How to detect touch within a portion of the screen.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.