Passing right swipes through to custom content
-> Right swipes must follow page settle by >= 200 ms.
Change-Id: Ie5a5ae36e63f28736599a8a846570949447f7a03
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 254bf00..859afa4 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -103,6 +103,10 @@
boolean mDrawBackground = true;
private float mBackgroundAlpha = 0;
+ private static final long CUSTOM_CONTENT_GESTURE_DELAY = 200;
+ private long mTouchDownTime = -1;
+ private long mCustomContentShowTime = -1;
+
private LayoutTransition mLayoutTransition;
private final WallpaperManager mWallpaperManager;
private IBinder mWindowToken;
@@ -819,6 +823,7 @@
case MotionEvent.ACTION_DOWN:
mXDown = ev.getX();
mYDown = ev.getY();
+ mTouchDownTime = System.currentTimeMillis();
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
@@ -859,18 +864,28 @@
protected void determineScrollingStart(MotionEvent ev) {
if (!isFinishedSwitchingState()) return;
- float deltaX = Math.abs(ev.getX() - mXDown);
- float deltaY = Math.abs(ev.getY() - mYDown);
+ float deltaX = ev.getX() - mXDown;
+ float absDeltaX = Math.abs(deltaX);
+ float absDeltaY = Math.abs(ev.getY() - mYDown);
- if (Float.compare(deltaX, 0f) == 0) return;
+ if (Float.compare(absDeltaX, 0f) == 0) return;
- float slope = deltaY / deltaX;
+ float slope = absDeltaY / absDeltaX;
float theta = (float) Math.atan(slope);
- if (deltaX > mTouchSlop || deltaY > mTouchSlop) {
+ if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
cancelCurrentPageLongPress();
}
+ boolean passRightSwipesToCustomContent =
+ (mTouchDownTime - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY;
+
+ if (deltaX > 0 && getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID
+ && passRightSwipesToCustomContent) {
+ // Pass swipes to the right to the custom content page.
+ return;
+ }
+
if (theta > MAX_SWIPE_ANGLE) {
// Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace
return;
@@ -961,6 +976,7 @@
mCustomContentShowing = true;
if (mCustomContentCallbacks != null) {
mCustomContentCallbacks.onShow();
+ mCustomContentShowTime = System.currentTimeMillis();
}
} else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) {
mCustomContentShowing = false;