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

Commit 416c453a authored by Mykola Podolian's avatar Mykola Podolian
Browse files

Added required changes to use DropTargetManager in Launcher.

Updated DragZoneFactory to provide bubble bar drop zone Rect. Do not
remove secondDropTargetView from parent container if there is no drop
zone.

Bug: 411506181
Flag: com.android.wm.shell.enable_create_any_bubble
Test: Manual. Go to overview screen and drag app icons from the taskbar
over the bubble bar

Change-Id: Ib2791ac16dbc91fd8372d726b896ac0ba2bf9e64
parent f3df552c
Loading
Loading
Loading
Loading
+17 −24
Original line number Diff line number Diff line
@@ -245,6 +245,21 @@ class DragZoneFactory(
        return dragZones
    }

    fun getBubbleBarDropRect(isLeftSide: Boolean): Rect {
        val dragZoneSize =
            if (deviceConfig.isSmallTablet) {
                bubbleDragZoneFoldableSize
            } else {
                bubbleDragZoneTabletSize
            }
        return Rect(
            if (isLeftSide) 0 else windowBounds.right - dragZoneSize,
            windowBounds.bottom - dragZoneSize,
            if (isLeftSide) dragZoneSize else windowBounds.right,
            windowBounds.bottom
        )
    }

    private fun createDismissDragZone(): DragZone {
        return DragZone.Dismiss(
            bounds =
@@ -257,36 +272,14 @@ class DragZoneFactory(
    }

    private fun createBubbleCornerDragZones(showSecondDropTarget: Boolean = false): List<DragZone> {
        val dragZoneSize =
            if (deviceConfig.isSmallTablet) {
                bubbleDragZoneFoldableSize
            } else {
                bubbleDragZoneTabletSize
            }
        return listOf(
            DragZone.Bubble.Left(
                bounds =
                    RectZone(
                        Rect(
                            0,
                            windowBounds.bottom - dragZoneSize,
                            dragZoneSize,
                            windowBounds.bottom,
                        ),
                    ),
                bounds = RectZone(getBubbleBarDropRect(isLeftSide = true)),
                dropTarget = expandedViewDropTargetLeft,
                secondDropTarget = if (showSecondDropTarget) bubbleBarDropTargetLeft else null
            ),
            DragZone.Bubble.Right(
                bounds =
                    RectZone(
                        Rect(
                            windowBounds.right - dragZoneSize,
                            windowBounds.bottom - dragZoneSize,
                            windowBounds.right,
                            windowBounds.bottom,
                        ),
                    ),
                bounds = RectZone(getBubbleBarDropRect(isLeftSide = false)),
                dropTarget = expandedViewDropTargetRight,
                secondDropTarget = if (showSecondDropTarget) bubbleBarDropTargetRight else null
            )
+1 −3
Original line number Diff line number Diff line
@@ -140,9 +140,7 @@ class DropTargetManager(
        val currentDragZone = dropState.currentDragZone
        if (currentDragZone == null) {
            startFadeAnimation(dropTargetView, to = 0f)
            startFadeAnimation(secondDropTargetView, to = 0f) {
                container.removeView(secondDropTargetView)
            }
            startFadeAnimation(secondDropTargetView, to = 0f)
            return
        }
        val dropTargetRect = currentDragZone.dropTarget
+38 −0
Original line number Diff line number Diff line
@@ -515,6 +515,44 @@ class DropTargetManagerTest {
        assertThat(runnableExecuted).isTrue()
    }

    @Test
    fun onDragUpdated_reEnterZoneWithMultipleDropTargetViews_dropTargetsShown() {
        dropTargetManager.onDragStarted(
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = false) {},
            listOf(bubbleLeftDragZoneWithSecondDropTarget, bubbleRightDragZoneWithSecondDropTarget)
        )
        val pointX = 200
        val pointY = 200
        assertThat(bubbleLeftDragZone.contains(pointX, pointY)).isFalse()
        assertThat(bubbleRightDragZone.contains(pointX, pointY)).isFalse()
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            dropTargetManager.onDragUpdated(
                bubbleRightDragZoneWithSecondDropTarget.bounds.rect.centerX(),
                bubbleRightDragZoneWithSecondDropTarget.bounds.rect.centerY()
            )
            animatorTestRule.advanceTimeBy(250)
        }
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            dropTargetManager.onDragUpdated(pointX, pointY)
            animatorTestRule.advanceTimeBy(250)
        }
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            dropTargetManager.onDragUpdated(
                bubbleRightDragZoneWithSecondDropTarget.bounds.rect.centerX(),
                bubbleRightDragZoneWithSecondDropTarget.bounds.rect.centerY()
            )
            animatorTestRule.advanceTimeBy(250)
        }
        assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_FOR_LAUNCHER_ICON)
        assertThat(dropTargetView.alpha).isEqualTo(1)
        assertThat(secondDropTargetView!!.alpha).isEqualTo(1)
        verifyDropTargetPosition(bubbleRightDragZoneWithSecondDropTarget.dropTarget.rect)
        verifyDropTargetPosition(
            secondDropTargetView!!,
            bubbleRightDragZoneWithSecondDropTarget.secondDropTarget!!.rect
        )
    }

    private fun verifyDropTargetPosition(rect: Rect) {
        verifyDropTargetPosition(dropTargetView, rect)
    }