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

Commit d9dc8907 authored by mpodolian's avatar mpodolian
Browse files

Updated LauncherIcon to only show secondary drop target

Introduce LauncherIcon support of only displaying only secondary drop
target for the scenario when expanded view is show in shell and the
bubble bar can not be shown from shell.
It is not possible to show both views in the shell since the taskbar
window is on top of the shell window (layering issue).

Bug: 411505605
Test: DropTargetManagerTest
Test: DragZoneFactoryTest
Flag: com.android.wm.shell.enable_create_any_bubble
Change-Id: Id04f71730af9f50af9c61790357e3bfed4f870a4
parent 3459bbe4
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -57,17 +57,17 @@ sealed interface DragZone {
    /** Represents the bubble drag area on the screen. */
    sealed class Bubble(
        override val bounds: Bounds.RectZone,
        override val dropTarget: DropTargetRect,
        override val dropTarget: DropTargetRect?,
    ) : DragZone {
        data class Left(
            override val bounds: Bounds.RectZone,
            override val dropTarget: DropTargetRect,
            override val dropTarget: DropTargetRect?,
            override val secondDropTarget: DropTargetRect? = null,
        ) : Bubble(bounds, dropTarget)

        data class Right(
            override val bounds: Bounds.RectZone,
            override val dropTarget: DropTargetRect,
            override val dropTarget: DropTargetRect?,
            override val secondDropTarget: DropTargetRect? = null,
        ) : Bubble(bounds, dropTarget)
    }
+8 −4
Original line number Diff line number Diff line
@@ -240,8 +240,9 @@ class DragZoneFactory(
                dragZones.addAll(createBubbleHalfScreenDragZones(forBubbleBar = false))
            }
            is DraggedObject.LauncherIcon -> {
                val showDropTarget = draggedObject.showDropTarget
                val showSecondDropTarget = !draggedObject.bubbleBarHasBubbles
                dragZones.addAll(createBubbleCornerDragZones(showSecondDropTarget))
                dragZones.addAll(createBubbleCornerDragZones(showDropTarget, showSecondDropTarget))
            }
        }
        return dragZones
