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

Commit 9a6ded7d authored by Ats Jenk's avatar Ats Jenk
Browse files

Stop tracking bubble bar bounds and only listen for top coordinate

Shell needs the top coordinate of bubble bar to see where to place the
bottom edge of the expanded view.
The left and right value of the bounds were used for the collapse/expand
animation of the expanded view. But we already know the location of the
bubble bar. Updating the expanded view animation to scale in from the
right edge of the screen. And not the center of the bubble bar view
itself.
Reduces the number of calls needed from launcher to shell to update the
bounds as they change every time number of bubbles changes or bar itself
expands/collapses.
Simplifies syncing between launcher and shell as we no longer need to
keep the entire bounds in sync. Just the top coordinate of the bar which
changes when user is on home screen or in the app.

Bug: 330585402
Flag: com.android.wm.shell.enable_bubble_bar
Test: atest BubblesTest
Test: atest WMShellMultivalentTestsOnDevice
Test: atest WMShellRobolectricTests
Test: bubble bar drag
  - drag bar from right to left
  - expand the bar
  - check that expanded view scales in from left edge
  - collapse and drag bar back, check the animation
Test: selected bubble drag
  - drag expanded bubble from right to left
  - check that expanded view scales in from the left edge
  - drag the bubble back to right, check animation
Test: other bubble drag
  - drag a unselected bubble from right to left
  - check that the selected bubble expands in from left edge
  - drag the bubble back to right, check animation again
Test: drag bubble from right to left, observe that expanded view
  expand animation originates from the bubble bar
Change-Id: Ica786e6116e75db9366653cf9e66746909761696
parent 4a72e44e
Loading
Loading
Loading
Loading
+9 −25
Original line number Diff line number Diff line
@@ -218,11 +218,10 @@ class BubblePositionerTest {
                insets = Insets.of(10, 20, 5, 15),
                windowBounds = Rect(0, 0, 1800, 2600)
            )
        val bubbleBarBounds = Rect(1700, 2500, 1780, 2600)

        positioner.setShowingInBubbleBar(true)
        positioner.update(deviceConfig)
        positioner.bubbleBarBounds = bubbleBarBounds
        positioner.bubbleBarTopOnScreen = 2500

        val spaceBetweenTopInsetAndBubbleBarInLandscape = 1680
        val expandedViewVerticalSpacing =
@@ -246,10 +245,9 @@ class BubblePositionerTest {
                insets = Insets.of(10, 20, 5, 15),
                windowBounds = Rect(0, 0, screenWidth, 2600)
            )
        val bubbleBarBounds = Rect(100, 2500, 280, 2550)
        positioner.setShowingInBubbleBar(true)
        positioner.update(deviceConfig)
        positioner.bubbleBarBounds = bubbleBarBounds
        positioner.bubbleBarTopOnScreen = 2500

        val spaceBetweenTopInsetAndBubbleBarInLandscape = 180
        val expandedViewSpacing =
