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

Commit 89f6fa68 authored by Ats Jenk's avatar Ats Jenk
Browse files

Introduce BubbleBarLocation to define bubble bar location

BubbleBarLocation allows bubble bar to be positioned at the default location.
This is on the right side for LTR languages and on the left for RTL.
In addition it includes values for left and right. This allows overriding
of the default position. And pin the bar to either side.
The bar does not animate between the two states. And will immediately show
on the other side when an update is received.

Bug: 313661121
Flag: ACONFIG com.android.wm.shell.enable_bubble_bar DEVELOPMENT
Test: atest WMShellUnitTests
Change-Id: I498b20d5e7fac1d5aacdcff6a903864d6bb57ffa
parent a4f4dfc9
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.wm.shell.R
import com.android.wm.shell.bubbles.BubblePositioner.MAX_HEIGHT
import com.android.wm.shell.common.bubbles.BubbleBarLocation
import com.google.common.truth.Truth.assertThat
import com.google.common.util.concurrent.MoreExecutors.directExecutor
import org.junit.Before
@@ -486,6 +487,32 @@ class BubblePositionerTest {
                positioner.screenRect.width() - paddings[0] - paddings[2])
    }

    @Test
    fun testIsBubbleBarOnLeft_defaultsToRight() {
        positioner.bubbleBarLocation = BubbleBarLocation.DEFAULT
        assertThat(positioner.isBubbleBarOnLeft).isFalse()

        // Check that left and right return expected position
        positioner.bubbleBarLocation = BubbleBarLocation.LEFT
        assertThat(positioner.isBubbleBarOnLeft).isTrue()
        positioner.bubbleBarLocation = BubbleBarLocation.RIGHT
        assertThat(positioner.isBubbleBarOnLeft).isFalse()
    }

    @Test
    fun testIsBubbleBarOnLeft_rtlEnabled_defaultsToLeft() {
        positioner.update(defaultDeviceConfig.copy(isRtl = true))

        positioner.bubbleBarLocation = BubbleBarLocation.DEFAULT
        assertThat(positioner.isBubbleBarOnLeft).isTrue()

        // Check that left and right return expected position
        positioner.bubbleBarLocation = BubbleBarLocation.LEFT
        assertThat(positioner.isBubbleBarOnLeft).isTrue()
        positioner.bubbleBarLocation = BubbleBarLocation.RIGHT
        assertThat(positioner.isBubbleBarOnLeft).isFalse()
    }

    private val defaultYPosition: Float
        /**
         * Calculates the Y position bubbles should be placed based on the config. Based on the
+26 −1
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ import com.android.wm.shell.common.TaskStackListenerCallback;
import com.android.wm.shell.common.TaskStackListenerImpl;
import com.android.wm.shell.common.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.common.bubbles.BubbleBarLocation;
import com.android.wm.shell.common.bubbles.BubbleBarUpdate;
import com.android.wm.shell.draganddrop.DragAndDropController;
import com.android.wm.shell.onehanded.OneHandedController;
@@ -708,6 +709,30 @@ public class BubbleController implements ConfigurationChangeListener,
        return mBubbleProperties.isBubbleBarEnabled() && mBubblePositioner.isLargeScreen();
    }

    /**
     * Returns current {@link BubbleBarLocation} if bubble bar is being used.
     * Otherwise returns <code>null</code>
     */
    @Nullable
    public BubbleBarLocation getBubbleBarLocation() {
        if (canShowAsBubbleBar()) {
            return mBubblePositioner.getBubbleBarLocation();
        }
        return null;
    }

    /**
     * Update bubble bar location and trigger and update to listeners
     */
    public void setBubbleBarLocation(BubbleBarLocation bubbleBarLocation) {
        if (canShowAsBubbleBar()) {
            mBubblePositioner.setBubbleBarLocation(bubbleBarLocation);
            BubbleBarUpdate bubbleBarUpdate = new BubbleBarUpdate();
            bubbleBarUpdate.bubbleBarLocation = bubbleBarLocation;
            mBubbleStateListener.onBubbleStateChange(bubbleBarUpdate);
        }
    }

    /** Whether this userId belongs to the current user. */
    private boolean isCurrentProfile(int userId) {
        return userId == UserHandle.USER_ALL
@@ -1179,7 +1204,7 @@ public class BubbleController implements ConfigurationChangeListener,
     */
    @VisibleForTesting
    public void expandStackAndSelectBubbleFromLauncher(String key, Rect bubbleBarBounds) {
        mBubblePositioner.setBubbleBarPosition(bubbleBarBounds);
        mBubblePositioner.setBubbleBarBounds(bubbleBarBounds);

        if (BubbleOverflow.KEY.equals(key)) {
            mBubbleData.setSelectedBubbleFromLauncher(mBubbleData.getOverflow());
+3 −1
Original line number Diff line number Diff line
@@ -255,7 +255,9 @@ public class BubbleData {
     * Returns a bubble bar update populated with the current list of active bubbles.
     */
    public BubbleBarUpdate getInitialStateForBubbleBar() {
        return mStateChange.getInitialState();
        BubbleBarUpdate initialState = mStateChange.getInitialState();
        initialState.bubbleBarLocation = mPositioner.getBubbleBarLocation();
        return initialState;
    }

    public void setSuppressionChangedListener(Bubbles.BubbleMetadataFlagListener listener) {
+25 −8
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.protolog.common.ProtoLog;
import com.android.launcher3.icons.IconNormalizer;
import com.android.wm.shell.R;
import com.android.wm.shell.common.bubbles.BubbleBarLocation;

/**
 * Keeps track of display size, configuration, and specific bubble sizes. One place for all
@@ -95,6 +96,7 @@ public class BubblePositioner {
    private PointF mRestingStackPosition;

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

    public BubblePositioner(Context context, WindowManager windowManager) {
@@ -797,13 +799,35 @@ public class BubblePositioner {
        mShowingInBubbleBar = showingInBubbleBar;
    }

    public void setBubbleBarLocation(BubbleBarLocation location) {
        mBubbleBarLocation = location;
    }

    public BubbleBarLocation getBubbleBarLocation() {
        return mBubbleBarLocation;
    }

    /**
     * @return <code>true</code> when bubble bar is on the left and <code>false</code> when on right
     */
    public boolean isBubbleBarOnLeft() {
        return mBubbleBarLocation.isOnLeft(mDeviceConfig.isRtl());
    }

    /**
     * Sets the position of the bubble bar in display coordinates.
     */
    public void setBubbleBarPosition(Rect bubbleBarBounds) {
    public void setBubbleBarBounds(Rect bubbleBarBounds) {
        mBubbleBarBounds.set(bubbleBarBounds);
    }

    /**
     * Returns the display coordinates of the bubble bar.
     */
    public Rect getBubbleBarBounds() {
        return mBubbleBarBounds;
    }

    /**
     * How wide the expanded view should be when showing from the bubble bar.
     */
@@ -831,11 +855,4 @@ public class BubblePositioner {
    public int getBubbleBarExpandedViewPadding() {
        return mExpandedViewPadding;
    }

    /**
     * Returns the display coordinates of the bubble bar.
     */
    public Rect getBubbleBarBounds() {
        return mBubbleBarBounds;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -477,7 +477,7 @@ public class BubbleBarAnimationHelper {
    private Point getExpandedViewRestPosition(Size size) {
        final int padding = mPositioner.getBubbleBarExpandedViewPadding();
        Point point = new Point();
        if (mLayerView.isOnLeft()) {
        if (mPositioner.isBubbleBarOnLeft()) {
            point.x = mPositioner.getInsets().left + padding;
        } else {
            point.x = mPositioner.getAvailableRect().width() - size.getWidth() - padding;
Loading