Merge "Ensure that the cancel and end listener are called when cancelling state animation" into sc-dev am: 012e978e31 am: 38e3dbe38e

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14949019

Change-Id: Id3b745f6409dde02c066f389bd259a9417097495
This commit is contained in:
TreeHugger Robot
2021-06-14 19:46:30 +00:00
committed by Automerger Merge Worker
2 changed files with 14 additions and 3 deletions
@@ -290,7 +290,10 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
callAnimatorCommandRecursively(mAnim, a -> a.setInterpolator(interpolator)); callAnimatorCommandRecursively(mAnim, a -> a.setInterpolator(interpolator));
} }
private static void callListenerCommandRecursively( /**
* Recursively calls a command on all the listeners of the provided animation
*/
public static void callListenerCommandRecursively(
Animator anim, BiConsumer<AnimatorListener, Animator> command) { Animator anim, BiConsumer<AnimatorListener, Animator> command) {
callAnimatorCommandRecursively(anim, a-> { callAnimatorCommandRecursively(anim, a-> {
for (AnimatorListener l : nonNullList(a.getListeners())) { for (AnimatorListener l : nonNullList(a.getListeners())) {
@@ -18,6 +18,7 @@ package com.android.launcher3.statemanager;
import static android.animation.ValueAnimator.areAnimatorsEnabled; import static android.animation.ValueAnimator.areAnimatorsEnabled;
import static com.android.launcher3.anim.AnimatorPlaybackController.callListenerCommandRecursively;
import static com.android.launcher3.states.StateAnimationConfig.SKIP_ALL_ANIMATIONS; import static com.android.launcher3.states.StateAnimationConfig.SKIP_ALL_ANIMATIONS;
import android.animation.Animator; import android.animation.Animator;
@@ -514,8 +515,15 @@ public class StateManager<STATE_TYPE extends BaseState<STATE_TYPE>> {
playbackController.getAnimationPlayer().cancel(); playbackController.getAnimationPlayer().cancel();
playbackController.dispatchOnCancel(); playbackController.dispatchOnCancel();
} else if (currentAnimation != null) { } else if (currentAnimation != null) {
currentAnimation.setDuration(0); AnimatorSet anim = currentAnimation;
currentAnimation.cancel(); anim.setDuration(0);
if (!anim.isStarted()) {
// If the animation is not started the listeners do not get notified,
// notify manually.
callListenerCommandRecursively(anim, AnimatorListener::onAnimationCancel);
callListenerCommandRecursively(anim, AnimatorListener::onAnimationEnd);
}
anim.cancel();
} }
currentAnimation = null; currentAnimation = null;