Merge "Moved DragZoneChangeListener logic to the shared package." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
53c3354ffa
@@ -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)!!
|
||||
|
||||
Reference in New Issue
Block a user