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

Commit 64005e04 authored by Mykola Podolian's avatar Mykola Podolian Committed by Android (Google) Code Review
Browse files

Merge "Added required changes to use DropTargetManager in Launcher." into main

parents 27d28381 416c453a
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)
    }