diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java index 82025d49e262e..4869485a33362 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java @@ -528,7 +528,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 47668b84cbef2..f2c8496c31860 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