Fix TaskViewTouchController crash in seascape
Previously, we were using scroll direction POSITIVE as a catch all
to mean "up" but in seascape, we actually want NEGATIVE. Added
getUpDirection() to capture that. Tried to clarify the code a bit
by putting all the methods used solely by TaskViewTouchController
together with documentation. It's still pretty confusing and feels
redundant, but couldn't think of an obvious way to simplify.
Test: Swipe up and down on a task in all permutations of:
- 3 button mode
- Gesture navigation
- Portrait
- Landscape
- Seascape
- LTR
- RTL
- Home rotation allowed
- Home rotation disallowed
Fixes: 174009771
Fixes: 173567204
Change-Id: Id0f8d6f4365d888eb46182d8544d18206795dfb8
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
index 9729695..9a3a67f 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
@@ -18,8 +18,6 @@
import static com.android.launcher3.AbstractFloatingView.TYPE_ACCESSIBLE;
import static com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS;
import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_BOTH;
-import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_NEGATIVE;
-import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_POSITIVE;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -59,6 +57,8 @@
private AnimatorPlaybackController mCurrentAnimation;
private boolean mCurrentAnimationIsGoingUp;
+ private boolean mAllowGoingUp;
+ private boolean mAllowGoingDown;
private boolean mNoIntercept;
@@ -74,7 +74,7 @@
mRecentsView = activity.getOverviewPanel();
mIsRtl = Utilities.isRtl(activity.getResources());
SingleAxisSwipeDetector.Direction dir =
- mRecentsView.getPagedOrientationHandler().getOppositeSwipeDirection();
+ mRecentsView.getPagedOrientationHandler().getUpDownSwipeDirection();
mDetector = new SingleAxisSwipeDetector(activity, this, dir);
}
@@ -148,15 +148,24 @@
break;
}
mTaskBeingDragged = view;
+ int upDirection = mRecentsView.getPagedOrientationHandler()
+ .getUpDirection(mIsRtl);
if (!SysUINavigationMode.getMode(mActivity).hasGestures) {
// Don't allow swipe down to open if we don't support swipe up
// to enter overview.
- directionsToDetectScroll = DIRECTION_POSITIVE;
+ directionsToDetectScroll = upDirection;
+ mAllowGoingUp = true;
+ mAllowGoingDown = false;
} else {
// The task can be dragged up to dismiss it,
// and down to open if it's the current page.
- directionsToDetectScroll = i == mRecentsView.getCurrentPage()
- ? DIRECTION_BOTH : DIRECTION_POSITIVE;
+ mAllowGoingUp = true;
+ if (i == mRecentsView.getCurrentPage()) {
+ mAllowGoingDown = true;
+ directionsToDetectScroll = DIRECTION_BOTH;
+ } else {
+ directionsToDetectScroll = upDirection;
+ }
}
break;
}
@@ -189,9 +198,7 @@
// No need to init
return;
}
- int scrollDirections = mDetector.getScrollDirections();
- if (goingUp && ((scrollDirections & DIRECTION_POSITIVE) == 0)
- || !goingUp && ((scrollDirections & DIRECTION_NEGATIVE) == 0)) {
+ if ((goingUp && !mAllowGoingUp) || (!goingUp && !mAllowGoingDown)) {
// Trying to re-init in an unsupported direction.
return;
}
diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
index 1d7f747..f05f15e 100644
--- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
@@ -75,11 +75,6 @@
}
@Override
- public boolean isGoingUp(float displacement, boolean isRtl) {
- return isRtl ? displacement < 0 : displacement > 0;
- }
-
- @Override
public boolean isLayoutNaturalToLauncher() {
return false;
}
@@ -215,11 +210,6 @@
}
@Override
- public SingleAxisSwipeDetector.Direction getOppositeSwipeDirection() {
- return HORIZONTAL;
- }
-
- @Override
public int getPrimaryTranslationDirectionFactor() {
return -1;
}
@@ -229,11 +219,6 @@
}
@Override
- public int getTaskDragDisplacementFactor(boolean isRtl) {
- return isRtl ? 1 : -1;
- }
-
- @Override
public float getTaskMenuX(float x, View thumbnailView) {
return thumbnailView.getMeasuredWidth() + x;
}
@@ -261,6 +246,31 @@
lp.weight = 1;
}
+ /* ---------- The following are only used by TaskViewTouchHandler. ---------- */
+
+ @Override
+ public SingleAxisSwipeDetector.Direction getUpDownSwipeDirection() {
+ return HORIZONTAL;
+ }
+
+ @Override
+ public int getUpDirection(boolean isRtl) {
+ return isRtl ? SingleAxisSwipeDetector.DIRECTION_NEGATIVE
+ : SingleAxisSwipeDetector.DIRECTION_POSITIVE;
+ }
+
+ @Override
+ public boolean isGoingUp(float displacement, boolean isRtl) {
+ return isRtl ? displacement < 0 : displacement > 0;
+ }
+
+ @Override
+ public int getTaskDragDisplacementFactor(boolean isRtl) {
+ return isRtl ? 1 : -1;
+ }
+
+ /* -------------------- */
+
@Override
public ChildBounds getChildBounds(View child, int childStart, int pageCenter,
boolean layoutChild) {
diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java
index a9c50cd..b9acfa3 100644
--- a/src/com/android/launcher3/touch/PagedOrientationHandler.java
+++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java
@@ -75,10 +75,8 @@
int getCenterForPage(View view, Rect insets);
int getScrollOffsetStart(View view, Rect insets);
int getScrollOffsetEnd(View view, Rect insets);
- SingleAxisSwipeDetector.Direction getOppositeSwipeDirection();
int getPrimaryTranslationDirectionFactor();
int getSecondaryTranslationDirectionFactor();
- int getTaskDragDisplacementFactor(boolean isRtl);
ChildBounds getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild);
void setMaxScroll(AccessibilityEvent event, int maxScroll);
boolean getRecentsRtlSetting(Resources resources);
@@ -92,7 +90,6 @@
void delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y);
void scrollerStartScroll(OverScroller scroller, int newPosition);
void getCurveProperties(PagedView view, Rect insets, CurveProperties out);
- boolean isGoingUp(float displacement, boolean isRtl);
boolean isLayoutNaturalToLauncher();
float getTaskMenuX(float x, View thumbnailView);
float getTaskMenuY(float y, View thumbnailView);
@@ -101,6 +98,16 @@
void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp);
int getDistanceToBottomOfRect(DeviceProfile dp, Rect rect);
+ // The following are only used by TaskViewTouchHandler.
+ /** @return Either VERTICAL or HORIZONTAL. */
+ SingleAxisSwipeDetector.Direction getUpDownSwipeDirection();
+ /** @return Given {@link #getUpDownSwipeDirection()}, whether POSITIVE or NEGATIVE is up. */
+ int getUpDirection(boolean isRtl);
+ /** @return Whether the displacement is going towards the top of the screen. */
+ boolean isGoingUp(float displacement, boolean isRtl);
+ /** @return Either 1 or -1, a factor to multiply by so the animation goes the correct way. */
+ int getTaskDragDisplacementFactor(boolean isRtl);
+
/**
* Maps the velocity from the coordinate plane of the foreground app to that
* of Launcher's (which now will always be portrait)
diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
index 587e35a..3663b5f 100644
--- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
+++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
@@ -73,12 +73,6 @@
}
@Override
- public boolean isGoingUp(float displacement, boolean isRtl) {
- // Ignore rtl since it only affects X value displacement, Y displacement doesn't change
- return displacement < 0;
- }
-
- @Override
public boolean isLayoutNaturalToLauncher() {
return true;
}
@@ -212,11 +206,6 @@
}
@Override
- public SingleAxisSwipeDetector.Direction getOppositeSwipeDirection() {
- return VERTICAL;
- }
-
- @Override
public int getPrimaryTranslationDirectionFactor() {
return 1;
}
@@ -226,12 +215,6 @@
}
@Override
- public int getTaskDragDisplacementFactor(boolean isRtl) {
- // Ignore rtl since it only affects X value displacement, Y displacement doesn't change
- return 1;
- }
-
- @Override
public float getTaskMenuX(float x, View thumbnailView) {
return x;
}
@@ -257,6 +240,33 @@
// no-op, defaults are fine
}
+ /* ---------- The following are only used by TaskViewTouchHandler. ---------- */
+
+ @Override
+ public SingleAxisSwipeDetector.Direction getUpDownSwipeDirection() {
+ return VERTICAL;
+ }
+
+ @Override
+ public int getUpDirection(boolean isRtl) {
+ // Ignore rtl since it only affects X value displacement, Y displacement doesn't change
+ return SingleAxisSwipeDetector.DIRECTION_POSITIVE;
+ }
+
+ @Override
+ public boolean isGoingUp(float displacement, boolean isRtl) {
+ // Ignore rtl since it only affects X value displacement, Y displacement doesn't change
+ return displacement < 0;
+ }
+
+ @Override
+ public int getTaskDragDisplacementFactor(boolean isRtl) {
+ // Ignore rtl since it only affects X value displacement, Y displacement doesn't change
+ return 1;
+ }
+
+ /* -------------------- */
+
@Override
public ChildBounds getChildBounds(View child, int childStart, int pageCenter,
boolean layoutChild) {
diff --git a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
index 60d19d9..54af029 100644
--- a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
@@ -16,6 +16,8 @@
package com.android.launcher3.touch;
+import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
+
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.Rect;
@@ -33,11 +35,6 @@
}
@Override
- public int getTaskDragDisplacementFactor(boolean isRtl) {
- return isRtl ? -1 : 1;
- }
-
- @Override
public boolean getRecentsRtlSetting(Resources resources) {
return Utilities.isRtl(resources);
}
@@ -53,11 +50,6 @@
}
@Override
- public boolean isGoingUp(float displacement, boolean isRtl) {
- return isRtl ? displacement > 0 : displacement < 0;
- }
-
- @Override
public void adjustFloatingIconStartVelocity(PointF velocity) {
float oldX = velocity.x;
float oldY = velocity.y;
@@ -78,4 +70,29 @@
public int getDistanceToBottomOfRect(DeviceProfile dp, Rect rect) {
return dp.widthPx - rect.right;
}
+
+ /* ---------- The following are only used by TaskViewTouchHandler. ---------- */
+
+ @Override
+ public SingleAxisSwipeDetector.Direction getUpDownSwipeDirection() {
+ return HORIZONTAL;
+ }
+
+ @Override
+ public int getUpDirection(boolean isRtl) {
+ return isRtl ? SingleAxisSwipeDetector.DIRECTION_POSITIVE
+ : SingleAxisSwipeDetector.DIRECTION_NEGATIVE;
+ }
+
+ @Override
+ public boolean isGoingUp(float displacement, boolean isRtl) {
+ return isRtl ? displacement > 0 : displacement < 0;
+ }
+
+ @Override
+ public int getTaskDragDisplacementFactor(boolean isRtl) {
+ return isRtl ? -1 : 1;
+ }
+
+ /* -------------------- */
}
diff --git a/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java b/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java
index 875eefb..ddb4b0f 100644
--- a/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java
+++ b/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java
@@ -60,6 +60,11 @@
return direction.x;
}
+ @NonNull
+ @Override
+ public String toString() {
+ return "VERTICAL";
+ }
};
public static final Direction HORIZONTAL = new Direction() {
@@ -86,6 +91,11 @@
return direction.y;
}
+ @NonNull
+ @Override
+ public String toString() {
+ return "HORIZONTAL";
+ }
};
private final Direction mDir;
@@ -117,10 +127,6 @@
mIgnoreSlopWhenSettling = ignoreSlop;
}
- public int getScrollDirections() {
- return mScrollDirections;
- }
-
/**
* Returns if the start drag was towards the positive direction or negative.
*