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

Commit a0d8e5fb authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge changes from topic "bubble-bar-drag" into main

* changes:
  Support expanded view drag to left or right
  Introduce BubbleBarLocation to define bubble bar location
parents 9fe5e6f2 a3403943
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());
+4 −2
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class BubbleData {
         * used when {@link BubbleController#isShowingAsBubbleBar()} is true.
         */
        BubbleBarUpdate getInitialState() {
            BubbleBarUpdate bubbleBarUpdate = new BubbleBarUpdate();
            BubbleBarUpdate bubbleBarUpdate = BubbleBarUpdate.createInitialState();
            bubbleBarUpdate.shouldShowEducation = shouldShowEducation;
            for (int i = 0; i < bubbles.size(); i++) {
                bubbleBarUpdate.currentBubbleList.add(bubbles.get(i).asBubbleBarBubble());
@@ -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