Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3829caa5 authored by Joshua Tsuji's avatar Joshua Tsuji
Browse files

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
parent 707b4655
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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();
+7 −9
Original line number Diff line number Diff line
@@ -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);
+12 −0
Original line number Diff line number Diff line
@@ -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