diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index ae70876b18..eac264736e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -131,8 +131,8 @@ public class TaskbarDragController extends DragController im public void init(TaskbarControllers controllers) { mControllers = controllers; - mControllers.bubbleControllers.ifPresent( - c -> c.dragToBubbleController.addBubbleBarDropTargets(this)); + mControllers.runAfterInit(() -> mControllers.bubbleControllers.ifPresent( + c -> c.dragToBubbleController.addBubbleBarDropTargets(this))); } /** Called when the controller is destroyed. */ diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarLocationDropTarget.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarLocationDropTarget.kt index 24e7d99187..5f80fd56fd 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarLocationDropTarget.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarLocationDropTarget.kt @@ -21,72 +21,57 @@ import android.view.View import com.android.launcher3.DropTarget import com.android.launcher3.dragndrop.DragOptions import com.android.launcher3.model.data.ItemInfo -import com.android.wm.shell.shared.bubbles.BubbleBarLocation +import com.android.wm.shell.shared.bubbles.DragZoneFactory +import com.android.wm.shell.shared.bubbles.DropTargetManager /** * Implementation of the {@link DropTarget} that handles drag and drop events over the bubble bar * locations. */ class BubbleBarLocationDropTarget( - private val bubbleBarLocation: BubbleBarLocation, - private val bubbleBarDragListener: BubbleBarDragListener, + private val bubbleBarDropTargetController: BubbleBarDropTargetController, + dragZoneFactory: DragZoneFactory, + private val dropTargetManager: DropTargetManager, + private val isLeftDropTarget: Boolean, ) : DropTarget { - /** Controller that takes care of the bubble bar drag events inside launcher process. */ - interface BubbleBarDragListener { + interface BubbleBarDropTargetController { - /** Called when the drag event is over the bubble bar drop zone. */ - fun onLauncherItemDraggedOverBubbleBarDragZone(location: BubbleBarLocation) + /** Return whether the item info can be dropped on the bubble bar drop target. */ + fun acceptDrop(itemInfo: ItemInfo): Boolean - /** Called when the drag event leaves the bubble bar drop zone. */ - fun onLauncherItemDraggedOutsideBubbleBarDropZone() - - /** Called when the drop event happens over the bubble bar drop zone. */ - fun onLauncherItemDroppedOverBubbleBarDragZone( - location: BubbleBarLocation, - itemInfo: ItemInfo, - ) - - /** Gets the hit [rect][android.graphics.Rect] of the bubble bar location. */ - fun getBubbleBarLocationHitRect(bubbleBarLocation: BubbleBarLocation, outRect: Rect) - - /** Provides the view that will accept the drop. */ - fun getDropView(): View + /** Called after dragged item info drop on the bubble bar drop target. */ + fun onDrop(itemInfo: ItemInfo, isLeftDropTarget: Boolean) } - private var isShowingDropTarget = false + private val dropRect = dragZoneFactory.getBubbleBarDropRect(isLeftDropTarget) override fun isDropEnabled(): Boolean = true override fun onDrop(dragObject: DropTarget.DragObject, options: DragOptions) { - val itemInfo = dragObject.dragInfo ?: return - bubbleBarDragListener.onLauncherItemDroppedOverBubbleBarDragZone( - bubbleBarLocation, - itemInfo, - ) + bubbleBarDropTargetController.onDrop(dragObject.dragInfo, isLeftDropTarget) } - override fun onDragEnter(dragObject: DropTarget.DragObject) {} + override fun onDragEnter(dragObject: DropTarget.DragObject) { + dropTargetManager.onDragUpdated(dragObject.x, dragObject.y) + } override fun onDragOver(dragObject: DropTarget.DragObject) { - if (isShowingDropTarget) return - isShowingDropTarget = true - bubbleBarDragListener.onLauncherItemDraggedOverBubbleBarDragZone(bubbleBarLocation) + dropTargetManager.onDragUpdated(dragObject.x, dragObject.y) } override fun onDragExit(dragObject: DropTarget.DragObject) { - if (!isShowingDropTarget) return - isShowingDropTarget = false - bubbleBarDragListener.onLauncherItemDraggedOutsideBubbleBarDropZone() + dropTargetManager.onDragUpdated(dragObject.x, dragObject.y) } - override fun acceptDrop(dragObject: DropTarget.DragObject): Boolean = true + override fun acceptDrop(dragObject: DropTarget.DragObject): Boolean = + bubbleBarDropTargetController.acceptDrop(dragObject.dragInfo) override fun prepareAccessibilityDrop() {} override fun getHitRectRelativeToDragLayer(outRect: Rect) { - bubbleBarDragListener.getBubbleBarLocationHitRect(bubbleBarLocation, outRect) + outRect.set(dropRect) } - override fun getDropView(): View = bubbleBarDragListener.getDropView() + override fun getDropView(): View? = null } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index bf4c605534..a4630a23f0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -24,8 +24,6 @@ import static com.android.launcher3.taskbar.TaskbarPinningController.PINNING_TRA import android.animation.Animator; import android.animation.AnimatorSet; -import android.content.Intent; -import android.content.pm.ShortcutInfo; import android.content.res.Resources; import android.graphics.Point; import android.graphics.PointF; @@ -41,20 +39,15 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.app.animation.Interpolators; -import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; import com.android.launcher3.anim.AnimatedFloat; import com.android.launcher3.anim.RoundedRectRevealOutlineProvider; -import com.android.launcher3.dragndrop.DragController; -import com.android.launcher3.model.data.ItemInfo; -import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.taskbar.TaskbarActivityContext; import com.android.launcher3.taskbar.TaskbarControllers; import com.android.launcher3.taskbar.TaskbarInsetsController; import com.android.launcher3.taskbar.TaskbarSharedState; import com.android.launcher3.taskbar.TaskbarStashController; -import com.android.launcher3.taskbar.bubbles.BubbleBarLocationDropTarget.BubbleBarDragListener; import com.android.launcher3.taskbar.bubbles.animation.BubbleBarViewAnimator; import com.android.launcher3.taskbar.bubbles.flyout.BubbleBarFlyoutController; import com.android.launcher3.taskbar.bubbles.flyout.BubbleBarFlyoutPositioner; @@ -65,7 +58,6 @@ import com.android.launcher3.util.MultiValueAlpha; import com.android.quickstep.SystemUiProxy; import com.android.wm.shell.Flags; import com.android.wm.shell.shared.bubbles.BubbleBarLocation; -import com.android.wm.shell.shared.bubbles.DeviceConfig; import java.io.PrintWriter; import java.util.List; @@ -124,60 +116,6 @@ public class BubbleBarViewController { updateTranslationY(); setBubbleBarScaleAndPadding(pinningProgress); }); - private final BubbleBarDragListener mDragListener = new BubbleBarDragListener() { - - @Override - public void getBubbleBarLocationHitRect(@NonNull BubbleBarLocation bubbleBarLocation, - Rect outRect) { - Point screenSize = mActivity.getScreenSize(); - outRect.top = screenSize.y - mBubbleBarDropTargetSize; - outRect.bottom = screenSize.y; - if (bubbleBarLocation.isOnLeft(mBarView.isLayoutRtl())) { - outRect.left = 0; - outRect.right = mBubbleBarDropTargetSize; - } else { - outRect.left = screenSize.x - mBubbleBarDropTargetSize; - outRect.right = screenSize.x; - } - } - - @Override - public void onLauncherItemDroppedOverBubbleBarDragZone(@NonNull BubbleBarLocation location, - @NonNull ItemInfo itemInfo) { - AbstractFloatingView.closeAllOpenViews(mActivity); - if (itemInfo instanceof WorkspaceItemInfo) { - ShortcutInfo shortcutInfo = ((WorkspaceItemInfo) itemInfo).getDeepShortcutInfo(); - if (shortcutInfo != null) { - mSystemUiProxy.showShortcutBubble(shortcutInfo, location); - return; - } - } - Intent itemIntent = itemInfo.getIntent(); - if (itemIntent != null && itemIntent.getComponent() != null) { - itemIntent.setPackage(itemIntent.getComponent().getPackageName()); - mSystemUiProxy.showAppBubble(itemIntent, itemInfo.user, location); - } - } - - @Override - public void onLauncherItemDraggedOutsideBubbleBarDropZone() { - onItemDraggedOutsideBubbleBarDropZone(); - mSystemUiProxy.showBubbleDropTarget(/* show = */ false); - } - - @Override - public void onLauncherItemDraggedOverBubbleBarDragZone( - @NonNull BubbleBarLocation location) { - onDragItemOverBubbleBarDragZone(location); - mSystemUiProxy.showBubbleDropTarget(/* show = */ true, location); - } - - @NonNull - @Override - public View getDropView() { - return mBarView; - } - }; // Modified when swipe up is happening on the bubble bar or task bar. private float mBubbleBarSwipeUpTranslationY; @@ -203,11 +141,8 @@ public class BubbleBarViewController { private BubbleBarFlyoutController mBubbleBarFlyoutController; private BubbleBarPinController mBubbleBarPinController; private TaskbarSharedState mTaskbarSharedState; - private final BubbleBarLocationDropTarget mBubbleBarLeftDropTarget; - private final BubbleBarLocationDropTarget mBubbleBarRightDropTarget; private final TimeSource mTimeSource = System::currentTimeMillis; private final int mTaskbarTranslationDelta; - private final int mBubbleBarDropTargetSize; @Nullable private BubbleBarBoundsChangeListener mBoundsChangeListener; @@ -225,15 +160,6 @@ public class BubbleBarViewController { R.dimen.bubblebar_transient_taskbar_min_distance); mDragElevation = res.getDimensionPixelSize(R.dimen.dragged_bubble_elevation); mTaskbarTranslationDelta = getBubbleBarTranslationDeltaForTaskbar(activity); - if (DeviceConfig.isSmallTablet(mActivity)) { - mBubbleBarDropTargetSize = res.getDimensionPixelSize(R.dimen.drag_zone_bubble_fold); - } else { - mBubbleBarDropTargetSize = res.getDimensionPixelSize(R.dimen.drag_zone_bubble_tablet); - } - mBubbleBarLeftDropTarget = new BubbleBarLocationDropTarget(BubbleBarLocation.LEFT, - mDragListener); - mBubbleBarRightDropTarget = new BubbleBarLocationDropTarget(BubbleBarLocation.RIGHT, - mDragListener); } /** Initializes controller. */ @@ -350,18 +276,6 @@ public class BubbleBarViewController { }; } - /** Adds bubble bar locations drop zones to the drag controller. */ - public void addBubbleBarDropTargets(DragController dragController) { - dragController.addDropTarget(mBubbleBarLeftDropTarget); - dragController.addDropTarget(mBubbleBarRightDropTarget); - } - - /** Removes bubble bar locations drop zones to the drag controller. */ - public void removeBubbleBarDropTargets(DragController dragController) { - dragController.removeDropTarget(mBubbleBarLeftDropTarget); - dragController.removeDropTarget(mBubbleBarRightDropTarget); - } - /** Returns animated float property responsible for pinning transition animation. */ public AnimatedFloat getBubbleBarPinning() { return mBubbleBarPinning; @@ -641,6 +555,11 @@ public class BubbleBarViewController { return mBarView.isShowingDropTarget(); } + /** Tells bubble bar view if it should show the drop target. */ + public void setShowingDropTarget(boolean showingDropTarget) { + mBarView.showDropTarget(showingDropTarget); + } + /** * Notifies the controller that a drag event is over the Bubble Bar drop zone. The controller * will display the appropriate drop target and enter drop target mode. The controller will also diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java index ef5c7d7df7..0a68478fc0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java @@ -28,6 +28,7 @@ import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController; import com.android.launcher3.util.MultiPropertyFactory; import com.android.launcher3.util.RunnableList; import com.android.quickstep.SystemUiProxy; +import com.android.wm.shell.shared.bubbles.DragZoneFactory; import java.io.PrintWriter; import java.util.Optional; @@ -122,7 +123,23 @@ public class BubbleControllers { bubbleBarPinController.init(this, bubbleBarLocationListeners); bubblePinController.init(this); bubbleBarSwipeController.ifPresent(c -> c.init(this)); - dragToBubbleController.init(bubbleBarViewController, bubbleStashController, + dragToBubbleController.init(bubbleBarViewController, + new DragZoneFactory.BubbleBarPropertiesProvider() { + @Override + public int getHeight() { + return (int) bubbleBarViewController.getBubbleBarCollapsedHeight(); + } + + @Override + public int getWidth() { + return (int) bubbleBarViewController.getBubbleBarCollapsedWidth(); + } + + @Override + public int getBottomPadding() { + return -(int) bubbleStashController.getBubbleBarTranslationY(); + } + }, SystemUiProxy.INSTANCE.get(taskbarControllers.taskbarActivityContext)); mPostInitRunnables.executeAllAndDestroy(); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt index d6acb89c0b..5d7579406e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt @@ -16,30 +16,76 @@ package com.android.launcher3.taskbar.bubbles +import android.content.Context +import android.content.Intent +import android.view.WindowManager import android.widget.FrameLayout import com.android.launcher3.DropTarget.DragObject import com.android.launcher3.dragndrop.DragController import com.android.launcher3.dragndrop.DragOptions -import com.android.launcher3.taskbar.TaskbarActivityContext -import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController +import com.android.launcher3.model.data.ItemInfo +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.DeviceConfig +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 +import com.android.wm.shell.shared.bubbles.DragZoneFactory.DesktopWindowModeChecker +import com.android.wm.shell.shared.bubbles.DragZoneFactory.SplitScreenModeChecker +import com.android.wm.shell.shared.bubbles.DragZoneFactory.SplitScreenModeChecker.SplitScreenMode +import com.android.wm.shell.shared.bubbles.DraggedObject +import com.android.wm.shell.shared.bubbles.DraggedObject.LauncherIcon +import com.android.wm.shell.shared.bubbles.DropTargetManager +import com.android.wm.shell.shared.bubbles.DropTargetManager.DragZoneChangedListener +// TODO(b/411506181) add tests class DragToBubbleController( - private val activity: TaskbarActivityContext, + private val context: Context, private val bubbleBarContainer: FrameLayout, ) : DragController.DragListener { + private val dropTargetManager: DropTargetManager + + private lateinit var bubbleBarLeftDropTarget: BubbleBarLocationDropTarget + private lateinit var bubbleBarRightDropTarget: BubbleBarLocationDropTarget + private 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) + } + fun init( bubbleBarViewController: BubbleBarViewController, - bubbleStashController: BubbleStashController, + bubbleBarPropertiesProvider: BubbleBarPropertiesProvider, systemUiProxy: SystemUiProxy, - ) {} + ) { + this.bubbleBarViewController = bubbleBarViewController + this.systemUiProxy = systemUiProxy + val dropController: BubbleBarDropTargetController = createDropController() + dragZoneFactory = createDragZoneFactory(bubbleBarPropertiesProvider) + bubbleBarLeftDropTarget = createDropTarget(dropController, isLeftDropTarget = true) + bubbleBarRightDropTarget = createDropTarget(dropController, isLeftDropTarget = false) + } /** Adds bubble bar locations drop zones to the drag controller. */ - fun addBubbleBarDropTargets(dragController: DragController<*>) {} + fun addBubbleBarDropTargets(dragController: DragController<*>) { + dragController.addDragListener(this) + dragController.addDropTarget(bubbleBarLeftDropTarget) + dragController.addDropTarget(bubbleBarRightDropTarget) + } /** Removes bubble bar locations drop zones to the drag controller. */ - fun removeBubbleBarDropTargets(dragController: DragController<*>) {} + fun removeBubbleBarDropTargets(dragController: DragController<*>) { + dragController.removeDragListener(this) + dragController.removeDropTarget(bubbleBarLeftDropTarget) + dragController.removeDropTarget(bubbleBarRightDropTarget) + } /** * Runs the provided action once all drop target views are removed from the container. If there @@ -47,10 +93,145 @@ class DragToBubbleController( * immediately. */ fun runAfterDropTargetsHidden(afterHiddenAction: Runnable) { - afterHiddenAction.run() + dropTargetManager.onDropTargetRemoved(afterHiddenAction) } - override fun onDragStart(dragObject: DragObject, options: DragOptions) {} + override fun onDragStart(dragObject: DragObject, options: DragOptions) { + val launcherIcon: DraggedObject = LauncherIcon(bubbleBarViewController.hasBubbles()) {} + val dragZones: List = dragZoneFactory.createSortedDragZones(launcherIcon) + dropTargetManager.onDragStarted(launcherIcon, dragZones) + } - override fun onDragEnd() {} + override fun onDragEnd() { + dropTargetManager.onDragEnded() + } + + private fun createDropTargetManager(bubbleBarContainer: FrameLayout): DropTargetManager { + val listener: DragZoneChangedListener = + object : DragZoneChangedListener { + + 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 + } + bubbleBarViewController.isShowingDropTarget = true + val updateLocation = getBarLocation(to) + updateBubbleBarLocation(updateLocation) + lastUpdateLocation = updateLocation + } + + override fun onDragEnded(zone: DragZone?) { + if (isLocationChangedFromOriginal) { + bubbleBarViewController.animateBubbleBarLocation( + bubbleBarViewController.bubbleBarLocation + ) + } + 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) + } + } + + fun getBarLocation(dragZone: DragZone?): BubbleBarLocation? { + return when (dragZone) { + is DragZone.Bubble.Left -> BubbleBarLocation.LEFT + is DragZone.Bubble.Right -> BubbleBarLocation.RIGHT + else -> null + } + } + + fun isDifferentSides(f: BubbleBarLocation?, s: BubbleBarLocation?): Boolean { + return f != null && s != null && f.isOnLeft(isRtl) != s.isOnLeft(isRtl) + } + } + 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)!! + val deviceConfig: DeviceConfig = DeviceConfig.create(context, windowManager) + return DragZoneFactory( + context, + deviceConfig, + splitScreenModeChecker, + desktopWindowModeChecker, + bubbleBarPropertiesProvider, + ) + } + + private fun createDropController(): BubbleBarDropTargetController { + return object : BubbleBarDropTargetController { + override fun onDrop(itemInfo: ItemInfo, isLeftDropTarget: Boolean) { + val location = + if (isLeftDropTarget) { + BubbleBarLocation.LEFT + } else { + BubbleBarLocation.RIGHT + } + if (hasShortcutInfo(itemInfo)) { + val si = (itemInfo as WorkspaceItemInfo).deepShortcutInfo + systemUiProxy.showShortcutBubble(si, location) + return + } + val itemIntent: Intent = itemInfo.intent ?: return + val packageName = itemIntent.component?.packageName ?: return + itemIntent.setPackage(packageName) + systemUiProxy.showAppBubble(itemIntent, itemInfo.user, location) + } + + override fun acceptDrop(itemInfo: ItemInfo): Boolean { + return hasShortcutInfo(itemInfo) || itemInfo.intent?.component != null + } + + fun hasShortcutInfo(itemInfo: ItemInfo): Boolean { + return itemInfo is WorkspaceItemInfo && itemInfo.deepShortcutInfo != null + } + } + } + + private fun createDropTarget( + dropController: BubbleBarDropTargetController, + isLeftDropTarget: Boolean, + ) = + BubbleBarLocationDropTarget( + dropController, + dragZoneFactory, + dropTargetManager, + isLeftDropTarget, + ) }