Update taskbar resume alignment anim if launcher state changes in the middle
One way to reproduce this issue is to run `adb shell input keyevent KEYCODE_HOME`, which happens to pause and immediately resume launcher. For example, let's say we run this while in All Apps. Because the isResumed=true comes before the state transition to Normal, we behave as if we are still going to All Apps, specifically goingToUnstashedState = false (since we stash in All Apps). To fix this, we now listen to state changes while the resume alignment animation is playing, and update it if necessary.
Also did the same correction for the gesture alignment animation, though I don't have a specific repo for that.
Finally, because there are now more triggers for alignment animations to play, we add a check to only play them if it's not animating to the same value it's already animating towards. One notable experience this improves is swiping down from All Apps to home; if you do it quick enough, the state animation ends before the taskbar unstash animation, and thus the unstash animation would cancel and start again with the full duration, making it look laggy/disjointed (this behavior existed before this change as well).
Test: TaplTestsQuickstep
Test: Go to All Apps, run `adb shell input keyevent KEYCODE_HOME`, open an app and ensure taskbar icons are visible
Test: Quick switch from home when taskbar is present in apps, but instead go to overview; ensure no jump when taskbar stashes
Test: Swipe down quickly from All Apps, ensure taskbar unstashing doesn't slow down when reaching the end of the state transition
Fixes: 214562370
Change-Id: Ie0c6140e14186e41c7e4748dc745f87349b084fe
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
index a654a56..30f2073 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
@@ -208,51 +208,83 @@
private Animator onStateChangeApplied(int changedFlags, long duration, boolean start) {
AnimatorSet animatorSet = new AnimatorSet();
- if (hasAnyFlag(changedFlags, FLAG_RESUMED)) {
+
+ // Add the state animation first to ensure FLAG_IN_STASHED_LAUNCHER_STATE is set and we can
+ // determine whether goingToUnstashedLauncherStateChanged.
+ boolean wasGoingToUnstashedLauncherState = goingToUnstashedLauncherState();
+ if (hasAnyFlag(changedFlags, FLAG_TRANSITION_STATE_RUNNING)) {
+ boolean committed = !hasAnyFlag(FLAG_TRANSITION_STATE_RUNNING);
+ playStateTransitionAnim(animatorSet, duration, committed);
+
+ if (committed && mLauncherState == LauncherState.QUICK_SWITCH) {
+ // We're about to be paused, set immediately to ensure seamless handoff.
+ updateStateForFlag(FLAG_RESUMED, false);
+ applyState(0 /* duration */);
+ }
+ }
+ boolean goingToUnstashedLauncherStateChanged = wasGoingToUnstashedLauncherState
+ != goingToUnstashedLauncherState();
+
+ boolean launcherStateChangedDuringAnimToResumeAlignment =
+ mIconAlignmentForResumedState.isAnimating() && goingToUnstashedLauncherStateChanged;
+ if (hasAnyFlag(changedFlags, FLAG_RESUMED)
+ || launcherStateChangedDuringAnimToResumeAlignment) {
boolean isResumed = isResumed();
- ObjectAnimator anim = mIconAlignmentForResumedState
- .animateToValue(isResumed && goingToUnstashedLauncherState()
- ? 1 : 0)
- .setDuration(duration);
+ float toAlignmentForResumedState = isResumed && goingToUnstashedLauncherState() ? 1 : 0;
+ // If we're already animating to the value, just leave it be instead of restarting it.
+ if (!mIconAlignmentForResumedState.isAnimatingToValue(toAlignmentForResumedState)) {
+ ObjectAnimator resumeAlignAnim = mIconAlignmentForResumedState
+ .animateToValue(toAlignmentForResumedState)
+ .setDuration(duration);
- anim.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mIsAnimatingToLauncherViaResume = false;
- }
+ resumeAlignAnim.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mIsAnimatingToLauncherViaResume = false;
+ }
- @Override
- public void onAnimationStart(Animator animation) {
- mIsAnimatingToLauncherViaResume = isResumed;
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mIsAnimatingToLauncherViaResume = isResumed;
- TaskbarStashController stashController = mControllers.taskbarStashController;
- stashController.updateStateForFlag(FLAG_IN_APP, !isResumed);
- stashController.applyState(duration);
- }
- });
- animatorSet.play(anim);
+ TaskbarStashController stashController =
+ mControllers.taskbarStashController;
+ stashController.updateStateForFlag(FLAG_IN_APP, !isResumed);
+ stashController.applyState(duration);
+ }
+ });
+ animatorSet.play(resumeAlignAnim);
+ }
}
- if (hasAnyFlag(changedFlags, FLAG_RECENTS_ANIMATION_RUNNING)) {
- boolean isRecentsAnimationRunning = isRecentsAnimationRunning();
- Animator animator = mIconAlignmentForGestureState
- .animateToValue(isRecentsAnimationRunning && goingToUnstashedLauncherState()
- ? 1 : 0);
- if (isRecentsAnimationRunning) {
- animator.setDuration(duration);
- }
- animator.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mIsAnimatingToLauncherViaGesture = false;
- }
- @Override
- public void onAnimationStart(Animator animation) {
- mIsAnimatingToLauncherViaGesture = isRecentsAnimationRunning();
+ boolean launcherStateChangedDuringAnimToGestureAlignment =
+ mIconAlignmentForGestureState.isAnimating() && goingToUnstashedLauncherStateChanged;
+ if (hasAnyFlag(changedFlags, FLAG_RECENTS_ANIMATION_RUNNING)
+ || launcherStateChangedDuringAnimToGestureAlignment) {
+ boolean isRecentsAnimationRunning = isRecentsAnimationRunning();
+ float toAlignmentForGestureState = isRecentsAnimationRunning
+ && goingToUnstashedLauncherState() ? 1 : 0;
+ // If we're already animating to the value, just leave it be instead of restarting it.
+ if (!mIconAlignmentForGestureState.isAnimatingToValue(toAlignmentForGestureState)) {
+ Animator gestureAlignAnim = mIconAlignmentForGestureState
+ .animateToValue(toAlignmentForGestureState);
+ if (isRecentsAnimationRunning) {
+ gestureAlignAnim.setDuration(duration);
}
- });
- animatorSet.play(animator);
+ gestureAlignAnim.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mIsAnimatingToLauncherViaGesture = false;
+ }
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mIsAnimatingToLauncherViaGesture = isRecentsAnimationRunning();
+ }
+ });
+ animatorSet.play(gestureAlignAnim);
+ }
}
if (hasAnyFlag(changedFlags, FLAG_RESUMED | FLAG_RECENTS_ANIMATION_RUNNING)) {
@@ -265,17 +297,6 @@
.setDuration(duration));
}
- if (hasAnyFlag(changedFlags, FLAG_TRANSITION_STATE_RUNNING)) {
- boolean committed = !hasAnyFlag(FLAG_TRANSITION_STATE_RUNNING);
- playStateTransitionAnim(animatorSet, duration, committed);
-
- if (committed && mLauncherState == LauncherState.QUICK_SWITCH) {
- // We're about to be paused, set immediately to ensure seamless handoff.
- updateStateForFlag(FLAG_RESUMED, false);
- applyState(0 /* duration */);
- }
- }
-
if (start) {
animatorSet.start();
}
@@ -315,8 +336,11 @@
animatorSet.play(stashAnimator);
}
- animatorSet.play(mIconAlignmentForLauncherState.animateToValue(toAlignment)
- .setDuration(duration));
+ // If we're already animating to the value, just leave it be instead of restarting it.
+ if (!mIconAlignmentForLauncherState.isAnimatingToValue(toAlignment)) {
+ animatorSet.play(mIconAlignmentForLauncherState.animateToValue(toAlignment)
+ .setDuration(duration));
+ }
}
private boolean isResumed() {
diff --git a/quickstep/src/com/android/quickstep/AnimatedFloat.java b/quickstep/src/com/android/quickstep/AnimatedFloat.java
index 95c8710..6a7d066 100644
--- a/quickstep/src/com/android/quickstep/AnimatedFloat.java
+++ b/quickstep/src/com/android/quickstep/AnimatedFloat.java
@@ -42,6 +42,8 @@
private final Runnable mUpdateCallback;
private ObjectAnimator mValueAnimator;
+ // Only non-null when an animation is playing to this value.
+ private Float mEndValue;
public float value;
@@ -68,9 +70,17 @@
mValueAnimator = ObjectAnimator.ofFloat(this, VALUE, start, end);
mValueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
+ public void onAnimationStart(Animator animator) {
+ if (mValueAnimator == animator) {
+ mEndValue = end;
+ }
+ }
+
+ @Override
public void onAnimationEnd(Animator animator) {
if (mValueAnimator == animator) {
mValueAnimator = null;
+ mEndValue = null;
}
}
});
@@ -103,4 +113,15 @@
public ObjectAnimator getCurrentAnimation() {
return mValueAnimator;
}
+
+ public boolean isAnimating() {
+ return mValueAnimator != null;
+ }
+
+ /**
+ * Returns whether we are currently animating, and the animation's end value matches the given.
+ */
+ public boolean isAnimatingToValue(float endValue) {
+ return isAnimating() && mEndValue != null && mEndValue == endValue;
+ }
}