From fa6cbbe15b4c2d698b20e10a28efc95e1fe8ada4 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 4 May 2018 13:17:46 -0700 Subject: [PATCH] Cleanup swipe detector in case of double cancel We manually dispatch cancel when returning to the previous state in onDragEnd(), but could end in a bad state if getting a second, external cancel (e.g. by pressing home). Thus, we restore the onCancelListener after manually dispatching cancel. Bug: 79258868 Change-Id: Idc4c33cede1d8af1829a4a744b9348d379bcf8f7 --- .../android/launcher3/anim/AnimatorPlaybackController.java | 4 ++++ .../launcher3/touch/AbstractStateChangeTouchController.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/com/android/launcher3/anim/AnimatorPlaybackController.java b/src/com/android/launcher3/anim/AnimatorPlaybackController.java index 8e729e884e..84085cb6c0 100644 --- a/src/com/android/launcher3/anim/AnimatorPlaybackController.java +++ b/src/com/android/launcher3/anim/AnimatorPlaybackController.java @@ -206,6 +206,10 @@ public abstract class AnimatorPlaybackController implements ValueAnimator.Animat mOnCancelRunnable = runnable; } + public Runnable getOnCancelRunnable() { + return mOnCancelRunnable; + } + public static class AnimatorPlaybackControllerVL extends AnimatorPlaybackController { private final ValueAnimator[] mChildAnimations; diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java index 658af955ad..bad4976e4e 100644 --- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java +++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java @@ -244,8 +244,13 @@ public abstract class AbstractStateChangeTouchController endProgress - Math.max(progress, 0)); } } else { + // Let the state manager know that the animation didn't go to the target state, + // but don't cancel ourselves (we already clean up when the animation completes). + Runnable onCancel = mCurrentAnimation.getOnCancelRunnable(); mCurrentAnimation.setOnCancelRunnable(null); mCurrentAnimation.dispatchOnCancel(); + mCurrentAnimation.setOnCancelRunnable(onCancel); + endProgress = 0; if (progress <= 0) { duration = 0;