From 349ac6070be667aa73c0df3077f3662e46c26c36 Mon Sep 17 00:00:00 2001 From: yueg Date: Wed, 17 Jan 2018 09:02:45 -0800 Subject: Handle hiding bubble right after showing it. If hide bubble right after showing it, we should cancel animation, remove view and set visibility to HIDEN. Otherwise we can't retrieve correct bubble status later, thus hide/show bubble unexpectedly. It at least fix some cases of IllegalArgumentException. Bug: 71746139 Test: NewBubbleTest PiperOrigin-RevId: 182222155 Change-Id: If020b83cfffd9c643fd6fe3d2879a05e5969281f --- java/com/android/newbubble/NewBubble.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'java/com/android/newbubble') diff --git a/java/com/android/newbubble/NewBubble.java b/java/com/android/newbubble/NewBubble.java index cb7a09469..65f7a0aab 100644 --- a/java/com/android/newbubble/NewBubble.java +++ b/java/com/android/newbubble/NewBubble.java @@ -103,7 +103,7 @@ public class NewBubble { @NonNull private NewBubbleInfo currentInfo; - @Visibility private int visibility; + @VisibleForTesting @Visibility int visibility; private boolean expanded; private CharSequence textAfterShow; private int collapseEndAction; @@ -112,6 +112,7 @@ public class NewBubble { private AnimatorSet collapseAnimatorSet; private Integer overrideGravity; @VisibleForTesting AnimatorSet exitAnimatorSet; + @VisibleForTesting AnimatorSet enterAnimatorSet; private final int primaryIconMoveDistance; private final int leftBoundary; @@ -120,15 +121,15 @@ public class NewBubble { /** Type of action after bubble collapse */ @Retention(RetentionPolicy.SOURCE) @IntDef({CollapseEnd.NOTHING, CollapseEnd.HIDE}) - @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - public @interface CollapseEnd { + private @interface CollapseEnd { int NOTHING = 0; int HIDE = 1; } @Retention(RetentionPolicy.SOURCE) + @VisibleForTesting @IntDef({Visibility.ENTERING, Visibility.SHOWING, Visibility.EXITING, Visibility.HIDDEN}) - private @interface Visibility { + @interface Visibility { int HIDDEN = 0; int ENTERING = 1; int SHOWING = 2; @@ -440,7 +441,7 @@ public class NewBubble { ObjectAnimator.ofFloat(viewHolder.getPrimaryAvatar(), "alpha", 1); ObjectAnimator iconAlphaAnimator = ObjectAnimator.ofFloat(viewHolder.getPrimaryIcon(), "alpha", 1); - AnimatorSet enterAnimatorSet = new AnimatorSet(); + enterAnimatorSet = new AnimatorSet(); enterAnimatorSet.playTogether( scaleXAnimator, scaleYAnimator, avatarAlphaAnimator, iconAlphaAnimator); enterAnimatorSet.setInterpolator(new OvershootInterpolator()); @@ -609,6 +610,14 @@ public class NewBubble { // Make bubble non clickable to prevent further buggy actions viewHolder.setChildClickable(false); + if (visibility == Visibility.ENTERING) { + enterAnimatorSet.removeAllListeners(); + enterAnimatorSet.cancel(); + enterAnimatorSet = null; + afterHiding.run(); + return; + } + if (collapseAnimatorSet != null) { collapseEndAction = CollapseEnd.HIDE; return; -- cgit v1.2.3