From a7b018535b3257f0d974b4a766ba732c338465da Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 11 Jun 2021 14:52:25 -0700 Subject: [PATCH] Ensure that the cancel and end listener are called when cancelling state animation Bug: 190856140 Test: Manual Change-Id: Ib6b869445cee9fad2a97a590d27429140f2b3ba9 --- .../launcher3/anim/AnimatorPlaybackController.java | 5 ++++- .../android/launcher3/statemanager/StateManager.java | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/anim/AnimatorPlaybackController.java b/src/com/android/launcher3/anim/AnimatorPlaybackController.java index f6d1651cb6..7d8b82a8eb 100644 --- a/src/com/android/launcher3/anim/AnimatorPlaybackController.java +++ b/src/com/android/launcher3/anim/AnimatorPlaybackController.java @@ -290,7 +290,10 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL 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 command) { callAnimatorCommandRecursively(anim, a-> { for (AnimatorListener l : nonNullList(a.getListeners())) { diff --git a/src/com/android/launcher3/statemanager/StateManager.java b/src/com/android/launcher3/statemanager/StateManager.java index 03b68535bc..13d6568f78 100644 --- a/src/com/android/launcher3/statemanager/StateManager.java +++ b/src/com/android/launcher3/statemanager/StateManager.java @@ -18,6 +18,7 @@ package com.android.launcher3.statemanager; 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 android.animation.Animator; @@ -514,8 +515,15 @@ public class StateManager> { playbackController.getAnimationPlayer().cancel(); playbackController.dispatchOnCancel(); } else if (currentAnimation != null) { - currentAnimation.setDuration(0); - currentAnimation.cancel(); + AnimatorSet anim = currentAnimation; + 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;