diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java index 97296957fe..9a3a67f859 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 @@ package com.android.launcher3.uioverrides.touchcontrollers; 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 @@ public abstract class TaskViewTouchController private AnimatorPlaybackController mCurrentAnimation; private boolean mCurrentAnimationIsGoingUp; + private boolean mAllowGoingUp; + private boolean mAllowGoingDown; private boolean mNoIntercept; @@ -74,7 +74,7 @@ public abstract class TaskViewTouchController 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 @@ public abstract class TaskViewTouchController 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 @@ public abstract class TaskViewTouchController // 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 1d7f747c02..f05f15e01d 100644 --- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java @@ -74,11 +74,6 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { out.screenCenter = insets.top + view.getPaddingTop() + out.scroll + out.halfPageSize; } - @Override - public boolean isGoingUp(float displacement, boolean isRtl) { - return isRtl ? displacement < 0 : displacement > 0; - } - @Override public boolean isLayoutNaturalToLauncher() { return false; @@ -214,11 +209,6 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { return view.getHeight() - view.getPaddingBottom() - insets.bottom; } - @Override - public SingleAxisSwipeDetector.Direction getOppositeSwipeDirection() { - return HORIZONTAL; - } - @Override public int getPrimaryTranslationDirectionFactor() { return -1; @@ -228,11 +218,6 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { return 1; } - @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 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { 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 a9c50cdffc..b9acfa3ca8 100644 --- a/src/com/android/launcher3/touch/PagedOrientationHandler.java +++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java @@ -75,10 +75,8 @@ public interface PagedOrientationHandler { 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 @@ public interface PagedOrientationHandler { 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 @@ public interface PagedOrientationHandler { 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 587e35ad6c..3663b5fcd3 100644 --- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java +++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java @@ -72,12 +72,6 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { out.screenCenter = insets.left + view.getPaddingLeft() + out.scroll + out.halfPageSize; } - @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; @@ -211,11 +205,6 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { return view.getWidth() - view.getPaddingRight() - insets.right; } - @Override - public SingleAxisSwipeDetector.Direction getOppositeSwipeDirection() { - return VERTICAL; - } - @Override public int getPrimaryTranslationDirectionFactor() { return 1; @@ -225,12 +214,6 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { return -1; } - @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 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { // 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 60d19d9beb..54af029266 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; @@ -32,11 +34,6 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { return -1; } - @Override - public int getTaskDragDisplacementFactor(boolean isRtl) { - return isRtl ? -1 : 1; - } - @Override public boolean getRecentsRtlSetting(Resources resources) { return Utilities.isRtl(resources); @@ -52,11 +49,6 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { return Surface.ROTATION_270; } - @Override - public boolean isGoingUp(float displacement, boolean isRtl) { - return isRtl ? displacement > 0 : displacement < 0; - } - @Override public void adjustFloatingIconStartVelocity(PointF velocity) { float oldX = velocity.x; @@ -78,4 +70,29 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { 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 875eefbc58..ddb4b0f6ea 100644 --- a/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java +++ b/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java @@ -60,6 +60,11 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { return direction.x; } + @NonNull + @Override + public String toString() { + return "VERTICAL"; + } }; public static final Direction HORIZONTAL = new Direction() { @@ -86,6 +91,11 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { return direction.y; } + @NonNull + @Override + public String toString() { + return "HORIZONTAL"; + } }; private final Direction mDir; @@ -117,10 +127,6 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { mIgnoreSlopWhenSettling = ignoreSlop; } - public int getScrollDirections() { - return mScrollDirections; - } - /** * Returns if the start drag was towards the positive direction or negative. *