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

Commit d47f6d69 authored by mpodolian's avatar mpodolian
Browse files

Added LauncherIcon DraggedObject

As part of the migration to the DropTargetManager framework, the missing
LauncherIcon drag object was added. Additionally, the DragZoneFactory
was updated to provide drag zones for the LauncherIcon. The Bubble.Left
and Bubble.Right drag zones were updated to have secondary drop targets
set to the bubble bar location if the bubble bar has no bubbles. Tests
for the DragZoneFactory were added to verify new logic.

Bug: 403363673
Flag: com.android.wm.shell.enable_create_any_bubble
Test: DragZoneFactoryTest, DropTargetManagerTest
Change-Id: I6d3e496f99b696028a6003291429c0c2867d6de7
parent afa16744
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ class DragZoneFactoryScreenshotTest(private val param: Param) {
                is DraggedObject.Bubble -> "bubble"
                is DraggedObject.BubbleBar -> "bubbleBar"
                is DraggedObject.ExpandedView -> "expandedView"
                is DraggedObject.LauncherIcon -> "launcherIcon"
            }

        private val splitScreenModeName =
+14 −5
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ sealed interface DragZone {
    /** The bounds of the drop target associated with this drag zone. */
    val dropTarget: DropTargetRect?

    /** The bounds of the second drop target associated with this drag zone. */
    val secondDropTarget: DropTargetRect?

    fun contains(x: Int, y: Int) = bounds.contains(x, y)

    sealed interface Bounds {
@@ -54,39 +57,45 @@ sealed interface DragZone {
    /** Represents the bubble drag area on the screen. */
    sealed class Bubble(
        override val bounds: Bounds.RectZone,
        override val dropTarget: DropTargetRect
        override val dropTarget: DropTargetRect,
    ) : DragZone {
        data class Left(
            override val bounds: Bounds.RectZone,
            override val dropTarget: DropTargetRect
            override val dropTarget: DropTargetRect,
            override val secondDropTarget: DropTargetRect? = null,
        ) : Bubble(bounds, dropTarget)

        data class Right(
            override val bounds: Bounds.RectZone,
            override val dropTarget: DropTargetRect
            override val dropTarget: DropTargetRect,
            override val secondDropTarget: DropTargetRect? = null,
        ) : Bubble(bounds, dropTarget)
    }

    /** Represents dragging to Desktop Window. */
    data class DesktopWindow(
        override val bounds: Bounds.RectZone,
        override val dropTarget: DropTargetRect
        override val dropTarget: DropTargetRect,
        override val secondDropTarget: DropTargetRect? = null,
    ) : DragZone

    /** Represents dragging to Full Screen. */
    data class FullScreen(
        override val bounds: Bounds.RectZone,
        override val dropTarget: DropTargetRect
        override val dropTarget: DropTargetRect,
        override val secondDropTarget: DropTargetRect? = null,
    ) : DragZone

    /** Represents dragging to dismiss. */
    data class Dismiss(override val bounds: Bounds.CircleZone) : DragZone {
        override val dropTarget: DropTargetRect? = null
        override val secondDropTarget: DropTargetRect? = null
    }

    /** Represents dragging to enter Split or replace a Split app. */
    sealed class Split(override val bounds: Bounds.RectZone) : DragZone {
        override val dropTarget: DropTargetRect? = null
        override val secondDropTarget: DropTargetRect? = null

        data class Left(override val bounds: Bounds.RectZone) : Split(bounds)

+7 −1
Original line number Diff line number Diff line
@@ -237,6 +237,10 @@ class DragZoneFactory(
                }
                dragZones.addAll(createBubbleHalfScreenDragZones(forBubbleBar = false))
            }
            is DraggedObject.LauncherIcon -> {
                val showSecondDropTarget = !draggedObject.bubbleBarHasBubbles
                dragZones.addAll(createBubbleCornerDragZones(showSecondDropTarget))
            }
        }
        return dragZones
    }
@@ -252,7 +256,7 @@ class DragZoneFactory(
        )
    }

    private fun createBubbleCornerDragZones(): List<DragZone> {
    private fun createBubbleCornerDragZones(showSecondDropTarget: Boolean = false): List<DragZone> {
        val dragZoneSize =
            if (deviceConfig.isSmallTablet) {
                bubbleDragZoneFoldableSize
@@ -271,6 +275,7 @@ class DragZoneFactory(
                        ),
                    ),
                dropTarget = expandedViewDropTargetLeft,
                secondDropTarget = if (showSecondDropTarget) bubbleBarDropTargetLeft else null
            ),
            DragZone.Bubble.Right(
                bounds =
@@ -283,6 +288,7 @@ class DragZoneFactory(
                        ),
                    ),
                dropTarget = expandedViewDropTargetRight,
                secondDropTarget = if (showSecondDropTarget) bubbleBarDropTargetRight else null
            )
        )
    }
