Skip to content

Commit

Permalink
Improve content touch interception (Fixes GH-9)
Browse files Browse the repository at this point in the history
Instead of recursively enabling/disabling the content ViewGroup
when the drawer closes/opens, just do a simple check in
onInterceptTouchEvent to see if the touch needs to be
intercepted on an ACTION_UP event.

Also intercept ACTION_DOWN events when the drawer is in motion
and the event originated within the content ViewGroup.

Signed-off-by: Eddie Ringle <eddie@eringle.net>
  • Loading branch information
EddieRingle committed Apr 13, 2013
1 parent e7f795c commit 7283c60
Showing 1 changed file with 14 additions and 31 deletions.
Expand Up @@ -303,6 +303,10 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
mGestureStarted = true;
}

if (mDrawerMoving && mGestureStartX > mDecorOffsetX) {
return true;
}

/*
* We still want to return false here since we aren't positive we've got a gesture
* we want just yet.
Expand Down Expand Up @@ -340,17 +344,22 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
*/
return overcameSlop;
case MotionEvent.ACTION_UP:

mGestureStarted = false;

/*
* If we just tapped the right edge with the drawer open, close the drawer.
*/
if (mGestureStartX > mDrawerWidth && mDrawerOpened) {
closeDrawer();
mGestureStartX = mGestureCurrentX = -1;
mGestureStartY = mGestureCurrentY = -1;
return true;
} else {
mGestureStartX = mGestureCurrentX = -1;
mGestureStartY = mGestureCurrentY = -1;
return false;
}

mGestureStarted = false;
mGestureStartX = mGestureCurrentX = -1;
mGestureStartY = mGestureCurrentY = -1;
return false;
}

return false;
Expand Down Expand Up @@ -559,7 +568,6 @@ public void run() {
mScrollerHandler.post(new Runnable() {
@Override
public void run() {
enableDisableViewGroup(mDecorContent, false);
mDrawerCallbacks.onDrawerOpened();
}
});
Expand Down Expand Up @@ -606,7 +614,6 @@ public void run() {
mScrollerHandler.post(new Runnable() {
@Override
public void run() {
enableDisableViewGroup(mDecorContent, true);
mDrawerCallbacks.onDrawerClosed();
}
});
Expand Down Expand Up @@ -650,28 +657,4 @@ public void setSlideTarget(final int slideTarget) {
}

}

public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = viewGroup.getChildAt(i);
if (view.isFocusable()) {
view.setEnabled(enabled);
}
if (view instanceof ViewGroup) {
enableDisableViewGroup((ViewGroup) view, enabled);
} else if (view instanceof ListView) {
if (view.isFocusable()) {
view.setEnabled(enabled);
}
ListView listView = (ListView) view;
int listChildCount = listView.getChildCount();
for (int j = 0; j < listChildCount; j++) {
if (view.isFocusable()) {
listView.getChildAt(j).setEnabled(false);
}
}
}
}
}
}

0 comments on commit 7283c60

Please sign in to comment.