@@ -273,16 +274,19 @@ class DragZoneFactory(
        )
    }

    private fun createBubbleCornerDragZones(showSecondDropTarget: Boolean = false): List<DragZone> {
    private fun createBubbleCornerDragZones(
        showDropTarget: Boolean = true,
        showSecondDropTarget: Boolean = false
    ): List<DragZone> {
        return listOf(
            DragZone.Bubble.Left(
                bounds = RectZone(getBubbleBarDropRect(isLeftSide = true)),
                dropTarget = expandedViewDropTargetLeft,
                dropTarget = if (showDropTarget) expandedViewDropTargetLeft else null,
                secondDropTarget = if (showSecondDropTarget) bubbleBarDropTargetLeft else null
            ),
            DragZone.Bubble.Right(
                bounds = RectZone(getBubbleBarDropRect(isLeftSide = false)),
                dropTarget = expandedViewDropTargetRight,
                dropTarget = if (showDropTarget) expandedViewDropTargetRight else null,
                secondDropTarget = if (showSecondDropTarget) bubbleBarDropTargetRight else null
            )
        )
+6 −3
Original line number Diff line number Diff line
@@ -25,7 +25,10 @@ sealed interface DraggedObject {

    data class ExpandedView(val initialLocation: BubbleBarLocation) : DraggedObject

    // TODO(b/411505605) Remove onDropAction
    data class LauncherIcon(val bubbleBarHasBubbles: Boolean, val onDropAction: Runnable) :
        DraggedObject
    // TODO(b/411505605) Remove onDropAction and move showDropTarget up
    data class LauncherIcon(
        val bubbleBarHasBubbles: Boolean,
        val showDropTarget: Boolean = true,
        val onDropAction: Runnable
    ) : DraggedObject
}
+28 −0
Original line number Diff line number Diff line
@@ -412,10 +412,38 @@ class DragZoneFactoryTest {
        }
    }

    @Test
    fun dragZonesForLauncherIcon_bubbleBarHasNoBubblesDoNotShowDropTarget() {
        dragZoneFactory =
            DragZoneFactory(
                context,
                tabletPortrait,
                splitScreenModeChecker,
                desktopWindowModeChecker,
                bubbleBarPropertiesProvider,
            )
        val dragZones =
            dragZoneFactory.createSortedDragZones(
                DraggedObject.LauncherIcon(showDropTarget = false, bubbleBarHasBubbles = false) { }
            )
        val expectedZones: List<DragZoneVerifier> =
            listOf(verifyInstance<DragZone.Bubble.Left>(), verifyInstance<DragZone.Bubble.Right>())
        assertThat(dragZones).hasSize(expectedZones.size)
        dragZones.zip(expectedZones).forEach { (zone, instanceVerifier) ->
            instanceVerifier(zone)
            zone.verifyDropZone(isPresent = false)
            zone.verifySecondaryDropZone(isPresent = true)
        }
    }

    private inline fun <reified T> verifyInstance(): DragZoneVerifier = { dragZone ->
        assertThat(dragZone).isInstanceOf(T::class.java)
    }

    private fun DragZone.verifyDropZone(isPresent: Boolean) {
        assertThat(dropTarget != null == isPresent).isTrue()
    }

    private fun DragZone.verifySecondaryDropZone(isPresent: Boolean) {
        assertThat(secondDropTarget != null == isPresent).isTrue()
    }
+49 −12
Original line number Diff line number Diff line
@@ -61,6 +61,12 @@ class DropTargetManagerTest {
            bounds = RectZone(Rect(0, 0, 100, 100)),
            dropTarget = DropTargetRect(Rect(0, 0, 50, 200), cornerRadius = 30f)
        )
    private val bubbleLeftDragZoneOnlySecondDropTarget =
        DragZone.Bubble.Left(
            bounds = RectZone(Rect(0, 0, 100, 100)),
            dropTarget = null,
            secondDropTarget = DropTargetRect(Rect(0, 250, 50, 300), cornerRadius = 25f)
        )
    private val bubbleLeftDragZoneWithSecondDropTarget =
        DragZone.Bubble.Left(
            bounds = RectZone(Rect(0, 0, 100, 100)),
@@ -74,6 +80,12 @@ class DropTargetManagerTest {
            bounds = RectZone(Rect(200, 0, 300, 100)),
            dropTarget = DropTargetRect(Rect(200, 0, 280, 150), cornerRadius = 30f)
        )
    private val bubbleRightDragZoneOnlySecondDropTarget =
        DragZone.Bubble.Right(
            bounds = RectZone(Rect(200, 0, 300, 100)),
            dropTarget = null,
            secondDropTarget = DropTargetRect(Rect(200, 200, 80, 280), cornerRadius = 25f)
        )
    private val bubbleRightDragZoneWithSecondDropTarget =
        DragZone.Bubble.Right(
            bounds = RectZone(Rect(200, 0, 300, 100)),
@@ -321,7 +333,7 @@ class DropTargetManagerTest {
        }

        assertThat(dropTargetView.alpha).isEqualTo(1)
        verifyDropTargetPosition(bubbleRightDragZone.dropTarget.rect)
        verifyDropTargetPosition(bubbleRightDragZone.dropTarget!!.rect)
    }

    @Test
@@ -358,7 +370,7 @@ class DropTargetManagerTest {
        }

        assertThat(dropTargetView.alpha).isEqualTo(1)
        verifyDropTargetPosition(bubbleRightDragZone.dropTarget.rect)
        verifyDropTargetPosition(bubbleRightDragZone.dropTarget!!.rect)

        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            val dragZone = dropTargetManager.onDragUpdated(
@@ -370,7 +382,7 @@ class DropTargetManagerTest {
        }

        assertThat(dropTargetView.alpha).isEqualTo(1)
        verifyDropTargetPosition(bubbleLeftDragZone.dropTarget.rect)
        verifyDropTargetPosition(bubbleLeftDragZone.dropTarget!!.rect)
    }

    @Test
@@ -403,7 +415,7 @@ class DropTargetManagerTest {
    fun onDragUpdated_noZoneToZoneWithDropTargetView_listenerNotified() {
        val onDropAction = Runnable { }
        dropTargetManager.onDragStarted(
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = true, onDropAction),
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = true, onDropAction = onDropAction),
            listOf(bubbleLeftDragZone, bubbleRightDragZone)
        )

@@ -441,7 +453,7 @@ class DropTargetManagerTest {
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT)
        assertThat(dropTargetView.alpha).isEqualTo(1)
        assertThat(secondDropTargetView).isNull()
        verifyDropTargetPosition(bubbleLeftDragZone.dropTarget.rect)
        verifyDropTargetPosition(bubbleLeftDragZone.dropTarget!!.rect)
    }

    @Test
@@ -460,16 +472,41 @@ class DropTargetManagerTest {
            animatorTestRule.advanceTimeBy(250)
        }

        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_LAUNCHER_ICON)
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)
        assertThat(dropTargetView.alpha).isEqualTo(1)
        assertThat(secondDropTargetView!!.alpha).isEqualTo(1)
        verifyDropTargetPosition(bubbleRightDragZoneWithSecondDropTarget.dropTarget.rect)
        verifyDropTargetPosition(bubbleRightDragZoneWithSecondDropTarget.dropTarget!!.rect)
        verifyDropTargetPosition(
            secondDropTargetView!!,
            bubbleRightDragZoneWithSecondDropTarget.secondDropTarget!!.rect
        )
    }

    @Test
    fun onDragUpdated_noZoneToZoneWithOnlySecondDropTargetView_secondDropTargetShown() {
        dropTargetManager.onDragStarted(
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = false) {},
            listOf(bubbleLeftDragZoneOnlySecondDropTarget, bubbleRightDragZoneOnlySecondDropTarget)
        )

        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            val dragZone = dropTargetManager.onDragUpdated(
                bubbleRightDragZoneOnlySecondDropTarget.bounds.rect.centerX(),
                bubbleRightDragZoneOnlySecondDropTarget.bounds.rect.centerY()
            )
            assertThat(dragZone).isNotNull()
            animatorTestRule.advanceTimeBy(250)
        }

        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)
        assertThat(dropTargetView.alpha).isEqualTo(0)
        assertThat(secondDropTargetView!!.alpha).isEqualTo(1)
        verifyDropTargetPosition(
            secondDropTargetView!!,
            bubbleRightDragZoneOnlySecondDropTarget.secondDropTarget!!.rect
        )
    }

    @Test
    fun runOnDropTargetsRemoved_dropTargetViewsAdded_notExecutedUntilAllViewsRemoved() {
        var runnableExecuted = false
@@ -478,14 +515,14 @@ class DropTargetManagerTest {
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = false) {},
            listOf(bubbleLeftDragZoneWithSecondDropTarget, bubbleRightDragZoneWithSecondDropTarget)
        )
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_LAUNCHER_ICON)
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)
        dropTargetManager.onDropTargetRemoved(action)
        assertThat(runnableExecuted).isFalse()

        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            dropTargetManager.onDragEnded()
        }
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_LAUNCHER_ICON)
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)
        assertThat(runnableExecuted).isFalse()

        InstrumentationRegistry.getInstrumentation().runOnMainSync {
@@ -543,10 +580,10 @@ class DropTargetManagerTest {
            )
            animatorTestRule.advanceTimeBy(250)
        }
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_LAUNCHER_ICON)
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)
        assertThat(dropTargetView.alpha).isEqualTo(1)
        assertThat(secondDropTargetView!!.alpha).isEqualTo(1)
        verifyDropTargetPosition(bubbleRightDragZoneWithSecondDropTarget.dropTarget.rect)
        verifyDropTargetPosition(bubbleRightDragZoneWithSecondDropTarget.dropTarget!!.rect)
        verifyDropTargetPosition(
            secondDropTargetView!!,
            bubbleRightDragZoneWithSecondDropTarget.secondDropTarget!!.rect
@@ -592,6 +629,6 @@ class DropTargetManagerTest {

    companion object {
        const val DROP_VIEWS_COUNT = 1
        const val DROP_VIEWS_COUNT_FOR_LAUNCHER_ICON = 2
        const val DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS = 2
    }
}
 No newline at end of file