+7 −5
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.wm.shell.shared.bubbles

/** A Bubble object being dragged. */
sealed interface DraggedObject {
    /** The initial location of the object at the start of the drag gesture. */
    val initialLocation: BubbleBarLocation

    data class Bubble(override val initialLocation: BubbleBarLocation) : DraggedObject
    data class BubbleBar(override val initialLocation: BubbleBarLocation) : DraggedObject
    data class ExpandedView(override val initialLocation: BubbleBarLocation) : DraggedObject
    data class Bubble(val initialLocation: BubbleBarLocation) : DraggedObject

    data class BubbleBar(val initialLocation: BubbleBarLocation) : DraggedObject

    data class ExpandedView(val initialLocation: BubbleBarLocation) : DraggedObject

    data class LauncherIcon(val bubbleBarHasBubbles: Boolean) : DraggedObject
}
+23 −10
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ import androidx.core.animation.Animator
import androidx.core.animation.AnimatorListenerAdapter
import androidx.core.animation.ValueAnimator
import com.android.wm.shell.shared.bubbles.DragZone.DropTargetRect
import com.android.wm.shell.shared.bubbles.DraggedObject.Bubble
import com.android.wm.shell.shared.bubbles.DraggedObject.BubbleBar
import com.android.wm.shell.shared.bubbles.DraggedObject.ExpandedView
import com.android.wm.shell.shared.bubbles.DraggedObject.LauncherIcon

/**
 * Manages animating drop targets in response to dragging bubble icons or bubble expanded views
@@ -148,29 +152,38 @@ class DropTargetManager(
        private val dragZones: List<DragZone>,
        val draggedObject: DraggedObject
    ) {
        val initialDragZone =
            if (draggedObject.initialLocation.isOnLeft(isLayoutRtl)) {
        val initialDragZone = draggedObject.initialLocation?.let {
                if (it.isOnLeft(isLayoutRtl)) {
                    dragZones.filterIsInstance<DragZone.Bubble.Left>().first()
                } else {
                    dragZones.filterIsInstance<DragZone.Bubble.Right>().first()
                }
        var currentDragZone: DragZone = initialDragZone
            }
        var currentDragZone: DragZone? = initialDragZone

        fun getMatchingDragZone(x: Int, y: Int): DragZone {
        fun getMatchingDragZone(x: Int, y: Int): DragZone? {
            return dragZones.firstOrNull { it.contains(x, y) } ?: currentDragZone
        }
    }

    private val DraggedObject.initialLocation: BubbleBarLocation?
        get() = when (this) {
            is Bubble -> initialLocation
            is BubbleBar -> initialLocation
            is ExpandedView -> initialLocation
            is LauncherIcon -> null
        }

    /** An interface to be notified when drag zones change. */
    interface DragZoneChangedListener {
        /** An initial drag zone was set. Called when a drag starts. */
        fun onInitialDragZoneSet(dragZone: DragZone)
        fun onInitialDragZoneSet(dragZone: DragZone?)

        /** Called when the object was dragged to a different drag zone. */
        fun onDragZoneChanged(draggedObject: DraggedObject, from: DragZone, to: DragZone)
        fun onDragZoneChanged(draggedObject: DraggedObject, from: DragZone?, to: DragZone?)

        /** Called when the drag has ended with the zone it ended in. */
        fun onDragEnded(zone: DragZone)
        fun onDragEnded(zone: DragZone?)
    }

    private fun Animator.doOnEnd(onEnd: () -> Unit) {
Loading