From f3a59b59f4e28e25adbb98223761a1b69108954f Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 26 Oct 2022 09:39:26 -0700 Subject: [PATCH] Add app window thresholds for transient taskbar. - Threshold to move app window - Threshold to reach home/overview - Threshold for window to catch up to finger Bug: 252905206 Test: manual Change-Id: I71082fab07a0227d64ce6ed66cbfa3c1ffb319f5 --- quickstep/res/values/dimens.xml | 4 ++ .../taskbar/TaskbarUIController.java | 7 +++ .../android/quickstep/AbsSwipeUpHandler.java | 61 ++++++++++++++++--- .../quickstep/SwipeUpAnimationLogic.java | 3 + .../OtherActivityInputConsumer.java | 29 ++++++++- res/values/dimens.xml | 5 ++ 6 files changed, 101 insertions(+), 8 deletions(-) diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 45a2cf8423..c0765ee111 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -288,6 +288,10 @@ 24dp 40dp 10dp + + 150dp + 225dp + 300dp 24dp diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java index 49dba95151..9ec8cfeffa 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java @@ -97,6 +97,13 @@ public class TaskbarUIController { } } + /** + * Returns true iff taskbar is stashed. + */ + public boolean isTaskbarStashed() { + return mControllers.taskbarStashController.isStashed(); + } + @CallSuper protected void dumpLogs(String prefix, PrintWriter pw) { pw.println(String.format( diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index d4b713b2a8..603ab86559 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -64,6 +64,7 @@ import android.app.ActivityManager; import android.app.WindowConfiguration; import android.content.Context; import android.content.Intent; +import android.content.res.Resources; import android.graphics.Matrix; import android.graphics.PointF; import android.graphics.Rect; @@ -101,6 +102,7 @@ import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.tracing.InputConsumerProto; import com.android.launcher3.tracing.SwipeHandlerProto; import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter; +import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.TraceHelper; import com.android.launcher3.util.WindowBounds; import com.android.quickstep.BaseActivityInterface.AnimationFactory; @@ -311,6 +313,10 @@ public abstract class AbsSwipeUpHandler, // Interpolate RecentsView scale from start of quick switch scroll until this scroll threshold private final float mQuickSwitchScaleScrollThreshold; + private final int mTaskbarAppWindowThreshold; + private final int mTaskbarCatchUpThreshold; + private boolean mTaskbarAlreadyOpen; + public AbsSwipeUpHandler(Context context, RecentsAnimationDeviceState deviceState, TaskAnimationManager taskAnimationManager, GestureState gestureState, long touchTimeMs, boolean continuingLastGesture, @@ -331,11 +337,17 @@ public abstract class AbsSwipeUpHandler, mTaskAnimationManager = taskAnimationManager; mTouchTimeMs = touchTimeMs; mContinuingLastGesture = continuingLastGesture; - mQuickSwitchScaleScrollThreshold = context.getResources().getDimension( - R.dimen.quick_switch_scaling_scroll_threshold); - mSplashMainWindowShiftLength = -context.getResources().getDimensionPixelSize( - R.dimen.starting_surface_exit_animation_window_shift_length); + Resources res = context.getResources(); + mTaskbarAppWindowThreshold = res + .getDimensionPixelSize(R.dimen.taskbar_app_window_threshold); + mTaskbarCatchUpThreshold = res.getDimensionPixelSize(R.dimen.taskbar_catch_up_threshold); + + mQuickSwitchScaleScrollThreshold = res + .getDimension(R.dimen.quick_switch_scaling_scroll_threshold); + + mSplashMainWindowShiftLength = -res + .getDimensionPixelSize(R.dimen.starting_surface_exit_animation_window_shift_length); initAfterSubclassConstructor(); initStateCallbacks(); @@ -824,7 +836,7 @@ public abstract class AbsSwipeUpHandler, return; } mLauncherTransitionController.setProgress( - Math.max(mCurrentShift.value, getScaleProgressDueToScroll()), mDragLengthFactor); + Math.max(getTaskbarProgress(), getScaleProgressDueToScroll()), mDragLengthFactor); } /** @@ -1170,7 +1182,7 @@ public abstract class AbsSwipeUpHandler, } private boolean hasReachedOverviewThreshold() { - return mCurrentShift.value > MIN_PROGRESS_FOR_OVERVIEW; + return getTaskbarProgress() > MIN_PROGRESS_FOR_OVERVIEW; } @UiThread @@ -2196,7 +2208,7 @@ public abstract class AbsSwipeUpHandler, AnimatorControllerWithResistance playbackController = remoteHandle.getPlaybackController(); if (playbackController != null) { - playbackController.setProgress(Math.max(mCurrentShift.value, + playbackController.setProgress(Math.max(getTaskbarProgress(), getScaleProgressDueToScroll()), mDragLengthFactor); } @@ -2240,6 +2252,41 @@ public abstract class AbsSwipeUpHandler, return scaleProgress; } + /** + * Updates the current status of taskbar during this swipe. + */ + public void setTaskbarAlreadyOpen(boolean taskbarAlreadyOpen) { + mTaskbarAlreadyOpen = taskbarAlreadyOpen; + } + + /** + * Overrides the current shift progress to keep the app window at the bottom of the screen + * while the transient taskbar is being swiped in. + * + * There is also a catch up period so that the window can start moving 1:1 with the swipe. + */ + private float getTaskbarProgress() { + if (!DisplayController.isTransientTaskbar(mContext)) { + return mCurrentShift.value; + } + + if (mTaskbarAlreadyOpen) { + return mCurrentShift.value; + } + + if (mCurrentDisplacement < mTaskbarAppWindowThreshold) { + return 0; + } + + // "Catch up" with `mCurrentShift.value`. + if (mCurrentDisplacement < mTaskbarCatchUpThreshold) { + return Utilities.mapToRange(mCurrentDisplacement, mTaskbarAppWindowThreshold, + mTaskbarCatchUpThreshold, 0, mCurrentShift.value, ACCEL_DEACCEL); + } + + return mCurrentShift.value; + } + private void setDividerShown(boolean shown, boolean immediate) { if (mDividerAnimator != null) { mDividerAnimator.cancel(); diff --git a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java index f591a1cff6..ddb06ce858 100644 --- a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java +++ b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java @@ -65,6 +65,7 @@ public abstract class SwipeUpAnimationLogic implements // 1 => preview snapShot is completely aligned with the recents view and hotseat is completely // visible. protected final AnimatedFloat mCurrentShift = new AnimatedFloat(this::updateFinalShift); + protected float mCurrentDisplacement; // The distance needed to drag to reach the task size in recents. protected int mTransitionDragLength; @@ -116,6 +117,8 @@ public abstract class SwipeUpAnimationLogic implements public void updateDisplacement(float displacement) { // We are moving in the negative x/y direction displacement = -displacement; + mCurrentDisplacement = displacement; + float shift; if (displacement > mTransitionDragLength * mDragLengthFactor && mTransitionDragLength > 0) { shift = mDragLengthFactor; diff --git a/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java index 60d5ba4f01..9d269fbc9e 100644 --- a/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java +++ b/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java @@ -37,6 +37,7 @@ import android.annotation.TargetApi; import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; +import android.content.res.Resources; import android.graphics.PointF; import android.os.Build; import android.util.Log; @@ -48,13 +49,16 @@ import androidx.annotation.UiThread; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.taskbar.TaskbarUIController; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; import com.android.launcher3.tracing.InputConsumerProto; +import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.Preconditions; import com.android.launcher3.util.TraceHelper; import com.android.quickstep.AbsSwipeUpHandler; import com.android.quickstep.AbsSwipeUpHandler.Factory; +import com.android.quickstep.BaseActivityInterface; import com.android.quickstep.GestureState; import com.android.quickstep.InputConsumer; import com.android.quickstep.RecentsAnimationCallbacks; @@ -97,6 +101,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC private final CachedEventDispatcher mRecentsViewDispatcher = new CachedEventDispatcher(); private final InputMonitorCompat mInputMonitorCompat; private final InputEventReceiver mInputEventReceiver; + private final BaseActivityInterface mActivityInterface; private final AbsSwipeUpHandler.Factory mHandlerFactory; @@ -131,6 +136,10 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC // Might be displacement in X or Y, depending on the direction we are swiping from the nav bar. private float mStartDisplacement; + private final boolean mIsTransientTaskbar; + private final boolean mTaskbarAlreadyOpen; + private final int mTaskbarHomeOverviewThreshold; + public OtherActivityInputConsumer(Context base, RecentsAnimationDeviceState deviceState, TaskAnimationManager taskAnimationManager, GestureState gestureState, boolean isDeferredDownTarget, Consumer onCompleteCallback, @@ -142,6 +151,11 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC mTaskAnimationManager = taskAnimationManager; mGestureState = gestureState; mHandlerFactory = handlerFactory; + mActivityInterface = mGestureState.getActivityInterface(); + + Resources res = base.getResources(); + mTaskbarHomeOverviewThreshold = res + .getDimensionPixelSize(R.dimen.taskbar_home_overview_threshold); mMotionPauseDetector = new MotionPauseDetector(base, false, mNavBarPosition.isLeftEdge() || mNavBarPosition.isRightEdge() @@ -153,6 +167,10 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC mInputMonitorCompat = inputMonitorCompat; mInputEventReceiver = inputEventReceiver; + TaskbarUIController controller = mActivityInterface.getTaskbarController(); + mTaskbarAlreadyOpen = controller != null && !controller.isTaskbarStashed(); + mIsTransientTaskbar = DisplayController.isTransientTaskbar(base); + boolean continuingPreviousGesture = mTaskAnimationManager.isRecentsAnimationRunning(); mIsDeferredDownTarget = !continuingPreviousGesture && isDeferredDownTarget; @@ -279,6 +297,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC float upDist = -displacement; boolean passedSlop = squaredHypot(displacementX, displacementY) >= mSquaredTouchSlop; + if (!mPassedSlopOnThisGesture && passedSlop) { mPassedSlopOnThisGesture = true; } @@ -323,7 +342,13 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC } if (mDeviceState.isFullyGesturalNavMode()) { - mMotionPauseDetector.setDisallowPause(upDist < mMotionPauseMinDisplacement + float minDisplacement = mMotionPauseMinDisplacement; + + if (mIsTransientTaskbar && !mTaskbarAlreadyOpen) { + minDisplacement += mTaskbarHomeOverviewThreshold; + } + + mMotionPauseDetector.setDisallowPause(upDist < minDisplacement || isLikelyToStartNewTask); mMotionPauseDetector.addPosition(ev); mInteractionHandler.setIsLikelyToStartNewTask(isLikelyToStartNewTask); @@ -357,6 +382,8 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC // Notify the handler that the gesture has actually started mInteractionHandler.onGestureStarted(isLikelyToStartNewTask); + + mInteractionHandler.setTaskbarAlreadyOpen(mTaskbarAlreadyOpen); } private void startTouchTrackingForWindowAnimation(long touchTimeMs) { diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 0a28b6c62f..afdb0717b3 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -380,6 +380,11 @@ 0dp 0dp 0dp + + 0dp + 0dp + 0dp + 0dp 16dp