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

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

Merge "Introduce bubble drag indicators" into main

parents c533272a 884afc81
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -295,6 +295,10 @@
    <dimen name="bubble_bar_dismiss_zone_width">192dp</dimen>
    <!-- Height of the box around bottom center of the screen where drag only leads to dismiss -->
    <dimen name="bubble_bar_dismiss_zone_height">242dp</dimen>
    <!-- Height of the box at the corner of the screen where drag leads to app moving to bubble -->
    <dimen name="bubble_transform_area_width">140dp</dimen>
    <!-- Width of the box at the corner of the screen where drag leads to app moving to bubble -->
    <dimen name="bubble_transform_area_height">140dp</dimen>

    <!-- Bottom and end margin for compat buttons. -->
    <dimen name="compat_button_margin">24dp</dimen>
+51 −4
Original line number Diff line number Diff line
@@ -76,7 +76,11 @@ public class DesktopModeVisualIndicator {
        /** Indicates impending transition into split select on the left side */
        TO_SPLIT_LEFT_INDICATOR,
        /** Indicates impending transition into split select on the right side */
        TO_SPLIT_RIGHT_INDICATOR
        TO_SPLIT_RIGHT_INDICATOR,
        /** Indicates impending transition into bubble on the left side */
        TO_BUBBLE_LEFT_INDICATOR,
        /** Indicates impending transition into bubble on the right side */
        TO_BUBBLE_RIGHT_INDICATOR
    }

    /**
@@ -175,15 +179,24 @@ public class DesktopModeVisualIndicator {
                captionHeight);
        final Region splitRightRegion = calculateSplitRightRegion(layout, transitionAreaWidth,
                captionHeight);
        if (fullscreenRegion.contains((int) inputCoordinates.x, (int) inputCoordinates.y)) {
        final int x = (int) inputCoordinates.x;
        final int y = (int) inputCoordinates.y;
        if (fullscreenRegion.contains(x, y)) {
            result = TO_FULLSCREEN_INDICATOR;
        }
        if (splitLeftRegion.contains((int) inputCoordinates.x, (int) inputCoordinates.y)) {
        if (splitLeftRegion.contains(x, y)) {
            result = IndicatorType.TO_SPLIT_LEFT_INDICATOR;
        }
        if (splitRightRegion.contains((int) inputCoordinates.x, (int) inputCoordinates.y)) {
        if (splitRightRegion.contains(x, y)) {
            result = IndicatorType.TO_SPLIT_RIGHT_INDICATOR;
        }
        if (BubbleAnythingFlagHelper.enableBubbleToFullscreen()) {
            if (calculateBubbleLeftRegion(layout).contains(x, y)) {
                result = IndicatorType.TO_BUBBLE_LEFT_INDICATOR;
            } else if (calculateBubbleRightRegion(layout).contains(x, y)) {
                result = IndicatorType.TO_BUBBLE_RIGHT_INDICATOR;
            }
        }
        if (mDragStartState != DragStartState.DRAGGED_INTENT) {
            transitionIndicator(result);
        }
@@ -247,6 +260,25 @@ public class DesktopModeVisualIndicator {
        return region;
    }

    @VisibleForTesting
    Region calculateBubbleLeftRegion(DisplayLayout layout) {
        int regionWidth = mContext.getResources().getDimensionPixelSize(
                com.android.wm.shell.R.dimen.bubble_transform_area_width);
        int regionHeight = mContext.getResources().getDimensionPixelSize(
                com.android.wm.shell.R.dimen.bubble_transform_area_height);
        return new Region(0, layout.height() - regionHeight, regionWidth, layout.height());
    }

    @VisibleForTesting
    Region calculateBubbleRightRegion(DisplayLayout layout) {
        int regionWidth = mContext.getResources().getDimensionPixelSize(
                com.android.wm.shell.R.dimen.bubble_transform_area_width);
        int regionHeight = mContext.getResources().getDimensionPixelSize(
                com.android.wm.shell.R.dimen.bubble_transform_area_height);
        return new Region(layout.width() - regionWidth, layout.height() - regionHeight,
                layout.width(), layout.height());
    }

    /**
     * Create a fullscreen indicator with no animation
     */
@@ -481,6 +513,21 @@ public class DesktopModeVisualIndicator {
                    return new Rect(desktopStableBounds.width() / 2 + padding, padding,
                            desktopStableBounds.width() - padding,
                            desktopStableBounds.height());
                case TO_BUBBLE_LEFT_INDICATOR:
                    // TODO(b/388851898): define based on bubble size on the device
                    return new Rect(
                            padding,
                            desktopStableBounds.height() / 2 - padding,
                            desktopStableBounds.width() / 2 - padding,
                            desktopStableBounds.height());
                case TO_BUBBLE_RIGHT_INDICATOR:
                    // TODO(b/388851898): define based on bubble size on the device
                    return new Rect(
                            desktopStableBounds.width() / 2 + padding,
                            desktopStableBounds.height() / 2 - padding,
                            desktopStableBounds.width() - padding,
                            desktopStableBounds.height()
                    );
                default:
                    throw new IllegalArgumentException("Invalid indicator type provided.");
            }