@@ -597,16 +595,19 @@ class BubblePositionerTest {

    private fun testGetBubbleBarExpandedViewBounds(onLeft: Boolean, isOverflow: Boolean) {
        positioner.setShowingInBubbleBar(true)
        val windowBounds = Rect(0, 0, 2000, 2600)
        val insets = Insets.of(10, 20, 5, 15)
        val deviceConfig =
            defaultDeviceConfig.copy(
                isLargeScreen = true,
                isLandscape = true,
                insets = Insets.of(10, 20, 5, 15),
                windowBounds = Rect(0, 0, 2000, 2600)
                insets = insets,
                windowBounds = windowBounds
            )
        positioner.update(deviceConfig)

        positioner.bubbleBarBounds = getBubbleBarBounds(onLeft, deviceConfig)
        val bubbleBarHeight = 100
        positioner.bubbleBarTopOnScreen = windowBounds.bottom - insets.bottom - bubbleBarHeight

        val expandedViewPadding =
            context.resources.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding)
@@ -624,7 +625,7 @@ class BubblePositionerTest {
            left = right - positioner.getExpandedViewWidthForBubbleBar(isOverflow)
        }
        // Above the bubble bar
        val bottom = positioner.bubbleBarBounds.top - expandedViewPadding
        val bottom = positioner.bubbleBarTopOnScreen - expandedViewPadding
        // Calculate right and top based on size
        val top = bottom - positioner.getExpandedViewHeightForBubbleBar(isOverflow)
        val expectedBounds = Rect(left, top, right, bottom)
@@ -666,21 +667,4 @@ class BubblePositionerTest {
                positioner.getAllowableStackPositionRegion(1 /* bubbleCount */)
            return allowableStackRegion.top + allowableStackRegion.height() * offsetPercent
        }

    private fun getBubbleBarBounds(onLeft: Boolean, deviceConfig: DeviceConfig): Rect {
        val width = 200
        val height = 100
        val bottom = deviceConfig.windowBounds.bottom - deviceConfig.insets.bottom
        val top = bottom - height
        val left: Int
        val right: Int
        if (onLeft) {
            left = deviceConfig.insets.left
            right = left + width
        } else {
            right = deviceConfig.windowBounds.right - deviceConfig.insets.right
            left = right - width
        }
        return Rect(left, top, right, bottom)
    }
}
+6 −12
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ class BubbleExpandedViewPinControllerTest {
        const val SCREEN_WIDTH = 2000
        const val SCREEN_HEIGHT = 1000

        const val BUBBLE_BAR_WIDTH = 100
        const val BUBBLE_BAR_HEIGHT = 50
    }

@@ -84,14 +83,8 @@ class BubbleExpandedViewPinControllerTest {
                insets = Insets.of(10, 20, 30, 40)
            )
        positioner.update(deviceConfig)
        positioner.bubbleBarBounds =
            Rect(
                SCREEN_WIDTH - deviceConfig.insets.right - BUBBLE_BAR_WIDTH,
                SCREEN_HEIGHT - deviceConfig.insets.bottom - BUBBLE_BAR_HEIGHT,
                SCREEN_WIDTH - deviceConfig.insets.right,
                SCREEN_HEIGHT - deviceConfig.insets.bottom
            )

        positioner.bubbleBarTopOnScreen =
            SCREEN_HEIGHT - deviceConfig.insets.bottom - BUBBLE_BAR_HEIGHT
        controller = BubbleExpandedViewPinController(context, container, positioner)
        testListener = TestLocationChangeListener()
        controller.setListener(testListener)
