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

Commit 51ae40ce authored by Josh Tsuji's avatar Josh Tsuji Committed by Android (Google) Code Review
Browse files

Merge "Always pass a legal position to expandFromStack so that we don't return...

Merge "Always pass a legal position to expandFromStack so that we don't return to an illegal position."
parents 7235bef1 3829caa5
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -528,7 +528,9 @@ public class BubbleStackView extends FrameLayout {
            if (shouldExpand) {
            if (shouldExpand) {
                mBubbleContainer.setController(mExpandedAnimationController);
                mBubbleContainer.setController(mExpandedAnimationController);
                mExpandedAnimationController.expandFromStack(
                mExpandedAnimationController.expandFromStack(
                        mStackAnimationController.getStackPosition(),
                        /* collapseTo */
                        mStackAnimationController.getStackPositionAlongNearestHorizontalEdge(),
                        /* after */
                        () -> {
                        () -> {
                            updatePointerPosition();
                            updatePointerPosition();
                            updateAfter.run();
                            updateAfter.run();
+7 −9
Original line number Original line Diff line number Diff line
@@ -49,11 +49,8 @@ public class ExpandedAnimationController
    /** How much to scale down bubbles when they're animating in/out. */
    /** How much to scale down bubbles when they're animating in/out. */
    private static final float ANIMATE_SCALE_PERCENT = 0.5f;
    private static final float ANIMATE_SCALE_PERCENT = 0.5f;


    /**
    /** The stack position to collapse back to in {@link #collapseBackToStack}. */
     * The stack position from which the bubbles were expanded. Saved in {@link #expandFromStack}
    private PointF mCollapseToPoint;
     * and used to return to stack form in {@link #collapseBackToStack}.
     */
    private PointF mExpandedFrom;


    /** Horizontal offset between bubbles, which we need to know to re-stack them. */
    /** Horizontal offset between bubbles, which we need to know to re-stack them. */
    private float mStackOffsetPx;
    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.
     * @return The y-value to which the bubbles were expanded, in case that's useful.
     */
     */
    public float expandFromStack(PointF expandedFrom, Runnable after) {
    public float expandFromStack(PointF collapseTo, Runnable after) {
        mExpandedFrom = expandedFrom;
        mCollapseToPoint = collapseTo;


        // How much to translate the next bubble, so that it is not overlapping the previous one.
        // How much to translate the next bubble, so that it is not overlapping the previous one.
        float translateNextBubbleXBy = mBubblePaddingPx;
        float translateNextBubbleXBy = mBubblePaddingPx;
@@ -123,10 +120,11 @@ public class ExpandedAnimationController
    /** Animate collapsing the bubbles back to their stacked position. */
    /** Animate collapsing the bubbles back to their stacked position. */
    public void collapseBackToStack(Runnable after) {
    public void collapseBackToStack(Runnable after) {
        // Stack to the left if we're going to the left, or right if not.
        // 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++) {
        for (int i = 0; i < mLayout.getChildCount(); i++) {
            mLayout.animatePositionForChildAtIndex(
            mLayout.animatePositionForChildAtIndex(
                    i, mExpandedFrom.x + (sideMultiplier * i * mStackOffsetPx), mExpandedFrom.y);
                    i,
                    mCollapseToPoint.x + (sideMultiplier * i * mStackOffsetPx), mCollapseToPoint.y);
        }
        }


        runAfterTranslationsEnd(after);
        runAfterTranslationsEnd(after);
+12 −0
Original line number Original line Diff line number Diff line
@@ -133,6 +133,18 @@ public class StackAnimationController extends
        return mStackPosition;
        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
     * 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
     * values. When the animation ends - either by hitting the min/max, or by friction sufficiently