diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index f743a4212a..26479c1543 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -136,6 +136,7 @@ import com.android.launcher3.taskbar.bubbles.BubbleDismissController; import com.android.launcher3.taskbar.bubbles.BubbleDragController; import com.android.launcher3.taskbar.bubbles.BubblePinController; import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController; +import com.android.launcher3.taskbar.bubbles.DragToBubbleController; import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController; import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.TaskbarHotseatDimensionsProvider; import com.android.launcher3.taskbar.bubbles.stashing.DeviceProfileDimensionsProviderAdapter; @@ -342,6 +343,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { new BubbleBarPinController(this, bubbleBarContainer, this::getScreenSize), new BubblePinController(this, bubbleBarContainer, this::getScreenSize), bubbleBarSwipeController, + new DragToBubbleController(this, bubbleBarContainer), new BubbleCreator(this) )); } @@ -1289,7 +1291,10 @@ public class TaskbarActivityContext extends BaseTaskbarContext { && !AbstractFloatingView.hasOpenView( this, TYPE_ALL & ~TYPE_TASKBAR_OVERLAY_PROXY)) { // Reverts Taskbar window to its original size - setTaskbarWindowFullscreen(false); + Runnable resetTaskbarFullscreen = () -> setTaskbarWindowFullscreen(false); + mControllers.bubbleControllers.ifPresentOrElse( + bc -> bc.dragToBubbleController.runAfterDropTargetsHidden( + resetTaskbarFullscreen), resetTaskbarFullscreen); } setAutohideSuspendFlag(FLAG_AUTOHIDE_SUSPEND_DRAGGING, isDragInProgress); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index 5a58a84565..eac264736e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -131,14 +131,14 @@ public class TaskbarDragController extends DragController im public void init(TaskbarControllers controllers) { mControllers = controllers; - mControllers.bubbleControllers.ifPresent( - c -> c.bubbleBarViewController.addBubbleBarDropTargets(this)); + mControllers.runAfterInit(() -> mControllers.bubbleControllers.ifPresent( + c -> c.dragToBubbleController.addBubbleBarDropTargets(this))); } /** Called when the controller is destroyed. */ public void onDestroy() { mControllers.bubbleControllers.ifPresent( - c -> c.bubbleBarViewController.removeBubbleBarDropTargets(this)); + c -> c.dragToBubbleController.removeBubbleBarDropTargets(this)); } public void setDisallowGlobalDrag(boolean disallowGlobalDrag) { 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 e014326b24..91eec3db52 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 68917ff236..0a68478fc0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java @@ -27,6 +27,8 @@ import com.android.launcher3.taskbar.bubbles.stashing.BubbleBarLocationOnDemandL 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; @@ -44,6 +46,7 @@ public class BubbleControllers { public final BubblePinController bubblePinController; public final Optional bubbleBarSwipeController; public final BubbleCreator bubbleCreator; + public final DragToBubbleController dragToBubbleController; private final RunnableList mPostInitRunnables = new RunnableList(); @@ -62,6 +65,7 @@ public class BubbleControllers { BubbleBarPinController bubbleBarPinController, BubblePinController bubblePinController, Optional bubbleBarSwipeController, + DragToBubbleController dragToBubbleController, BubbleCreator bubbleCreator) { this.bubbleBarController = bubbleBarController; this.bubbleBarViewController = bubbleBarViewController; @@ -73,6 +77,7 @@ public class BubbleControllers { this.bubblePinController = bubblePinController; this.bubbleBarSwipeController = bubbleBarSwipeController; this.bubbleCreator = bubbleCreator; + this.dragToBubbleController = dragToBubbleController; } /** @@ -118,7 +123,24 @@ public class BubbleControllers { bubbleBarPinController.init(this, bubbleBarLocationListeners); bubblePinController.init(this); bubbleBarSwipeController.ifPresent(c -> c.init(this)); + 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 new file mode 100644 index 0000000000..2263ecfb53 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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.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 +import com.google.common.annotations.VisibleForTesting + +class DragToBubbleController( + private val context: Context, + private val bubbleBarContainer: FrameLayout, +) : DragController.DragListener { + + @VisibleForTesting val dropTargetManager: DropTargetManager + + @VisibleForTesting lateinit var bubbleBarLeftDropTarget: BubbleBarLocationDropTarget + @VisibleForTesting lateinit var bubbleBarRightDropTarget: BubbleBarLocationDropTarget + @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) + } + + fun init( + bubbleBarViewController: BubbleBarViewController, + 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<*>) { + dragController.addDragListener(this) + dragController.addDropTarget(bubbleBarLeftDropTarget) + dragController.addDropTarget(bubbleBarRightDropTarget) + } + + /** Removes bubble bar locations drop zones to the drag controller. */ + 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 + * are no drop target views currently present or being animated, the action will be executed + * immediately. + */ + fun runAfterDropTargetsHidden(afterHiddenAction: Runnable) { + dropTargetManager.onDropTargetRemoved(afterHiddenAction) + } + + 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() { + 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, + ) +} diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.kt b/quickstep/src/com/android/quickstep/SystemUiProxy.kt index 4fb8065c21..9493eaba5a 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.kt +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.kt @@ -704,13 +704,6 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context: fun showExpandedView() = executeWithErrorLog({ "Failed call showExpandedView" }) { bubbles?.showExpandedView() } - /** Tells SysUI to show the bubble drop target. */ - @JvmOverloads - fun showBubbleDropTarget(show: Boolean, bubbleBarLocation: BubbleBarLocation? = null) = - executeWithErrorLog({ "Failed call showDropTarget" }) { - bubbles?.showDropTarget(show, bubbleBarLocation) - } - /** Tells SysUI to move the dragged bubble to full screen. */ fun moveDraggedBubbleToFullscreen(key: String, dropLocation: Point) { executeWithErrorLog({ "Failed to call moveDraggedBubbleToFullscreen" }) { diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarInputConsumerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarInputConsumerTest.kt index c8f50f70d5..d5a8baf368 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarInputConsumerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarInputConsumerTest.kt @@ -50,6 +50,7 @@ class BubbleBarInputConsumerTest { @Mock private lateinit var bubbleBarPinController: BubbleBarPinController @Mock private lateinit var bubblePinController: BubblePinController @Mock private lateinit var bubbleBarSwipeController: BubbleBarSwipeController + @Mock private lateinit var dragToBubbleController: DragToBubbleController @Mock private lateinit var bubbleCreator: BubbleCreator @Mock private lateinit var motionEvent: MotionEvent @@ -69,6 +70,7 @@ class BubbleBarInputConsumerTest { bubbleBarPinController, bubblePinController, Optional.of(bubbleBarSwipeController), + dragToBubbleController, bubbleCreator, ) } diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarSwipeControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarSwipeControllerTest.kt index 024ec4c060..5865dcdb2f 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarSwipeControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarSwipeControllerTest.kt @@ -69,6 +69,7 @@ class BubbleBarSwipeControllerTest { @Mock private lateinit var bubbleDismissController: BubbleDismissController @Mock private lateinit var bubbleBarPinController: BubbleBarPinController @Mock private lateinit var bubblePinController: BubblePinController + @Mock private lateinit var dragToBubbleController: DragToBubbleController @Mock private lateinit var bubbleCreator: BubbleCreator @Before @@ -94,6 +95,7 @@ class BubbleBarSwipeControllerTest { bubbleBarPinController, bubblePinController, Optional.of(bubbleBarSwipeController), + dragToBubbleController, bubbleCreator, ) diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt new file mode 100644 index 0000000000..f8534fbe84 --- /dev/null +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.taskbar.bubbles + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.graphics.Insets +import android.graphics.Rect +import android.widget.FrameLayout +import androidx.core.animation.AnimatorTestRule +import androidx.test.core.app.ApplicationProvider.getApplicationContext +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import androidx.test.platform.app.InstrumentationRegistry +import com.android.launcher3.DropTarget +import com.android.launcher3.DropTarget.DragObject +import com.android.launcher3.dragndrop.DragOptions +import com.android.launcher3.model.data.AppInfo +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.DragZoneFactory +import com.android.wm.shell.shared.bubbles.DragZoneFactory.BubbleBarPropertiesProvider +import com.android.wm.shell.shared.bubbles.DragZoneFactory.SplitScreenModeChecker.SplitScreenMode +import com.android.wm.shell.shared.bubbles.DropTargetView +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.kotlin.any +import org.mockito.kotlin.doReturn +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.stub +import org.mockito.kotlin.verify + +/** Unit tests for [DragToBubbleControllerTest]. */ +@SmallTest +@RunWith(AndroidJUnit4::class) +class DragToBubbleControllerTest { + + @get:Rule val animatorTestRule = AnimatorTestRule() + + private val context = getApplicationContext() + private val container = FrameLayout(context) + private val bubbleBarViewController: BubbleBarViewController = mock() + private val systemUiProxy: SystemUiProxy = mock() + private val bubbleBarPropertiesProvider = FakeBubbleBarPropertiesProvider() + private val testDragZonesFactory = createTestDragZoneFactory() + private val dragObject = DragObject(context) + private lateinit var dragToBubbleController: DragToBubbleController + + private val dropTargetView: DropTargetView + get() = dragToBubbleController.dropTargetManager.dropTargetView + + private val secondDropTargetView: DropTargetView? + get() = dragToBubbleController.dropTargetManager.secondDropTargetView + + private val bubbleBarLeftDropTarget: DropTarget + get() = dragToBubbleController.bubbleBarLeftDropTarget + + private val bubbleBarRightDropTarget: DropTarget + get() = dragToBubbleController.bubbleBarRightDropTarget + + private val leftDropTargetRect: Rect + get() = testDragZonesFactory.getBubbleBarDropRect(isLeftSide = true) + + private val rightDropTargetRect: Rect + get() = testDragZonesFactory.getBubbleBarDropRect(isLeftSide = false) + + @Before + fun setUp() { + dragToBubbleController = DragToBubbleController(context, container) + dragToBubbleController.init( + bubbleBarViewController, + bubbleBarPropertiesProvider, + systemUiProxy, + ) + dragToBubbleController.dragZoneFactory = testDragZonesFactory + } + + @Test + fun dragStarted_noBubbleBar_dropZonesAdded() { + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT_NO_BUBBLE_BAR) + assertThat(dropTargetView.parent).isEqualTo(container) + assertThat(secondDropTargetView!!.parent).isEqualTo(container) + assertThat(dropTargetView.alpha).isEqualTo(0f) + assertThat(secondDropTargetView!!.alpha).isEqualTo(0f) + } + + @Test + fun dragStarted_hasBubbleBar_dropZonesAdded() { + prepareBubbleBarViewController(hasBubbles = true) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT) + assertThat(dropTargetView.parent).isEqualTo(container) + assertThat(dropTargetView.alpha).isEqualTo(0f) + assertThat(secondDropTargetView).isNull() + } + + @Test + fun dragEnded_allViewsRemoved() { + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragToBubbleController.onDragEnd() + animatorTestRule.advanceTimeBy(250) + } + + assertThat(container.childCount).isEqualTo(0) + } + + @Test + fun draggedToTheRightDropZone_noBubbles_dropTargetViewsShown() { + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(rightDropTargetRect) + bubbleBarRightDropTarget.onDragEnter(dragObject) + animatorTestRule.advanceTimeBy(250) + } + + assertThat(dropTargetView.alpha).isEqualTo(1f) + assertThat(secondDropTargetView!!.alpha).isEqualTo(1f) + verify(bubbleBarViewController, never()).animateBubbleBarLocation(any()) + } + + @Test + fun draggedToTheRightDropZone_hasBubblesOnTheRight_dropTargetViewShown() { + prepareBubbleBarViewController(hasBubbles = true) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(rightDropTargetRect) + bubbleBarRightDropTarget.onDragEnter(dragObject) + animatorTestRule.advanceTimeBy(250) + } + + assertThat(dropTargetView.alpha).isEqualTo(1f) + assertThat(secondDropTargetView).isNull() + } + + @Test + fun draggedToTheRightDropZone_hasBubblesOnTheRight_bubbleBarLocationChangeNotRequested() { + prepareBubbleBarViewController(hasBubbles = true) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(rightDropTargetRect) + bubbleBarRightDropTarget.onDragEnter(dragObject) + animatorTestRule.advanceTimeBy(250) + } + verify(bubbleBarViewController, never()).animateBubbleBarLocation(any()) + } + + @Test + fun draggedToTheLeftDropZone_hasBubblesOnTheRight_bubbleBarLocationChangeRequested() { + prepareBubbleBarViewController( + hasBubbles = true, + bubbleBarLocation = BubbleBarLocation.RIGHT, + ) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(leftDropTargetRect) + bubbleBarLeftDropTarget.onDragEnter(dragObject) + } + verify(bubbleBarViewController).animateBubbleBarLocation(BubbleBarLocation.LEFT) + } + + @Test + fun draggedToTheLeftDropZone_dragEnded_hasBubblesOnTheRight_locationRestored() { + val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT + prepareBubbleBarViewController( + hasBubbles = true, + bubbleBarLocation = bubbleBarOriginalLocation, + ) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(leftDropTargetRect) + bubbleBarLeftDropTarget.onDragEnter(dragObject) + dragObject.updateXY(x = 0, y = 0) + bubbleBarLeftDropTarget.onDragExit(dragObject) + dragToBubbleController.onDragEnd() + } + + verify(bubbleBarViewController).animateBubbleBarLocation(BubbleBarLocation.LEFT) + verify(bubbleBarViewController).animateBubbleBarLocation(bubbleBarOriginalLocation) + assertThat(container.childCount).isEqualTo(DROP_VIEWS_COUNT) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + animatorTestRule.advanceTimeBy(250) + } + assertThat(container.childCount).isEqualTo(0) + } + + @Test + fun droppedAtTheLeftDropZone_noBubblesOnTheRight_appBubbleCreationRequested() { + val bubbleBarOriginalLocation = BubbleBarLocation.RIGHT + prepareBubbleBarViewController( + hasBubbles = false, + bubbleBarLocation = bubbleBarOriginalLocation, + ) + val packageName = "test.package" + val itemIntent = + Intent().apply { + component = ComponentName(packageName, "TestClass") + `package` = packageName + } + val appInfo = AppInfo().apply { intent = itemIntent } + dragObject.dragInfo = appInfo + + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(leftDropTargetRect) + bubbleBarLeftDropTarget.onDragEnter(dragObject) + bubbleBarLeftDropTarget.onDragExit(dragObject) + bubbleBarLeftDropTarget.onDrop(dragObject, DragOptions()) + } + + verify(systemUiProxy).showAppBubble(itemIntent, appInfo.user, BubbleBarLocation.LEFT) + } + + private fun prepareBubbleBarViewController( + hasBubbles: Boolean = false, + bubbleBarLocation: BubbleBarLocation = BubbleBarLocation.RIGHT, + ) { + bubbleBarViewController.stub { + on { hasBubbles() } doReturn hasBubbles + on { getBubbleBarLocation() } doReturn bubbleBarLocation + } + } + + private fun DragObject.updateXYToCenterOf(rect: Rect) { + updateXY(rect.centerX(), rect.centerY()) + } + + private fun DragObject.updateXY(x: Int, y: Int) { + this.x = x + this.y = y + } + + private fun createTestDragZoneFactory(): DragZoneFactory { + val deviceConfig = + DeviceConfig( + isLargeScreen = true, + isSmallTablet = false, + isLandscape = true, + isRtl = false, + windowBounds = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), + insets = Insets.NONE, + ) + return DragZoneFactory( + context, + deviceConfig, + { SplitScreenMode.NONE }, + { false }, + bubbleBarPropertiesProvider, + ) + } + + private class FakeBubbleBarPropertiesProvider : BubbleBarPropertiesProvider { + + override fun getHeight(): Int = BUBBLE_BAR_HEIGHT + + override fun getWidth(): Int = BUBBLE_BAR_WIDTH + + override fun getBottomPadding(): Int = BUBBLE_BAR_BOTTOM_PADDING + } + + companion object { + const val BUBBLE_BAR_WIDTH = 100 + const val BUBBLE_BAR_HEIGHT = 110 + const val BUBBLE_BAR_BOTTOM_PADDING = 70 + const val SCREEN_WIDTH = 2000 + const val SCREEN_HEIGHT = 1000 + const val DROP_VIEWS_COUNT = 1 + const val DROP_VIEWS_COUNT_NO_BUBBLE_BAR = 2 + } +} diff --git a/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java b/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java index 617658fd3d..bc34471acf 100644 --- a/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java +++ b/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java @@ -55,6 +55,7 @@ import com.android.launcher3.taskbar.bubbles.BubbleDismissController; import com.android.launcher3.taskbar.bubbles.BubbleDragController; import com.android.launcher3.taskbar.bubbles.BubblePinController; import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController; +import com.android.launcher3.taskbar.bubbles.DragToBubbleController; import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController; import com.android.launcher3.util.LockedUserState; import com.android.launcher3.util.SandboxApplication; @@ -602,6 +603,7 @@ public class InputConsumerUtilsTest { BubbleBarPinController bubbleBarPinController = mock(BubbleBarPinController.class); BubblePinController bubblePinController = mock(BubblePinController.class); BubbleBarSwipeController bubbleBarSwipeController = mock(BubbleBarSwipeController.class); + DragToBubbleController dragToBubbleController = mock(DragToBubbleController.class); BubbleCreator bubbleCreator = mock(BubbleCreator.class); BubbleControllers bubbleControllers = new BubbleControllers( bubbleBarController, @@ -613,6 +615,7 @@ public class InputConsumerUtilsTest { bubbleBarPinController, bubblePinController, Optional.of(bubbleBarSwipeController), + dragToBubbleController, bubbleCreator); when(bubbleBarViewController.hasBubbles()).thenReturn(true); diff --git a/src/com/android/launcher3/DropTarget.java b/src/com/android/launcher3/DropTarget.java index 3b22d5caaf..e9e600728e 100644 --- a/src/com/android/launcher3/DropTarget.java +++ b/src/com/android/launcher3/DropTarget.java @@ -20,6 +20,8 @@ import android.content.Context; import android.graphics.Rect; import android.view.View; +import androidx.annotation.Nullable; + import com.android.launcher3.accessibility.DragViewStateAnnouncer; import com.android.launcher3.dagger.LauncherComponentProvider; import com.android.launcher3.dragndrop.DragOptions; @@ -147,8 +149,18 @@ public interface DropTarget { // These methods are implemented in Views void getHitRectRelativeToDragLayer(Rect outRect); - /** Returns the drop target view. By default, the implementor class is cast to the view. */ - default View getDropView() { + /** + * Returns the drop target view.
+ * + * By default, the implementor class is cast to the view.
+ * + * The returned {@link View} will be use to map touch coordinates to the view self descendant + * and set as [{@link DragObject#x DragObject.x} {@link DragObject#y DragObject.y}].
+ * + * If this method returns {@code null}, the raw touch event coordinates will be directly + * assigned to [{@link DragObject#x DragObject.x} and {@link DragObject#y DragObject.y}]. + */ + default @Nullable View getDropView() { return (View) this; } } diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index 415a2c6230..fa3048a997 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -553,7 +553,6 @@ public abstract class DragController private DropTarget findDropTarget(final int x, final int y) { mCoordinatesTemp[0] = x; mCoordinatesTemp[1] = y; - final Rect r = mRectTemp; final ArrayList dropTargets = mDropTargets; final int count = dropTargets.size(); @@ -564,8 +563,11 @@ public abstract class DragController target.getHitRectRelativeToDragLayer(r); if (r.contains(x, y)) { - mActivity.getDragLayer().mapCoordInSelfToDescendant(target.getDropView(), - mCoordinatesTemp); + View dropTargetView = target.getDropView(); + if (dropTargetView != null) { + mActivity.getDragLayer().mapCoordInSelfToDescendant(dropTargetView, + mCoordinatesTemp); + } mDragObject.x = mCoordinatesTemp[0]; mDragObject.y = mCoordinatesTemp[1]; return target;