Merge "Cancelling back gesture in case of multi-touch and long press" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
86d6077214
@@ -121,8 +121,8 @@ public class EdgeBackGestureHandler implements DisplayListener {
|
|||||||
private final int mEdgeWidth;
|
private final int mEdgeWidth;
|
||||||
// The slop to distinguish between horizontal and vertical motion
|
// The slop to distinguish between horizontal and vertical motion
|
||||||
private final float mTouchSlop;
|
private final float mTouchSlop;
|
||||||
// Minimum distance to move so that is can be considerd as a back swipe
|
// Duration after which we consider the event as longpress.
|
||||||
private final float mSwipeThreshold;
|
private final int mLongPressTimeout;
|
||||||
// The threshold where the touch needs to be at most, such that the arrow is displayed above the
|
// The threshold where the touch needs to be at most, such that the arrow is displayed above the
|
||||||
// finger, otherwise it will be below
|
// finger, otherwise it will be below
|
||||||
private final int mMinArrowPosition;
|
private final int mMinArrowPosition;
|
||||||
@@ -164,8 +164,9 @@ public class EdgeBackGestureHandler implements DisplayListener {
|
|||||||
// TODO: Get this for the current user
|
// TODO: Get this for the current user
|
||||||
mEdgeWidth = res.getDimensionPixelSize(
|
mEdgeWidth = res.getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.config_backGestureInset);
|
com.android.internal.R.dimen.config_backGestureInset);
|
||||||
|
|
||||||
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||||
mSwipeThreshold = res.getDimension(R.dimen.navigation_edge_action_drag_threshold);
|
mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
|
||||||
|
|
||||||
mNavBarHeight = res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height);
|
mNavBarHeight = res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height);
|
||||||
mMinArrowPosition = res.getDimensionPixelSize(
|
mMinArrowPosition = res.getDimensionPixelSize(
|
||||||
@@ -308,8 +309,18 @@ public class EdgeBackGestureHandler implements DisplayListener {
|
|||||||
return !isInExcludedRegion;
|
return !isInExcludedRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cancelGesture(MotionEvent ev) {
|
||||||
|
// Send action cancel to reset all the touch events
|
||||||
|
mAllowGesture = false;
|
||||||
|
MotionEvent cancelEv = MotionEvent.obtain(ev);
|
||||||
|
cancelEv.setAction(MotionEvent.ACTION_CANCEL);
|
||||||
|
mEdgePanel.handleTouch(cancelEv);
|
||||||
|
cancelEv.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
private void onMotionEvent(MotionEvent ev) {
|
private void onMotionEvent(MotionEvent ev) {
|
||||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
int action = ev.getActionMasked();
|
||||||
|
if (action == MotionEvent.ACTION_DOWN) {
|
||||||
// Verify if this is in within the touch region and we aren't in immersive mode, and
|
// Verify if this is in within the touch region and we aren't in immersive mode, and
|
||||||
// either the bouncer is showing or the notification panel is hidden
|
// either the bouncer is showing or the notification panel is hidden
|
||||||
int stateFlags = mOverviewProxyService.getSystemUiStateFlags();
|
int stateFlags = mOverviewProxyService.getSystemUiStateFlags();
|
||||||
@@ -330,16 +341,20 @@ public class EdgeBackGestureHandler implements DisplayListener {
|
|||||||
mThresholdCrossed = false;
|
mThresholdCrossed = false;
|
||||||
}
|
}
|
||||||
} else if (mAllowGesture) {
|
} else if (mAllowGesture) {
|
||||||
if (!mThresholdCrossed && ev.getAction() == MotionEvent.ACTION_MOVE) {
|
if (!mThresholdCrossed) {
|
||||||
|
if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||||
|
// We do not support multi touch for back gesture
|
||||||
|
cancelGesture(ev);
|
||||||
|
return;
|
||||||
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||||
|
if ((ev.getEventTime() - ev.getDownTime()) > mLongPressTimeout) {
|
||||||
|
cancelGesture(ev);
|
||||||
|
return;
|
||||||
|
}
|
||||||
float dx = Math.abs(ev.getX() - mDownPoint.x);
|
float dx = Math.abs(ev.getX() - mDownPoint.x);
|
||||||
float dy = Math.abs(ev.getY() - mDownPoint.y);
|
float dy = Math.abs(ev.getY() - mDownPoint.y);
|
||||||
if (dy > dx && dy > mTouchSlop) {
|
if (dy > dx && dy > mTouchSlop) {
|
||||||
// Send action cancel to reset all the touch events
|
cancelGesture(ev);
|
||||||
mAllowGesture = false;
|
|
||||||
MotionEvent cancelEv = MotionEvent.obtain(ev);
|
|
||||||
cancelEv.setAction(MotionEvent.ACTION_CANCEL);
|
|
||||||
mEdgePanel.handleTouch(cancelEv);
|
|
||||||
cancelEv.recycle();
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if (dx > dy && dx > mTouchSlop) {
|
} else if (dx > dy && dx > mTouchSlop) {
|
||||||
@@ -349,10 +364,12 @@ public class EdgeBackGestureHandler implements DisplayListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// forward touch
|
// forward touch
|
||||||
mEdgePanel.handleTouch(ev);
|
mEdgePanel.handleTouch(ev);
|
||||||
|
|
||||||
boolean isUp = ev.getAction() == MotionEvent.ACTION_UP;
|
boolean isUp = action == MotionEvent.ACTION_UP;
|
||||||
if (isUp) {
|
if (isUp) {
|
||||||
boolean performAction = mEdgePanel.shouldTriggerBack();
|
boolean performAction = mEdgePanel.shouldTriggerBack();
|
||||||
if (performAction) {
|
if (performAction) {
|
||||||
@@ -363,7 +380,7 @@ public class EdgeBackGestureHandler implements DisplayListener {
|
|||||||
mOverviewProxyService.notifyBackAction(performAction, (int) mDownPoint.x,
|
mOverviewProxyService.notifyBackAction(performAction, (int) mDownPoint.x,
|
||||||
(int) mDownPoint.y, false /* isButton */, !mIsOnLeftEdge);
|
(int) mDownPoint.y, false /* isButton */, !mIsOnLeftEdge);
|
||||||
}
|
}
|
||||||
if (isUp || ev.getAction() == MotionEvent.ACTION_CANCEL) {
|
if (isUp || action == MotionEvent.ACTION_CANCEL) {
|
||||||
mRegionSamplingHelper.stop();
|
mRegionSamplingHelper.stop();
|
||||||
} else {
|
} else {
|
||||||
updateSamplingRect();
|
updateSamplingRect();
|
||||||
|
|||||||
Reference in New Issue
Block a user