@@ -247,7 +240,8 @@ class BubbleExpandedViewPinControllerTest {
    private val dropTargetView: View?
        get() = container.findViewById(R.id.bubble_bar_drop_target)

    private fun getExpectedDropTargetBounds(onLeft: Boolean): Rect = Rect().also {
    private fun getExpectedDropTargetBounds(onLeft: Boolean): Rect =
        Rect().also {
            positioner.getBubbleBarExpandedViewBounds(onLeft, false /* isOveflowExpanded */, it)
        }

+12 −11
Original line number Diff line number Diff line
@@ -1189,9 +1189,11 @@ public class BubbleController implements ConfigurationChangeListener,
     * Will be called only when bubble bar is expanded.
     *
     * @param location location where bubble was released
     * @param topOnScreen      top coordinate of the bubble bar on the screen after release
     */
    public void stopBubbleDrag(BubbleBarLocation location) {
    public void stopBubbleDrag(BubbleBarLocation location, int topOnScreen) {
        mBubblePositioner.setBubbleBarLocation(location);
        mBubblePositioner.setBubbleBarTopOnScreen(topOnScreen);
        if (mBubbleData.getSelectedBubble() != null) {
            mBubbleBarViewCallback.expansionChanged(/* isExpanded = */ true);
        }
@@ -1247,8 +1249,8 @@ public class BubbleController implements ConfigurationChangeListener,
     * <p>This is used by external callers (launcher).
     */
    @VisibleForTesting
    public void expandStackAndSelectBubbleFromLauncher(String key, Rect bubbleBarBounds) {
        mBubblePositioner.setBubbleBarBounds(bubbleBarBounds);
    public void expandStackAndSelectBubbleFromLauncher(String key, int topOnScreen) {
        mBubblePositioner.setBubbleBarTopOnScreen(topOnScreen);

        if (BubbleOverflow.KEY.equals(key)) {
            mBubbleData.setSelectedBubbleFromLauncher(mBubbleData.getOverflow());
@@ -2359,10 +2361,9 @@ public class BubbleController implements ConfigurationChangeListener,
        }

        @Override
        public void showBubble(String key, Rect bubbleBarBounds) {
        public void showBubble(String key, int topOnScreen) {
            mMainExecutor.execute(
                    () -> mController.expandStackAndSelectBubbleFromLauncher(
                            key, bubbleBarBounds));
                    () -> mController.expandStackAndSelectBubbleFromLauncher(key, topOnScreen));
        }

        @Override
@@ -2381,8 +2382,8 @@ public class BubbleController implements ConfigurationChangeListener,
        }

        @Override
        public void stopBubbleDrag(BubbleBarLocation location) {
            mMainExecutor.execute(() -> mController.stopBubbleDrag(location));
        public void stopBubbleDrag(BubbleBarLocation location, int topOnScreen) {
            mMainExecutor.execute(() -> mController.stopBubbleDrag(location, topOnScreen));
        }

        @Override
@@ -2403,9 +2404,9 @@ public class BubbleController implements ConfigurationChangeListener,
        }

        @Override
        public void setBubbleBarBounds(Rect bubbleBarBounds) {
        public void updateBubbleBarTopOnScreen(int topOnScreen) {
            mMainExecutor.execute(() -> {
                mBubblePositioner.setBubbleBarBounds(bubbleBarBounds);
                mBubblePositioner.setBubbleBarTopOnScreen(topOnScreen);
                if (mLayerView != null) mLayerView.updateExpandedView();
            });
        }
+8 −8
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class BubblePositioner {

    private boolean mShowingInBubbleBar;
    private BubbleBarLocation mBubbleBarLocation = BubbleBarLocation.DEFAULT;
    private final Rect mBubbleBarBounds = new Rect();
    private int mBubbleBarTopOnScreen;

    public BubblePositioner(Context context, WindowManager windowManager) {
        mContext = context;
@@ -846,17 +846,17 @@ public class BubblePositioner {
    }

    /**
     * Sets the position of the bubble bar in display coordinates.
     * Set top coordinate of bubble bar on screen
     */
    public void setBubbleBarBounds(Rect bubbleBarBounds) {
        mBubbleBarBounds.set(bubbleBarBounds);
    public void setBubbleBarTopOnScreen(int topOnScreen) {
        mBubbleBarTopOnScreen = topOnScreen;
    }

    /**
     * Returns the display coordinates of the bubble bar.
     * Returns the top coordinate of bubble bar on screen
     */
    public Rect getBubbleBarBounds() {
        return mBubbleBarBounds;
    public int getBubbleBarTopOnScreen() {
        return mBubbleBarTopOnScreen;
    }

    /**
@@ -908,7 +908,7 @@ public class BubblePositioner {

    /** The bottom position of the expanded view when showing above the bubble bar. */
    public int getExpandedViewBottomForBubbleBar() {
        return mBubbleBarBounds.top - mExpandedViewPadding;
        return mBubbleBarTopOnScreen - mExpandedViewPadding;
    }

    /**
+3 −3
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ interface IBubbles {

    oneway void unregisterBubbleListener(in IBubblesListener listener) = 2;

    oneway void showBubble(in String key, in Rect bubbleBarBounds) = 3;
    oneway void showBubble(in String key, in int topOnScreen) = 3;

    oneway void dragBubbleToDismiss(in String key) = 4;

@@ -45,7 +45,7 @@ interface IBubbles {

    oneway void setBubbleBarLocation(in BubbleBarLocation location) = 9;

    oneway void setBubbleBarBounds(in Rect bubbleBarBounds) = 10;
    oneway void updateBubbleBarTopOnScreen(in int topOnScreen) = 10;

    oneway void stopBubbleDrag(in BubbleBarLocation location) = 11;
    oneway void stopBubbleDrag(in BubbleBarLocation location, in int topOnScreen) = 11;
}
 No newline at end of file
Loading