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

Commit 3ac5d4e8 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix bubbles being on the wrong side after fold -> unfold

When bubbles are on the right hand edge of the device before unfolding
the position after unfolding would be on the left instead of the
right.

This was happening because the resting stack position is based in
the previous bounds, not the new ones.

To fix this, when the bounds change in BubblePositioner, the resting
stack position can be saved as a relative stack position using the
previous bounds and then restored using the new bounds. This converts
it to the correct spot on screen.

Test: manual - have bubbles on right side of fold phone, unfold
             => observe they are still on the right
             - check bubble position after orientation changes
Test: atest BubblePositionerTest
Bug: 256993976
Flag NONE; bug fix

Change-Id: Id515efa1c2aa32942e6d2eaffe69aa69f40bf5ca
parent 9a9bb380
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -164,6 +164,25 @@ class BubblePositionerTest {
        assertThat(startPosition.y).isEqualTo(defaultYPosition)
    }

    @Test
    fun testGetRestingPosition_afterBoundsChange() {
        positioner.update(defaultDeviceConfig.copy(isLargeScreen = true,
                windowBounds = Rect(0, 0, 2000, 1600)))

        // Set the resting position to the right side
        var allowableStackRegion = positioner.getAllowableStackPositionRegion(1 /* bubbleCount */)
        val restingPosition = PointF(allowableStackRegion.right, allowableStackRegion.centerY())
        positioner.restingPosition = restingPosition

        // Now make the device smaller
        positioner.update(defaultDeviceConfig.copy(isLargeScreen = false,
                windowBounds = Rect(0, 0, 1000, 1600)))

        // Check the resting position is on the correct side
        allowableStackRegion = positioner.getAllowableStackPositionRegion(1 /* bubbleCount */)
        assertThat(positioner.restingPosition.x).isEqualTo(allowableStackRegion.right)
    }

    @Test
    fun testHasUserModifiedDefaultPosition_false() {
        positioner.update(defaultDeviceConfig.copy(isLargeScreen = true, isRtl = true))
+13 −0
Original line number Diff line number Diff line
@@ -120,6 +120,13 @@ public class BubblePositioner {

    @VisibleForTesting
    public void updateInternal(int rotation, Insets insets, Rect bounds) {
        BubbleStackView.RelativeStackPosition prevStackPosition = null;
        if (mRestingStackPosition != null && mScreenRect != null && !mScreenRect.equals(bounds)) {
            // Save the resting position as a relative position with the previous bounds, at the
            // end of the update we'll restore it based on the new bounds.
            prevStackPosition = new BubbleStackView.RelativeStackPosition(getRestingPosition(),
                    getAllowableStackPositionRegion(1));
        }
        mRotation = rotation;
        mInsets = insets;

@@ -182,6 +189,12 @@ public class BubblePositioner {
                R.dimen.bubbles_flyout_min_width_large_screen);

        mMaxBubbles = calculateMaxBubbles();

        if (prevStackPosition != null) {
            // Get the new resting position based on the updated values
            mRestingStackPosition = prevStackPosition.getAbsolutePositionInRegion(
                    getAllowableStackPositionRegion(1));
        }
    }

    /**