From 3829caa5b2813f333cfa4c80a92b475938ee4a75 Mon Sep 17 00:00:00 2001 From: Joshua Tsuji Date: Tue, 5 Mar 2019 18:09:13 -0500 Subject: [PATCH] Always pass a legal position to expandFromStack so that we don't return to an illegal position. This was originally possible if the stack was expanded by tapping it while it animated across the screen. Fixes: 123023410 Test: manual Change-Id: Idc403dfe6affb0aac4fc5027fa9e97f8a733b31a --- .../systemui/bubbles/BubbleStackView.java | 4 +++- .../animation/ExpandedAnimationController.java | 16 +++++++--------- .../animation/StackAnimationController.java | 12 ++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java index 8235d8de3257b..9110174a7aaa1 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java @@ -491,7 +491,9 @@ public class BubbleStackView extends FrameLayout { if (shouldExpand) { mBubbleContainer.setController(mExpandedAnimationController); mExpandedAnimationController.expandFromStack( - mStackAnimationController.getStackPosition(), + /* collapseTo */ + mStackAnimationController.getStackPositionAlongNearestHorizontalEdge(), + /* after */ () -> { updatePointerPosition(); updateAfter.run(); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java b/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java index f7896b0b12018..7632cbb323175 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java @@ -49,11 +49,8 @@ public class ExpandedAnimationController /** How much to scale down bubbles when they're animating in/out. */ private static final float ANIMATE_SCALE_PERCENT = 0.5f; - /** - * The stack position from which the bubbles were expanded. Saved in {@link #expandFromStack} - * and used to return to stack form in {@link #collapseBackToStack}. - */ - private PointF mExpandedFrom; + /** The stack position to collapse back to in {@link #collapseBackToStack}. */ + private PointF mCollapseToPoint; /** Horizontal offset between bubbles, which we need to know to re-stack them. */ private float mStackOffsetPx; @@ -106,8 +103,8 @@ public class ExpandedAnimationController * * @return The y-value to which the bubbles were expanded, in case that's useful. */ - public float expandFromStack(PointF expandedFrom, Runnable after) { - mExpandedFrom = expandedFrom; + public float expandFromStack(PointF collapseTo, Runnable after) { + mCollapseToPoint = collapseTo; // How much to translate the next bubble, so that it is not overlapping the previous one. float translateNextBubbleXBy = mBubblePaddingPx; @@ -123,10 +120,11 @@ public class ExpandedAnimationController /** Animate collapsing the bubbles back to their stacked position. */ public void collapseBackToStack(Runnable after) { // Stack to the left if we're going to the left, or right if not. - final float sideMultiplier = mLayout.isFirstChildXLeftOfCenter(mExpandedFrom.x) ? -1 : 1; + final float sideMultiplier = mLayout.isFirstChildXLeftOfCenter(mCollapseToPoint.x) ? -1 : 1; for (int i = 0; i < mLayout.getChildCount(); i++) { mLayout.animatePositionForChildAtIndex( - i, mExpandedFrom.x + (sideMultiplier * i * mStackOffsetPx), mExpandedFrom.y); + i, + mCollapseToPoint.x + (sideMultiplier * i * mStackOffsetPx), mCollapseToPoint.y); } runAfterTranslationsEnd(after); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java b/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java index f47fbe0d149fa..4e9c419b6e4df 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java @@ -133,6 +133,18 @@ public class StackAnimationController extends return mStackPosition; } + /** + * Where the stack would be if it were snapped to the nearest horizontal edge (left or right). + */ + public PointF getStackPositionAlongNearestHorizontalEdge() { + final PointF stackPos = getStackPosition(); + final boolean onLeft = mLayout.isFirstChildXLeftOfCenter(stackPos.x); + final RectF bounds = getAllowableStackPositionRegion(); + + stackPos.x = onLeft ? bounds.left : bounds.right; + return stackPos; + } + /** * Flings the first bubble along the given property's axis, using the provided configuration * values. When the animation ends - either by hitting the min/max, or by friction sufficiently