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

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

Merge changes from topic "showing_drop_target_ipc" into main

* changes:
  Added IPC call to inform launcher of item was dragged over drop zone
  Update logic to cover all the drop target cases in Launcher
parents 252f1f06 e2bc9cc7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -500,5 +500,7 @@ class BubbleControllerBubbleBarTest {
        override fun animateBubbleBarLocation(location: BubbleBarLocation?) {}

        override fun showBubbleBarPillowAt(location: BubbleBarLocation?) {}

        override fun showBubbleBarDropTargetAt(location: BubbleBarLocation?) {}
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -30,4 +30,6 @@ class FakeBubblesStateListener : Bubbles.BubbleStateListener {
    override fun animateBubbleBarLocation(location: BubbleBarLocation?) {}

    override fun showBubbleBarPillowAt(location: BubbleBarLocation?) {}

    override fun showBubbleBarDropTargetAt(location: BubbleBarLocation?) {}
}
+30 −141
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
@@ -92,6 +91,16 @@ class DragToBubbleControllerTest {
        assertThat(dropTargetView.parent).isEqualTo(dropTargetContainer)
    }

    @Test
    fun dragStarted_isDropHandled_cleared() {
        dragToBubbleController.isDropHandled = true

        dragToBubbleController.onDragStarted()

        // Once drag is started again isDropHandled should be cleared
        assertThat(dragToBubbleController.isDropHandled).isFalse()
    }

    @Test
    fun dragStarted_multipleTimes_dropZoneAddedOnlyOnce() {
        repeat(10) { dragToBubbleController.onDragStarted() }
@@ -117,146 +126,6 @@ class DragToBubbleControllerTest {
        assertThat(dropTargetContainer.childCount).isEqualTo(0)
    }

    @Test
    fun draggedToTheRightDropZone_noBubbles_dropTargetViewShown_bubbleBarDropTargetShowRequested() {
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(rightDropRect.centerX(), rightDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }

        assertThat(dropTargetView.alpha).isEqualTo(1f)
        verify(bubbleController).showBubbleBarPinAtLocation(BubbleBarLocation.RIGHT)
        verify(bubbleController, never()).animateBubbleBarLocation(any())
    }

    @Test
    fun draggedToTheRightDropZone_bubbleOnTheRight_dropTargetShown_locationUpdatedNotRequested() {
        prepareBubbleController(hasBubbles = true, bubbleBarLocation = BubbleBarLocation.RIGHT)
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(rightDropRect.centerX(), rightDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }

        assertThat(dropTargetView.alpha).isEqualTo(1f)
        verify(bubbleController, never()).showBubbleBarPinAtLocation(any())
        verify(bubbleController, never()).showBubbleBarPinAtLocation(any())
    }

    @Test
    fun draggedToTheLeftDropZone_hasBubblesOnTheRight_bubbleBarLocationChangeRequested() {
        prepareBubbleController(hasBubbles = true, bubbleBarLocation = BubbleBarLocation.RIGHT)
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(leftDropRect.centerX(), leftDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }
        verify(bubbleController).animateBubbleBarLocation(BubbleBarLocation.LEFT)
    }

    @Test
    fun draggedToTheLeftDropZone_dragEnded_noBubblesOnTheRight_pinViewHideRequested() {
        val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT
        prepareBubbleController(hasBubbles = false, bubbleBarLocation = bubbleBarOriginalLocation)
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(leftDropRect.centerX(), leftDropRect.centerY())
            dragToBubbleController.onDragEnded()
        }

        verify(bubbleController).showBubbleBarPinAtLocation(BubbleBarLocation.LEFT)
        verify(bubbleController).showBubbleBarPinAtLocation(null)
        assertThat(dropTargetContainer.childCount).isEqualTo(1)

        runOnMainSync { animatorTestRule.advanceTimeBy(250) }
        assertThat(dropTargetContainer.childCount).isEqualTo(0)
    }

    @Test
    fun draggedToTheLeftDropZone_dragEnded_hasBubblesOnTheRight_locationRestored() {
        val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT
        prepareBubbleController(hasBubbles = true, bubbleBarLocation = bubbleBarOriginalLocation)
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(leftDropRect.centerX(), leftDropRect.centerY())
            dragToBubbleController.onDragEnded()
        }

        verify(bubbleController).animateBubbleBarLocation(BubbleBarLocation.LEFT)
        verify(bubbleController).animateBubbleBarLocation(bubbleBarOriginalLocation)
        assertThat(dropTargetContainer.childCount).isEqualTo(1)

        runOnMainSync { animatorTestRule.advanceTimeBy(250) }
        assertThat(dropTargetContainer.childCount).isEqualTo(0)
    }

    @Test
    fun dragBetweenLeftAndRightDropZones_hasBubblesOnRight_bubbleBarAnimatesCorrectly() {
        val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT
        prepareBubbleController(hasBubbles = true, bubbleBarLocation = bubbleBarOriginalLocation)
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(leftDropRect.centerX(), leftDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }
        verify(bubbleController).animateBubbleBarLocation(BubbleBarLocation.LEFT)

        runOnMainSync {
            // drag to no zone
            dragToBubbleController.onDragUpdate(0, 0)
            animatorTestRule.advanceTimeBy(250)
        }
        // should return to original position
        verify(bubbleController).animateBubbleBarLocation(bubbleBarOriginalLocation)
        clearInvocations(bubbleController)

        runOnMainSync {
            // drag to the same zone as bubble bar
            dragToBubbleController.onDragUpdate(rightDropRect.centerX(), rightDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }
        // should not trigger any call to animate bubble bar
        verify(bubbleController, never()).animateBubbleBarLocation(any())
    }

    @Test
    fun dragBetweenLeftAndRightDropZones_noBubblesOnRight_bubbleDropTargetShowRequestedCorrectly() {
        val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT
        prepareBubbleController(hasBubbles = false, bubbleBarLocation = bubbleBarOriginalLocation)
        dragToBubbleController.onDragStarted()

        runOnMainSync {
            dragToBubbleController.onDragUpdate(leftDropRect.centerX(), leftDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }
        // should request displaying pin on left
        verify(bubbleController).showBubbleBarPinAtLocation(BubbleBarLocation.LEFT)

        runOnMainSync {
            // drag to no zone
            dragToBubbleController.onDragUpdate(0, 0)
            animatorTestRule.advanceTimeBy(250)
        }
        // should hide pin view
        verify(bubbleController).showBubbleBarPinAtLocation(null)
        clearInvocations(bubbleController)

        runOnMainSync {
            // drag to the same zone as bubble bar
            dragToBubbleController.onDragUpdate(rightDropRect.centerX(), rightDropRect.centerY())
            animatorTestRule.advanceTimeBy(250)
        }
        // should request displaying pin at right
        verify(bubbleController).showBubbleBarPinAtLocation(BubbleBarLocation.RIGHT)
    }

    @Test
    fun droppedItemWithIntentAtTheLeftDropZone_noBubblesOnTheRight_bubbleCreationRequested() {
        val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT
@@ -273,6 +142,7 @@ class DragToBubbleControllerTest {

        verify(bubbleController)
            .expandStackAndSelectBubble(pendingIntent, userHandle, BubbleBarLocation.LEFT)
        assertThat(dragToBubbleController.isDropHandled).isTrue()
    }

    @Test
@@ -289,6 +159,25 @@ class DragToBubbleControllerTest {
        }

        verify(bubbleController).expandStackAndSelectBubble(shortcutInfo, BubbleBarLocation.LEFT)
        assertThat(dragToBubbleController.isDropHandled).isTrue()
    }

    @Test
    fun droppedItem_afterNewDragStartedOnItemDropCleared() {
        val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT
        prepareBubbleController(hasBubbles = false, bubbleBarLocation = bubbleBarOriginalLocation)
        val shortcutInfo = ShortcutInfo.Builder(context, "id").setLongLabel("Shortcut").build()
        runOnMainSync {
            dragToBubbleController.onDragStarted()
            dragToBubbleController.onDragUpdate(leftDropRect.centerX(), leftDropRect.centerY())
            dragToBubbleController.onItemDropped(shortcutInfo)
            assertThat(dragToBubbleController.isDropHandled).isTrue()
            dragToBubbleController.onDragEnded()
            animatorTestRule.advanceTimeBy(250)

            dragToBubbleController.onDragStarted()
        }
        assertThat(dragToBubbleController.isDropHandled).isFalse()
    }

    @Test
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ enum class BubbleBarLocation : Parcelable {
         * Checks whether locations are on the different sides from each other. If any of the
         * locations is null returns false.
         */
        @JvmStatic
        fun isDifferentSides(
            first: BubbleBarLocation?,
            second: BubbleBarLocation?,
+3 −2
Original line number Diff line number Diff line
@@ -114,8 +114,9 @@ class DragToBubblesZoneChangeListener(
        fun hasBubbles(): Boolean

        /** Called when need to animate the bubble bar location. */
        fun animateBubbleBarLocation(bubbleBarLocation: BubbleBarLocation)
        fun animateBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) {}

        // TODO(b/411505605) remove all related code
        /** Called when the bubble bar pillow view is shown at position. */
        fun bubbleBarPillowShownAtLocation(bubbleBarLocation: BubbleBarLocation?) {}

@@ -125,7 +126,7 @@ class DragToBubblesZoneChangeListener(
         * @param bubbleBarLocation The [BubbleBarLocation] that the drag operation has entered.
         *                          This will be non-null if the drag has entered a valid bubble bar
         *                          location. It will be `null` if the drag operation has exited
         *                          all bubble bar locations.
         *                          all bubble bar locations. Values are guaranteed to be distinct.
         */
        fun onDragEnteredLocation(bubbleBarLocation: BubbleBarLocation?) {}
    }
Loading