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

Commit 4a8efe32 authored by Lyn Han's avatar Lyn Han
Browse files

Spacing between bubbles

Calculate bubble spacing based on
-Bubble size
-Expanded view padding
-Launcher grid layout
-Screen width

Also some cleanup

Bug: 134070807
Test: manual
Change-Id: I5c7555b7d0c9a9c7cb94c35c55fcdd59b64d6fb1
parent 11af7e18
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1109,8 +1109,8 @@
    <dimen name="bubble_flyout_space_from_bubble">8dp</dimen>
    <!-- Padding around a collapsed bubble -->
    <dimen name="bubble_view_padding">0dp</dimen>
    <!-- Padding between bubbles when displayed in expanded state -->
    <dimen name="bubble_padding">8dp</dimen>
    <!-- Padding between status bar and bubbles when displayed in expanded state -->
    <dimen name="bubble_padding_top">8dp</dimen>
    <!-- Size of individual bubbles. -->
    <dimen name="individual_bubble_size">52dp</dimen>
    <!-- Size of the circle around the bubbles when they're in the dismiss target. -->
+3 −3
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ public class BubbleStackView extends FrameLayout {
    private float mVerticalPosPercentBeforeRotation = -1;

    private int mBubbleSize;
    private int mBubblePadding;
    private int mBubblePaddingTop;
    private int mExpandedViewPadding;
    private int mExpandedAnimateXDistance;
    private int mExpandedAnimateYDistance;
@@ -302,7 +302,7 @@ public class BubbleStackView extends FrameLayout {

        Resources res = getResources();
        mBubbleSize = res.getDimensionPixelSize(R.dimen.individual_bubble_size);
        mBubblePadding = res.getDimensionPixelSize(R.dimen.bubble_padding);
        mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top);
        mExpandedAnimateXDistance =
                res.getDimensionPixelSize(R.dimen.bubble_expanded_animate_x_distance);
        mExpandedAnimateYDistance =
@@ -1305,7 +1305,7 @@ public class BubbleStackView extends FrameLayout {
     * Calculates the y position of the expanded view when it is expanded.
     */
    float getExpandedViewY() {
        return getStatusBarHeight() + mBubbleSize + mBubblePadding + mPointerHeight;
        return getStatusBarHeight() + mBubbleSize + mBubblePaddingTop + mPointerHeight;
    }

    /**
+43 −50
Original line number Diff line number Diff line
@@ -53,16 +53,14 @@ public class ExpandedAnimationController

    /** Horizontal offset between bubbles, which we need to know to re-stack them. */
    private float mStackOffsetPx;
    /** Spacing between bubbles in the expanded state. */
    private float mBubblePaddingPx;
    /** Space between status bar and bubbles in the expanded state. */
    private float mBubblePaddingTop;
    /** Size of each bubble. */
    private float mBubbleSizePx;
    /** Height of the status bar. */
    private float mStatusBarHeight;
    /** Size of display. */
    private Point mDisplaySize;
    /** Size of dismiss target at bottom of screen. */
    private float mPipDismissHeight;
    /** Max number of bubbles shown in row above expanded view.*/
    private int mBubblesMaxRendered;

@@ -96,24 +94,16 @@ public class ExpandedAnimationController
    /** The bubble currently being dragged out of the row (to potentially be dismissed). */
    private View mBubbleDraggingOut;

    /**
     * Drag velocities for the dragging-out bubble when the drag finished. These are used by
     * {@link #onChildRemoved} to animate out the bubble while respecting touch velocity.
     */
    private float mBubbleDraggingOutVelX;
    private float mBubbleDraggingOutVelY;

    @Override
    protected void setLayout(PhysicsAnimationLayout layout) {
        super.setLayout(layout);

        final Resources res = layout.getResources();
        mStackOffsetPx = res.getDimensionPixelSize(R.dimen.bubble_stack_offset);
        mBubblePaddingPx = res.getDimensionPixelSize(R.dimen.bubble_padding);
        mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top);
        mBubbleSizePx = res.getDimensionPixelSize(R.dimen.individual_bubble_size);
        mStatusBarHeight =
                res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
        mPipDismissHeight = res.getDimensionPixelSize(R.dimen.pip_dismiss_gradient_height);
        mBubblesMaxRendered = res.getInteger(R.integer.bubbles_max_rendered);
    }

@@ -251,13 +241,10 @@ public class ExpandedAnimationController
    }

    /**
     * Sets configuration variables so that when the given bubble is removed, the animations are
     * started with the given velocities.
     * Sets configuration variables.
     */
    public void prepareForDismissalWithVelocity(View bubbleView, float velX, float velY) {
    public void prepareForDismissalWithVelocity(View bubbleView) {
        mBubbleDraggingOut = bubbleView;
        mBubbleDraggingOutVelX = velX;
        mBubbleDraggingOutVelY = velY;
        mBubbleDraggedOutEnough = false;
    }

@@ -270,26 +257,13 @@ public class ExpandedAnimationController
                0, (i, anim) -> anim.translationY(getExpandedY())).startAll(after);
    }

    /**
     * Animates the bubbles, starting at the given index, to the left or right by the given number
     * of bubble widths. Passing zero for numBubbleWidths will animate the bubbles to their normal
     * positions.
     */
    private void animateStackByBubbleWidthsStartingFrom(int numBubbleWidths, int startIndex) {
        animationsForChildrenFromIndex(
                startIndex,
                (index, animation) ->
                        animation.translationX(getXForChildAtIndex(index + numBubbleWidths)))
            .startAll();
    }

    /** The Y value of the row of expanded bubbles. */
    public float getExpandedY() {
        if (mLayout == null || mLayout.getRootWindowInsets() == null) {
            return 0;
        }
        final WindowInsets insets = mLayout.getRootWindowInsets();
        return mBubblePaddingPx + Math.max(
        return mBubblePaddingTop + Math.max(
            mStatusBarHeight,
            insets.getDisplayCutout() != null
                ? insets.getDisplayCutout().getSafeInsetTop()
@@ -325,8 +299,6 @@ public class ExpandedAnimationController

    @Override
    void onChildAdded(View child, int index) {
        child.setTranslationX(getXForChildAtIndex(index));

        animationForChild(child)
                .translationY(
                        getExpandedY() - mBubbleSizePx * ANIMATE_TRANSLATION_FACTOR, /* from */
@@ -384,38 +356,59 @@ public class ExpandedAnimationController
        }
    }

    /** Returns the appropriate X translation value for a bubble at the given index. */
    private float getXForChildAtIndex(int index) {
        return mBubblePaddingPx + (mBubbleSizePx + mBubblePaddingPx) * index;
    }

    /**
     * @param index Bubble index in row.
     * @return Bubble left x from left edge of screen.
     */
    public float getBubbleLeft(int index) {
        float bubbleLeftFromRowLeft = index * (mBubbleSizePx + mBubblePaddingPx);
        return getRowLeft() + bubbleLeftFromRowLeft;
        float bubbleFromRowLeft = index * (mBubbleSizePx + getSpaceBetweenBubbles());
        return getRowLeft() + bubbleFromRowLeft;
    }

    private float getRowLeft() {
        if (mLayout == null) {
            return 0;
        }

        int bubbleCount = mLayout.getChildCount();
        if (bubbleCount > mBubblesMaxRendered) {
            // Only shown bubbles are relevant for calculating position.
            // Only rendered bubbles are relevant for calculating row left.
            bubbleCount = mBubblesMaxRendered;
        }
        // Width calculations.
        double bubble = bubbleCount * mBubbleSizePx;
        float gap = (bubbleCount - 1) * mBubblePaddingPx;
        float row = gap + (float) bubble;

        float halfRow = row / 2f;
        float centerScreen = mDisplaySize.x / 2;
        float rowLeftFromScreenLeft = centerScreen - halfRow;
        final float totalBubbleWidth = bubbleCount * mBubbleSizePx;
        final float totalGapWidth = (bubbleCount - 1) * getSpaceBetweenBubbles();
        final float rowWidth = totalGapWidth + totalBubbleWidth;

        final float centerScreen = mDisplaySize.x / 2f;
        final float halfRow = rowWidth / 2f;
        final float rowLeft = centerScreen - halfRow;

        return rowLeft;
    }

    /**
     * @return Space between bubbles in row above expanded view.
     */
    private float getSpaceBetweenBubbles() {
        /**
         * Ordered left to right:
         *  Screen edge
         *      [mExpandedViewPadding]
         *  Expanded view edge
         *      [launcherGridDiff] --- arbitrary value until launcher exports widths
         *  Launcher's app icon grid edge that we must match
         */
        final float launcherGridDiff = mBubbleSizePx / 2f;
        final float rowMargins = (mExpandedViewPadding + launcherGridDiff) * 2;
        final float maxRowWidth = mDisplaySize.x - rowMargins;

        final float totalBubbleWidth = mBubblesMaxRendered * mBubbleSizePx;
        final float totalGapWidth = maxRowWidth - totalBubbleWidth;

        final int gapCount = mBubblesMaxRendered - 1;
        final float gapWidth = totalGapWidth / gapCount;

        return rowLeftFromScreenLeft;
        return gapWidth;
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ public class StackAnimationController extends
     * the screen or the IME. This does not apply to the left/right sides of the screen since the
     * stack goes offscreen intentionally.
     */
    private int mBubblePadding;
    private int mBubblePaddingTop;
    /** How far offscreen the stack rests. */
    private int mBubbleOffscreen;
    /** How far down the screen the stack starts, when there is no pre-existing location. */
@@ -161,7 +161,7 @@ public class StackAnimationController extends
        Resources res = layout.getResources();
        mStackOffset = res.getDimensionPixelSize(R.dimen.bubble_stack_offset);
        mIndividualBubbleSize = res.getDimensionPixelSize(R.dimen.individual_bubble_size);
        mBubblePadding = res.getDimensionPixelSize(R.dimen.bubble_padding);
        mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top);
        mBubbleOffscreen = res.getDimensionPixelSize(R.dimen.bubble_stack_offscreen);
        mStackStartingVerticalOffset =
                res.getDimensionPixelSize(R.dimen.bubble_stack_starting_offset_y);
@@ -449,7 +449,7 @@ public class StackAnimationController extends
                                    : 0);

            allowableRegion.top =
                    mBubblePadding
                    mBubblePaddingTop
                            + Math.max(
                            mStatusBarHeight,
                            insets.getDisplayCutout() != null
@@ -458,8 +458,8 @@ public class StackAnimationController extends
            allowableRegion.bottom =
                    mLayout.getHeight()
                            - mIndividualBubbleSize
                            - mBubblePadding
                            - (mImeHeight > Float.MIN_VALUE ? mImeHeight + mBubblePadding : 0f)
                            - mBubblePaddingTop
                            - (mImeHeight > Float.MIN_VALUE ? mImeHeight + mBubblePaddingTop : 0f)
                            - Math.max(
                            insets.getSystemWindowInsetBottom(),
                            insets.getDisplayCutout() != null
+2 −2
Original line number Diff line number Diff line
@@ -138,8 +138,8 @@ public class ExpandedAnimationControllerTest extends PhysicsAnimationLayoutTestC
        assertEquals(500f, draggedBubble.getTranslationX(), 1f);
        assertEquals(500f, draggedBubble.getTranslationY(), 1f);

        // Snap it back and make sure it made it back correctly.
        mExpandedController.prepareForDismissalWithVelocity(draggedBubble, 0f, 0f);
        // Snap bubble back and make sure it returned correctly.
        mExpandedController.prepareForDismissalWithVelocity(draggedBubble);
        mLayout.removeView(draggedBubble);
        waitForLayoutMessageQueue();
        waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y);