diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index b3a9f8db7c..3315f8cad2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -51,6 +51,8 @@ import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.popup.PopupContainerWithArrow; +import com.android.launcher3.shortcuts.DeepShortcutView; +import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.systemui.shared.recents.model.Task; import com.android.systemui.shared.system.ClipDescriptionCompat; import com.android.systemui.shared.system.LauncherAppsCompat; @@ -88,6 +90,21 @@ public class TaskbarDragController extends DragController { - startInternalDrag(btv); + DragView dragView = startInternalDrag(btv, dragPreviewProvider); + if (iconShift != null) { + dragView.animateShift(-iconShift.x, -iconShift.y); + } btv.getIcon().setIsDisabled(true); mControllers.taskbarAutohideSuspendController.updateFlag( TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING, true); @@ -104,7 +124,8 @@ public class TaskbarDragController extends DragController(mContext, container)); + new PopupLiveUpdateHandler(mContext, container) { + @Override + protected void showPopupContainerForIcon(BubbleTextView originalIcon) { + showForIcon(originalIcon); + } + }); // TODO (b/198438631): configure for taskbar/context + container.setPopupItemDragHandler(new TaskbarPopupItemDragHandler()); container.populateAndShow(icon, mPopupDataProvider.getShortcutCountForItem(item), @@ -145,4 +156,43 @@ public class TaskbarPopupController { container.requestFocus(); return container; } + + private class TaskbarPopupItemDragHandler implements + PopupContainerWithArrow.PopupItemDragHandler { + + protected final Point mIconLastTouchPos = new Point(); + + TaskbarPopupItemDragHandler() {} + + @Override + public boolean onTouch(View view, MotionEvent ev) { + // Touched a shortcut, update where it was touched so we can drag from there on + // long click. + switch (ev.getAction()) { + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_MOVE: + mIconLastTouchPos.set((int) ev.getX(), (int) ev.getY()); + break; + } + return false; + } + + @Override + public boolean onLongClick(View v) { + // Return early if not the correct view + if (!(v.getParent() instanceof DeepShortcutView)) return false; + + DeepShortcutView sv = (DeepShortcutView) v.getParent(); + sv.setWillDrawIcon(false); + + // Move the icon to align with the center-top of the touch point + Point iconShift = new Point(); + iconShift.x = mIconLastTouchPos.x - sv.getIconCenter().x; + iconShift.y = mIconLastTouchPos.y - mContext.getDeviceProfile().iconSizePx; + + mControllers.taskbarDragController.startDragOnLongClick(sv, iconShift); + + return false; + } + } } diff --git a/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java b/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java index 731f439d6c..3e3f633567 100644 --- a/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java +++ b/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java @@ -18,6 +18,7 @@ package com.android.launcher3.popup; import android.view.View; import android.view.ViewGroup; +import com.android.launcher3.BubbleTextView; import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.model.data.ItemInfo; @@ -86,4 +87,9 @@ public class LauncherPopupLiveUpdateHandler extends PopupLiveUpdateHandler }; } + public void setPopupItemDragHandler(PopupItemDragHandler popupItemDragHandler) { + mPopupItemDragHandler = popupItemDragHandler; + } + public PopupItemDragHandler getItemDragHandler() { return mPopupItemDragHandler; } diff --git a/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java b/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java index 194c22faf0..c5d545225c 100644 --- a/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java +++ b/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java @@ -20,6 +20,7 @@ import static android.view.View.GONE; import android.content.Context; import android.view.View; +import com.android.launcher3.BubbleTextView; import com.android.launcher3.dot.DotInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.notification.NotificationContainer; @@ -36,7 +37,7 @@ import java.util.function.Predicate; * * @param The activity on which the popup shows */ -public class PopupLiveUpdateHandler implements +public abstract class PopupLiveUpdateHandler implements PopupDataProvider.PopupDataChangeListener, View.OnAttachStateChangeListener { protected final T mContext; @@ -103,6 +104,8 @@ public class PopupLiveUpdateHandler impleme @Override public void onSystemShortcutsUpdated() { mPopupContainerWithArrow.close(true); - PopupContainerWithArrow.showForIcon(mPopupContainerWithArrow.getOriginalIcon()); + showPopupContainerForIcon(mPopupContainerWithArrow.getOriginalIcon()); } + + protected abstract void showPopupContainerForIcon(BubbleTextView originalIcon); } diff --git a/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java b/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java index cecbb0db13..c166bfc83a 100644 --- a/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java +++ b/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java @@ -23,12 +23,12 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.view.View; -import com.android.launcher3.Launcher; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.icons.BitmapRenderer; import com.android.launcher3.icons.FastBitmapDrawable; +import com.android.launcher3.views.ActivityContext; /** * Extension of {@link DragPreviewProvider} which generates bitmaps scaled to the default icon size. @@ -45,7 +45,8 @@ public class ShortcutDragPreviewProvider extends DragPreviewProvider { @Override public Drawable createDrawable() { if (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) { - int size = Launcher.getLauncher(mView.getContext()).getDeviceProfile().iconSizePx; + int size = ActivityContext.lookupContext(mView.getContext()) + .getDeviceProfile().iconSizePx; return new FastBitmapDrawable( BitmapRenderer.createHardwareBitmap( size + blurSizeOutline, @@ -59,7 +60,7 @@ public class ShortcutDragPreviewProvider extends DragPreviewProvider { private Bitmap createDragBitmapLegacy() { Drawable d = mView.getBackground(); Rect bounds = getDrawableBounds(d); - int size = Launcher.getLauncher(mView.getContext()).getDeviceProfile().iconSizePx; + int size = ActivityContext.lookupContext(mView.getContext()).getDeviceProfile().iconSizePx; final Bitmap b = Bitmap.createBitmap( size + blurSizeOutline, size + blurSizeOutline, @@ -84,9 +85,9 @@ public class ShortcutDragPreviewProvider extends DragPreviewProvider { @Override public float getScaleAndPosition(Drawable preview, int[] outPos) { - Launcher launcher = Launcher.getLauncher(mView.getContext()); + ActivityContext context = ActivityContext.lookupContext(mView.getContext()); int iconSize = getDrawableBounds(mView.getBackground()).width(); - float scale = launcher.getDragLayer().getLocationInDragLayer(mView, outPos); + float scale = context.getDragLayer().getLocationInDragLayer(mView, outPos); int iconLeft = mView.getPaddingStart(); if (Utilities.isRtl(mView.getResources())) { @@ -98,7 +99,7 @@ public class ShortcutDragPreviewProvider extends DragPreviewProvider { + mPositionShift.x); outPos[1] += Math.round((scale * mView.getHeight() - preview.getIntrinsicHeight()) / 2 + mPositionShift.y); - float size = launcher.getDeviceProfile().iconSizePx; + float size = context.getDeviceProfile().iconSizePx; return scale * iconSize / size; } }