From 308851d866c7f4f769d6e3819666b5a46a0493e3 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Thu, 9 Sep 2021 21:18:25 -0700 Subject: [PATCH] Stash the bar after settling in Overview Test: https://recall.googleplex.com/projects/81822932-8526-4ee7-b5f7-4ef6d6603f1d/sessions/f0f7a3db-76b6-4f60-87e8-8918bd6cf180 Bug: 193938970 Change-Id: Ic08d3156f5c78a34f353783b760d5cf098e442e8 --- .../taskbar/LauncherTaskbarUIController.java | 39 ++++++++++++++----- .../taskbar/TaskbarStashController.java | 34 +++++++++++++--- .../uioverrides/states/OverviewState.java | 5 +++ src/com/android/launcher3/LauncherState.java | 4 ++ 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java index 359f436218..68dfac72eb 100644 --- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java @@ -19,10 +19,12 @@ import static com.android.launcher3.LauncherState.HOTSEAT_ICONS; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_HIDE; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_SHOW; import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_APP; +import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_STASHED_LAUNCHER_STATE; import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_HOME; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.graphics.Rect; import android.view.MotionEvent; @@ -42,6 +44,7 @@ import com.android.launcher3.logging.InstanceId; import com.android.launcher3.logging.InstanceIdSequence; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; +import com.android.launcher3.statemanager.StateManager; import com.android.launcher3.util.MultiValueAlpha; import com.android.launcher3.util.MultiValueAlpha.AlphaProperty; import com.android.launcher3.util.OnboardingPrefs; @@ -76,6 +79,16 @@ public class LauncherTaskbarUIController extends TaskbarUIController { private final DeviceProfile.OnDeviceProfileChangeListener mOnDeviceProfileChangeListener = this::onStashedInAppChanged; + private final StateManager.StateListener mStateListener = + new StateManager.StateListener() { + @Override + public void onStateTransitionComplete(LauncherState finalState) { + TaskbarStashController controller = mControllers.taskbarStashController; + controller.updateStateForFlag(FLAG_IN_STASHED_LAUNCHER_STATE, + finalState.isTaskbarStashed()); + } + }; + // Initialized in init. private TaskbarControllers mControllers; private AnimatedFloat mTaskbarBackgroundAlpha; @@ -118,6 +131,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { onStashedInAppChanged(mLauncher.getDeviceProfile()); mLauncher.addOnDeviceProfileChangeListener(mOnDeviceProfileChangeListener); + mLauncher.getStateManager().addStateListener(mStateListener); } @Override @@ -127,6 +141,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { mIconAlignmentForGestureState.finishAnimation(); mLauncher.removeOnDeviceProfileChangeListener(mOnDeviceProfileChangeListener); + mLauncher.getStateManager().removeStateListener(mStateListener); mLauncher.getHotseat().setIconsAlpha(1f); mLauncher.setTaskbarUIController(null); } @@ -184,24 +199,28 @@ public class LauncherTaskbarUIController extends TaskbarUIController { */ public Animator createAnimToLauncher(@NonNull LauncherState toState, @NonNull RecentsAnimationCallbacks callbacks, long duration) { + AnimatorSet animatorSet = new AnimatorSet(); TaskbarStashController stashController = mControllers.taskbarStashController; - ObjectAnimator animator = mIconAlignmentForGestureState - .animateToValue(1) - .setDuration(duration); - animator.addListener(new AnimatorListenerAdapter() { + stashController.updateStateForFlag(FLAG_IN_STASHED_LAUNCHER_STATE, + toState.isTaskbarStashed()); + if (toState.isTaskbarStashed()) { + animatorSet.play(stashController.applyStateWithoutStart(duration)); + } else { + animatorSet.play(mIconAlignmentForGestureState + .animateToValue(1) + .setDuration(duration)); + } + animatorSet.addListener(new AnimatorListenerAdapter() { @Override - public void onAnimationEnd(Animator animation) { + public void onAnimationEnd(Animator animator) { mTargetStateOverride = null; animator.removeListener(this); } @Override - public void onAnimationStart(Animator animation) { + public void onAnimationStart(Animator animator) { mTargetStateOverride = toState; mIsAnimatingToLauncherViaGesture = true; - // TODO: FLAG_IN_APP might be sufficient for now, but in the future we do want to - // add another flag for LauncherState as well. We will need to decide whether to - // show hotseat or the task bar. stashController.updateStateForFlag(FLAG_IN_APP, false); stashController.applyState(duration); } @@ -215,7 +234,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { callbacks.removeListener(listener); }); - return animator; + return animatorSet; } private float getCurrentIconAlignmentRatio() { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index fc277cc1c3..a9ff03bdac 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -41,6 +41,7 @@ public class TaskbarStashController { public static final int FLAG_IN_APP = 1 << 0; public static final int FLAG_STASHED_IN_APP = 1 << 1; + public static final int FLAG_IN_STASHED_LAUNCHER_STATE = 1 << 2; /** * How long to stash/unstash when manually invoked via long press. @@ -83,9 +84,6 @@ public class TaskbarStashController { private final int mStashedHeight; private final int mUnstashedHeight; - private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder( - flags -> (((flags & FLAG_IN_APP) != 0) && (flags & FLAG_STASHED_IN_APP) != 0)); - // Initialized in init. private TaskbarControllers mControllers; // Taskbar background properties. @@ -106,6 +104,18 @@ public class TaskbarStashController { private @Nullable AnimatorSet mAnimator; + // Evaluate whether the handle should be stashed + private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder( + flags -> { + if (!supportsStashing()) { + return false; + } + boolean inApp = (flags & FLAG_IN_APP) != 0; + boolean stashedInApp = (flags & FLAG_STASHED_IN_APP) != 0; + boolean stashedLauncherState = (flags & FLAG_IN_STASHED_LAUNCHER_STATE) != 0; + return (inApp && stashedInApp) || (!inApp && stashedLauncherState); + }); + public TaskbarStashController(TaskbarActivityContext activity) { mActivity = activity; mPrefs = Utilities.getPrefs(mActivity); @@ -331,7 +341,15 @@ public class TaskbarStashController { } public void applyState(long duration) { - mStatePropertyHolder.setState(mState, duration); + mStatePropertyHolder.setState(mState, duration, true); + } + + public Animator applyStateWithoutStart() { + return applyStateWithoutStart(TASKBAR_STASH_DURATION); + } + + public Animator applyStateWithoutStart(long duration) { + return mStatePropertyHolder.setState(mState, duration, false); } /** @@ -360,12 +378,16 @@ public class TaskbarStashController { mStashCondition = stashCondition; } - public void setState(int flags, long duration) { + public Animator setState(int flags, long duration, boolean start) { boolean isStashed = mStashCondition.test(flags); if (mIsStashed != isStashed) { mIsStashed = isStashed; - createAnimToIsStashed(mIsStashed, duration).start(); + Animator animator = createAnimToIsStashed(mIsStashed, duration); + if (start) { + animator.start(); + } } + return mAnimator; } } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java index 1302ac00af..d396018d35 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java @@ -96,6 +96,11 @@ public class OverviewState extends LauncherState { return CLEAR_ALL_BUTTON | OVERVIEW_ACTIONS; } + @Override + public boolean isTaskbarStashed() { + return true; + } + @Override public int getWorkspaceScrimColor(Launcher launcher) { return Themes.getAttrColor(launcher, R.attr.overviewScrimColor); diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index 7985ab5ad3..15378e0ab9 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -197,6 +197,10 @@ public abstract class LauncherState implements BaseState { return (getVisibleElements(launcher) & elements) == elements; } + public boolean isTaskbarStashed() { + return false; + } + /** * Fraction shift in the vertical translation UI and related properties *