From 4a4b7a80592896055727d25416b3f23092a43625 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Tue, 11 Jun 2024 14:17:20 -0700 Subject: [PATCH] Delay taskbar background fade in animation - Taskbar background will fade in based on 1. Velocity threshold 2. End target gesture destination Bug: 298089923 Bug: 345768019 Test: swipe up fast to go home, note no taskbar bg swipe up slow to reveal taskhome, note taskbar bg shows immediately Flag: com.android.launcher3.enable_scaling_reveal_home_animation DISABLED Change-Id: I2c16352e1c0c52a8afc49900a39b80383bacde62 --- quickstep/res/values/dimens.xml | 5 ++ .../taskbar/TaskbarActivityContext.java | 7 ++ .../launcher3/taskbar/TaskbarDragLayer.java | 7 +- .../taskbar/TaskbarStashController.java | 77 ++++++++++++++++++- .../taskbar/TaskbarUIController.java | 7 ++ .../android/quickstep/AbsSwipeUpHandler.java | 12 +++ .../TaskbarUnstashInputConsumer.java | 47 +++++++++++ 7 files changed, 158 insertions(+), 4 deletions(-) diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 08d36d8d87..44eb6a591d 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -384,6 +384,11 @@ 24dp + + + -288dp + 80 + 4.5 10 diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 0de0550016..487d9aad6b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -1405,6 +1405,13 @@ public class TaskbarActivityContext extends BaseTaskbarContext { mControllers.taskbarStashController.toggleTaskbarStash(); } + /** + * Plays the taskbar background alpha animation if one is not currently playing. + */ + public void playTaskbarBackgroundAlphaAnimation() { + mControllers.taskbarStashController.playTaskbarBackgroundAlphaAnimation(); + } + /** * Called to start the taskbar translation spring to its settled translation (0). */ diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java index 84874a9371..f703463117 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java @@ -18,6 +18,7 @@ package com.android.launcher3.taskbar; import static android.view.KeyEvent.ACTION_UP; import static android.view.KeyEvent.KEYCODE_BACK; +import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; import static com.android.launcher3.config.FeatureFlags.ENABLE_TASKBAR_NAVBAR_UNIFICATION; import android.content.Context; @@ -41,6 +42,7 @@ import com.android.app.viewcapture.ViewCaptureFactory; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; +import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.MultiPropertyFactory; import com.android.launcher3.util.MultiPropertyFactory.MultiProperty; import com.android.launcher3.views.BaseDragLayer; @@ -104,7 +106,10 @@ public class TaskbarDragLayer extends BaseDragLayer { mTaskbarBackgroundAlpha = new MultiPropertyFactory<>(this, BG_ALPHA, INDEX_COUNT, (a, b) -> a * b, 1f); mTaskbarBackgroundAlpha.get(INDEX_ALL_OTHER_STATES).setValue(0); - mTaskbarBackgroundAlpha.get(INDEX_STASH_ANIM).setValue(1); + mTaskbarBackgroundAlpha.get(INDEX_STASH_ANIM).setValue( + enableScalingRevealHomeAnimation() && DisplayController.isTransientTaskbar(context) + ? 0 + : 1); } public void init(TaskbarDragLayerController.TaskbarDragLayerCallbacks callbacks) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 74d2d60014..a9521aea72 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -22,6 +22,7 @@ import static com.android.app.animation.Interpolators.FINAL_FRAME; import static com.android.app.animation.Interpolators.INSTANT; import static com.android.app.animation.Interpolators.LINEAR; import static com.android.internal.jank.InteractionJankMonitor.Configuration; +import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; import static com.android.launcher3.config.FeatureFlags.ENABLE_TASKBAR_NAVBAR_UNIFICATION; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TRANSIENT_TASKBAR_HIDE; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TRANSIENT_TASKBAR_SHOW; @@ -40,6 +41,7 @@ import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_S import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; +import android.animation.ValueAnimator; import android.app.RemoteAction; import android.graphics.drawable.Icon; import android.os.SystemClock; @@ -239,6 +241,10 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba private final Alarm mTimeoutAlarm = new Alarm(); private boolean mEnableBlockingTimeoutDuringTests = false; + private Animator mTaskbarBackgroundAlphaAnimator; + private long mTaskbarBackgroundDuration; + private boolean mIsGoingHome; + // Evaluate whether the handle should be stashed private final LongPredicate mIsStashedPredicate = flags -> { boolean inApp = hasAnyFlag(flags, FLAGS_IN_APP); @@ -258,6 +264,8 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba mSystemUiProxy = SystemUiProxy.INSTANCE.get(activity); mAccessibilityManager = mActivity.getSystemService(AccessibilityManager.class); + mTaskbarBackgroundDuration = + activity.getResources().getInteger(R.integer.taskbar_background_duration); if (mActivity.isPhoneMode()) { mUnstashedHeight = mActivity.getResources().getDimensionPixelSize( R.dimen.taskbar_phone_size); @@ -752,9 +760,16 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba backgroundAndHandleAlphaStartDelay, backgroundAndHandleAlphaDuration, LINEAR); - play(as, mTaskbarBackgroundAlphaForStash.animateToValue(backgroundAlphaTarget), - backgroundAndHandleAlphaStartDelay, - backgroundAndHandleAlphaDuration, LINEAR); + if (enableScalingRevealHomeAnimation() && !isStashed) { + play(as, getTaskbarBackgroundAnimatorWhenNotGoingHome(duration), + 0, 0, LINEAR); + as.addListener(AnimatorListeners.forEndCallback( + () -> mTaskbarBackgroundAlphaForStash.setValue(backgroundAlphaTarget))); + } else { + play(as, mTaskbarBackgroundAlphaForStash.animateToValue(backgroundAlphaTarget), + backgroundAndHandleAlphaStartDelay, + backgroundAndHandleAlphaDuration, LINEAR); + } // The rest of the animations might be "skipped" in TRANSITION_HANDLE_FADE transitions. AnimatorSet skippable = as; @@ -797,6 +812,62 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba .setDuration(isStashed ? duration / 2 : duration)); } + private Animator getTaskbarBackgroundAnimatorWhenNotGoingHome(long duration) { + ValueAnimator a = ValueAnimator.ofFloat(0, 1); + a.setDuration(duration); + a.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + // This value is arbitrary. + private static final float ANIMATED_FRACTION_THRESHOLD = 0.25f; + private boolean mTaskbarBgAlphaAnimationStarted = false; + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + if (mIsGoingHome) { + mTaskbarBgAlphaAnimationStarted = true; + } + if (mTaskbarBgAlphaAnimationStarted) { + return; + } + + if (valueAnimator.getAnimatedFraction() >= ANIMATED_FRACTION_THRESHOLD) { + if (!mIsGoingHome) { + playTaskbarBackgroundAlphaAnimation(); + setUserIsGoingHome(false); + mTaskbarBgAlphaAnimationStarted = true; + } + } + } + }); + return a; + } + + /** + * Sets whether the user is going home based on the current gesture. + */ + public void setUserIsGoingHome(boolean isGoingHome) { + mIsGoingHome = isGoingHome; + } + + /** + * Plays the taskbar background alpha animation if one is not currently playing. + */ + public void playTaskbarBackgroundAlphaAnimation() { + if (mTaskbarBackgroundAlphaAnimator != null + && mTaskbarBackgroundAlphaAnimator.isRunning()) { + return; + } + mTaskbarBackgroundAlphaAnimator = mTaskbarBackgroundAlphaForStash + .animateToValue(1f) + .setDuration(mTaskbarBackgroundDuration); + mTaskbarBackgroundAlphaAnimator.setInterpolator(LINEAR); + mTaskbarBackgroundAlphaAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mTaskbarBackgroundAlphaAnimator = null; + } + }); + mTaskbarBackgroundAlphaAnimator.start(); + } + private static void play(AnimatorSet as, @Nullable Animator a, long startDelay, long duration, Interpolator interpolator) { if (a == null) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java index 2b68b52932..593285f062 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java @@ -411,4 +411,11 @@ public class TaskbarUIController { public void setSkipNextRecentsAnimEnd() { // Overridden } + + /** + * Sets whether the user is going home based on the current gesture. + */ + public void setUserIsGoingHome(boolean isGoingHome) { + mControllers.taskbarStashController.setUserIsGoingHome(isGoingHome); + } } diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 463222dfd0..5903a27bfa 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -32,6 +32,7 @@ import static com.android.launcher3.BaseActivity.INVISIBLE_BY_STATE_HANDLER; import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS; import static com.android.launcher3.Flags.enableAdditionalHomeAnimations; import static com.android.launcher3.Flags.enableGridOnlyOverview; +import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; import static com.android.launcher3.PagedView.INVALID_PAGE; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.IGNORE; @@ -1193,6 +1194,10 @@ public abstract class AbsSwipeUpHandler= NUM_MOTION_MOVE_THRESHOLD // Arbitrary value + && velocityYPxPerS != 0 // Ignore these + && velocityYPxPerS >= mTaskbarSlowVelocityYThreshold) { + mTaskbarActivityContext.playTaskbarBackgroundAlphaAnimation(); + mCanPlayTaskbarBgAlphaAnimation = false; + } + } + private void cleanupAfterMotionEvent() { mTaskbarActivityContext.setAutohideSuspendFlag( FLAG_AUTOHIDE_SUSPEND_TOUCHING, false); @@ -264,6 +304,13 @@ public class TaskbarUnstashInputConsumer extends DelegateInputConsumer { mIsInBubbleBarArea = false; mIsVerticalGestureOverBubbleBar = false; mIsPassedBubbleBarSlop = false; + + if (mVelocityTracker != null) { + mVelocityTracker.recycle(); + } + mVelocityTracker = null; + mCanPlayTaskbarBgAlphaAnimation = true; + mMotionMoveCount = 0; } private boolean isInBubbleBarArea(float x) {