+10 −1
Original line number Diff line number Diff line
@@ -2788,7 +2788,11 @@ class DesktopTasksController(
                    desktopModeWindowDecoration,
                )
            }
            IndicatorType.NO_INDICATOR -> {
            IndicatorType.NO_INDICATOR,
            IndicatorType.TO_BUBBLE_LEFT_INDICATOR,
            IndicatorType.TO_BUBBLE_RIGHT_INDICATOR -> {
                // TODO(b/391928049): add support fof dragging desktop apps to a bubble

                // Create a copy so that we can animate from the current bounds if we end up having
                // to snap the surface back without a WCT change.
                val destinationBounds = Rect(currentDragBounds)
@@ -2915,6 +2919,11 @@ class DesktopTasksController(
                )
                requestSplit(taskInfo, leftOrTop = false)
            }
            IndicatorType.TO_BUBBLE_LEFT_INDICATOR,
            IndicatorType.TO_BUBBLE_RIGHT_INDICATOR -> {
                // TODO(b/388851898): move to bubble
                cancelDragToDesktop(taskInfo)
            }
        }
        return indicatorType
    }
+53 −5
Original line number Diff line number Diff line
@@ -193,6 +193,40 @@ class DesktopModeVisualIndicatorTest : ShellTestCase() {
        assertThat(testRegion.bounds).isEqualTo(Rect(2368, -50, 2400, 1600))
    }

    @Test
    fun testBubbleLeftRegionCalculation() {
        val bubbleRegionWidth =
            context.resources.getDimensionPixelSize(R.dimen.bubble_transform_area_width)
        val bubbleRegionHeight =
            context.resources.getDimensionPixelSize(R.dimen.bubble_transform_area_height)
        val expectedRect = Rect(0, 1600 - bubbleRegionHeight, bubbleRegionWidth, 1600)

        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_FULLSCREEN)
        var testRegion = visualIndicator.calculateBubbleLeftRegion(displayLayout)
        assertThat(testRegion.bounds).isEqualTo(expectedRect)

        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_SPLIT)
        testRegion = visualIndicator.calculateBubbleLeftRegion(displayLayout)
        assertThat(testRegion.bounds).isEqualTo(expectedRect)
    }

    @Test
    fun testBubbleRightRegionCalculation() {
        val bubbleRegionWidth =
            context.resources.getDimensionPixelSize(R.dimen.bubble_transform_area_width)
        val bubbleRegionHeight =
            context.resources.getDimensionPixelSize(R.dimen.bubble_transform_area_height)
        val expectedRect = Rect(2400 - bubbleRegionWidth, 1600 - bubbleRegionHeight, 2400, 1600)

        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_FULLSCREEN)
        var testRegion = visualIndicator.calculateBubbleRightRegion(displayLayout)
        assertThat(testRegion.bounds).isEqualTo(expectedRect)

        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_SPLIT)
        testRegion = visualIndicator.calculateBubbleRightRegion(displayLayout)
        assertThat(testRegion.bounds).isEqualTo(expectedRect)
    }

    @Test
    fun testDefaultIndicators() {
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_FULLSCREEN)
@@ -219,26 +253,40 @@ class DesktopModeVisualIndicatorTest : ShellTestCase() {
    fun testDefaultIndicatorWithNoDesktop() {
        whenever(DesktopModeStatus.canEnterDesktopMode(any())).thenReturn(false)

        // Fullscreen to center, no desktop indicator
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_FULLSCREEN)
        var result = visualIndicator.updateIndicatorType(PointF(500f, 500f))
        assertThat(result).isEqualTo(DesktopModeVisualIndicator.IndicatorType.NO_INDICATOR)

        // Fullscreen to split
        result = visualIndicator.updateIndicatorType(PointF(10000f, 500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_RIGHT_INDICATOR)

        result = visualIndicator.updateIndicatorType(PointF(-10000f, 500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_LEFT_INDICATOR)

        // Fullscreen to bubble
        result = visualIndicator.updateIndicatorType(PointF(100f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_LEFT_INDICATOR)
        result = visualIndicator.updateIndicatorType(PointF(2300f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_RIGHT_INDICATOR)
        // Split to center, no desktop indicator
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_SPLIT)
        result = visualIndicator.updateIndicatorType(PointF(500f, 500f))
        assertThat(result).isEqualTo(DesktopModeVisualIndicator.IndicatorType.NO_INDICATOR)

        // Split to fullscreen
        result = visualIndicator.updateIndicatorType(PointF(500f, 0f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_FULLSCREEN_INDICATOR)

        // Split to bubble
        result = visualIndicator.updateIndicatorType(PointF(100f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_LEFT_INDICATOR)
        result = visualIndicator.updateIndicatorType(PointF(2300f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_RIGHT_INDICATOR)
        // Drag app to center, no desktop indicator
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.DRAGGED_INTENT)
        result = visualIndicator.updateIndicatorType(PointF(500f, 500f))
        assertThat(result).isEqualTo(DesktopModeVisualIndicator.IndicatorType.NO_INDICATOR)