From 741dfe06833980406b4589a7ed619f26e33218a1 Mon Sep 17 00:00:00 2001 From: mpodolian Date: Tue, 27 May 2025 18:57:53 -0700 Subject: [PATCH] Moved DragZoneChangeListener logic to the shared package. Extracted logic that could be reused in the shell and Launcher to DragToBubbleController Bug: 411505605 Test: DragToBubbleControllerTest Flag: com.android.wm.shell.enable_create_any_bubble Change-Id: Ie97367f9a53acd606c8a09665a5d14e4b6bebba7 --- .../taskbar/bubbles/DragToBubbleController.kt | 87 +++++-------------- 1 file changed, 22 insertions(+), 65 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt index 2263ecfb53..c1c82584cf 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt @@ -28,7 +28,9 @@ import com.android.launcher3.model.data.WorkspaceItemInfo import com.android.launcher3.taskbar.bubbles.BubbleBarLocationDropTarget.BubbleBarDropTargetController import com.android.quickstep.SystemUiProxy import com.android.wm.shell.shared.bubbles.BubbleBarLocation +import com.android.wm.shell.shared.bubbles.ContextUtils.isRtl import com.android.wm.shell.shared.bubbles.DeviceConfig +import com.android.wm.shell.shared.bubbles.DragToBubblesZoneChangeListener import com.android.wm.shell.shared.bubbles.DragZone import com.android.wm.shell.shared.bubbles.DragZoneFactory import com.android.wm.shell.shared.bubbles.DragZoneFactory.BubbleBarPropertiesProvider @@ -41,10 +43,8 @@ import com.android.wm.shell.shared.bubbles.DropTargetManager import com.android.wm.shell.shared.bubbles.DropTargetManager.DragZoneChangedListener import com.google.common.annotations.VisibleForTesting -class DragToBubbleController( - private val context: Context, - private val bubbleBarContainer: FrameLayout, -) : DragController.DragListener { +class DragToBubbleController(private val context: Context, bubbleBarContainer: FrameLayout) : + DragController.DragListener { @VisibleForTesting val dropTargetManager: DropTargetManager @@ -53,8 +53,6 @@ class DragToBubbleController( @VisibleForTesting lateinit var dragZoneFactory: DragZoneFactory private lateinit var systemUiProxy: SystemUiProxy private lateinit var bubbleBarViewController: BubbleBarViewController - private val isRtl: Boolean - get() = bubbleBarContainer.isLayoutRtl init { dropTargetManager = createDropTargetManager(bubbleBarContainer) @@ -108,79 +106,38 @@ class DragToBubbleController( private fun createDropTargetManager(bubbleBarContainer: FrameLayout): DropTargetManager { val listener: DragZoneChangedListener = - object : DragZoneChangedListener { + DragToBubblesZoneChangeListener( + context.isRtl, + object : DragToBubblesZoneChangeListener.Callback { - private var lastUpdateLocation: BubbleBarLocation? = null - private val isLocationChangedFromOriginal: Boolean - get() = - lastUpdateLocation != null && - isDifferentSides( - lastUpdateLocation, - bubbleBarViewController.bubbleBarLocation, - ) - - override fun onInitialDragZoneSet(dragZone: DragZone?) {} - - override fun onDragZoneChanged( - draggedObject: DraggedObject, - from: DragZone?, - to: DragZone?, - ) { - if (!bubbleBarViewController.hasBubbles()) { - return + override fun onDragEnteredLocation(bubbleBarLocation: BubbleBarLocation?) { + bubbleBarViewController.isShowingDropTarget = bubbleBarLocation != null } - bubbleBarViewController.isShowingDropTarget = true - val updateLocation = getBarLocation(to) - updateBubbleBarLocation(updateLocation) - lastUpdateLocation = updateLocation - } - override fun onDragEnded(zone: DragZone?) { - if (isLocationChangedFromOriginal) { - bubbleBarViewController.animateBubbleBarLocation( - bubbleBarViewController.bubbleBarLocation - ) + override fun getStartingBubbleBarLocation(): BubbleBarLocation { + return bubbleBarViewController.bubbleBarLocation + ?: BubbleBarLocation.DEFAULT } - bubbleBarViewController.isShowingDropTarget = false - } - fun updateBubbleBarLocation(updateLocation: BubbleBarLocation?) { - val updatedBefore = lastUpdateLocation != null - val originalLocation = bubbleBarViewController.bubbleBarLocation - if (updateLocation == null && isLocationChangedFromOriginal) { - bubbleBarViewController.animateBubbleBarLocation(originalLocation) - return - } - if (updatedBefore && isDifferentSides(lastUpdateLocation, updateLocation)) { - // updated before and location changed - update to new location - bubbleBarViewController.animateBubbleBarLocation(updateLocation) - return - } - if (!updatedBefore && isDifferentSides(originalLocation, updateLocation)) { - // not updated before and location changed from original - bubbleBarViewController.animateBubbleBarLocation(updateLocation) - } - } + override fun hasBubbles(): Boolean = bubbleBarViewController.hasBubbles() - fun getBarLocation(dragZone: DragZone?): BubbleBarLocation? { - return when (dragZone) { - is DragZone.Bubble.Left -> BubbleBarLocation.LEFT - is DragZone.Bubble.Right -> BubbleBarLocation.RIGHT - else -> null + override fun animateBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) { + bubbleBarViewController.animateBubbleBarLocation(bubbleBarLocation) } - } - fun isDifferentSides(f: BubbleBarLocation?, s: BubbleBarLocation?): Boolean { - return f != null && s != null && f.isOnLeft(isRtl) != s.isOnLeft(isRtl) - } - } + override fun bubbleBarPillowShownAtLocation( + bubbleBarLocation: BubbleBarLocation? + ) { + // TODO(b/411506181) adjust taskbar + } + }, + ) return DropTargetManager(context, bubbleBarContainer, listener) } private fun createDragZoneFactory( bubbleBarPropertiesProvider: BubbleBarPropertiesProvider ): DragZoneFactory { - // TODO(b/411506181) remove IPC call to display drop target in shell val splitScreenModeChecker = SplitScreenModeChecker { SplitScreenMode.NONE } val desktopWindowModeChecker = DesktopWindowModeChecker { false } val windowManager: WindowManager = context.getSystemService(WindowManager::class.java)!!