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?

Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66
jpop
  • 1,094
  • 1
  • 7
  • 19
  • see this https://groups.google.com/forum/m/#!topic/android-developers/pV20xJsSJI0 – pskink Mar 04 '14 at 09:20
  • 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 04 '14 at 09:42
  • read Dianne's answer again, this can help too http://code.google.com/p/android/issues/detail?id=13931 – pskink Mar 04 '14 at 09: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 04 '14 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 04 '14 at 10:12
  • Really didn't sound that clear to me. And the documentation doesn't mention anything about the API being obsolete or deprecated. It's still present in API 19 docs (http://developer.android.com/reference/android/view/MotionEvent.html#getEdgeFlags()). Ah well, guess I'll fall back to manually calculating edge touches. – jpop Mar 04 '14 at 10:38
  • of course you are right when it comes to docs: they are bad and poor, thats why issue 13931 was opened – pskink Mar 04 '14 at 10:48

1 Answers1

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.

Jeffrey
  • 1,998
  • 1
  • 25
  • 22