diff --git a/go/quickstep/src/com/android/launcher3/Launcher3QuickStepGo.java b/go/quickstep/src/com/android/launcher3/Launcher3QuickStepGo.java index 8bd0fec2de..bb406a2dd9 100644 --- a/go/quickstep/src/com/android/launcher3/Launcher3QuickStepGo.java +++ b/go/quickstep/src/com/android/launcher3/Launcher3QuickStepGo.java @@ -28,8 +28,8 @@ public class Launcher3QuickStepGo extends QuickstepLauncher { private static final String TAG = "Launcher3QuickStepGo"; @Override - public Stream getSupportedShortcuts() { - Stream shortcuts = super.getSupportedShortcuts(); + public Stream getSupportedShortcuts(int container) { + Stream shortcuts = super.getSupportedShortcuts(container); if (AppSharing.ENABLE_APP_SHARING) { shortcuts = Stream.concat(shortcuts, Stream.of(AppSharing.SHORTCUT_FACTORY)); diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 636f16754a..13322b025d 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -31,6 +31,7 @@ import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.PENDING_ import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE; import static com.android.launcher3.LauncherSettings.Animation.DEFAULT_NO_ICON; import static com.android.launcher3.LauncherSettings.Animation.VIEW_BACKGROUND; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; @@ -51,6 +52,7 @@ import static com.android.launcher3.popup.SystemShortcut.BUBBLE_SHORTCUT; import static com.android.launcher3.popup.SystemShortcut.DONT_SUGGEST_APP; import static com.android.launcher3.popup.SystemShortcut.INSTALL; import static com.android.launcher3.popup.SystemShortcut.PRIVATE_PROFILE_INSTALL; +import static com.android.launcher3.popup.SystemShortcut.REMOVE; import static com.android.launcher3.popup.SystemShortcut.UNINSTALL_APP; import static com.android.launcher3.popup.SystemShortcut.WIDGETS; import static com.android.launcher3.taskbar.LauncherTaskbarUIController.ALL_APPS_PAGE_PROGRESS_INDEX; @@ -494,7 +496,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, } @Override - public Stream getSupportedShortcuts() { + public Stream getSupportedShortcuts(int container) { // Order matters as it affects order of appearance in popup container List shortcuts = new ArrayList(Arrays.asList( APP_INFO, WellbeingModel.SHORTCUT_FACTORY, mHotseatPredictionController)); @@ -502,6 +504,10 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, shortcuts.addAll(getSplitShortcuts()); shortcuts.add(WIDGETS); shortcuts.add(INSTALL); + if (Flags.enableLongPressRemoveShortcut() + && (container == CONTAINER_HOTSEAT || container == CONTAINER_DESKTOP)) { + shortcuts.add(REMOVE); + } shortcuts.add(DONT_SUGGEST_APP); if (Flags.enablePrivateSpaceInstallShortcut()) { shortcuts.add(PRIVATE_PROFILE_INSTALL); diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 798d8b4046..7bd3479f27 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -139,7 +139,7 @@ public class DeleteDropTarget extends ButtonDropTarget { public void completeDrop(DragObject d) { ItemInfo item = d.dragInfo; if (canRemove(item)) { - mDropTargetHandler.onDeleteComplete(item); + mDropTargetHandler.onDeleteComplete(item, /* view */ null); } else if (mText == getResources().getText(R.string.remove_drop_target_label)) { Log.wtf("b/379606516", "If the drop target text is 'remove', then" + " users should always be able to delete the item from launcher's db." diff --git a/src/com/android/launcher3/DropTargetHandler.kt b/src/com/android/launcher3/DropTargetHandler.kt index 3c162a2f85..a5c11352a5 100644 --- a/src/com/android/launcher3/DropTargetHandler.kt +++ b/src/com/android/launcher3/DropTargetHandler.kt @@ -64,8 +64,8 @@ class DropTargetHandler(launcher: Launcher) { mLauncher.modelWriter.prepareToUndoDelete() } - fun onDeleteComplete(item: ItemInfo) { - removeItemAndStripEmptyScreens(null /* view */, item) + fun onDeleteComplete(item: ItemInfo, view: View?) { + removeItemAndStripEmptyScreens(view, item) AbstractFloatingView.closeOpenViews( mLauncher, false, diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index c0e746d9e9..f4fc6f9bc1 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -29,6 +29,7 @@ import static com.android.launcher3.AbstractFloatingView.getTopOpenViewWithType; import static com.android.launcher3.Flags.allAppsBlur; import static com.android.launcher3.Flags.enableAddAppWidgetViaConfigActivityV2; import static com.android.launcher3.Flags.enableWorkspaceInflation; +import static com.android.launcher3.Flags.enableLongPressRemoveShortcut; import static com.android.launcher3.LauncherAnimUtils.HOTSEAT_SCALE_PROPERTY_FACTORY; import static com.android.launcher3.LauncherAnimUtils.SCALE_INDEX_WIDGET_TRANSITION; import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY; @@ -56,6 +57,7 @@ import static com.android.launcher3.LauncherConstants.TraceEvents.ON_START_EVT; import static com.android.launcher3.LauncherConstants.TraceEvents.SINGLE_TRACE_COOKIE; import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.EDIT_MODE; @@ -90,6 +92,7 @@ import static com.android.launcher3.model.ItemInstallQueue.FLAG_ACTIVITY_PAUSED; import static com.android.launcher3.model.ItemInstallQueue.FLAG_DRAG_AND_DROP; import static com.android.launcher3.popup.SystemShortcut.APP_INFO; import static com.android.launcher3.popup.SystemShortcut.INSTALL; +import static com.android.launcher3.popup.SystemShortcut.REMOVE; import static com.android.launcher3.popup.SystemShortcut.WIDGETS; import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK; import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; @@ -2860,7 +2863,17 @@ public class Launcher extends StatefulActivity return new RectF(x - halfSize, y - halfSize, x + halfSize, y + halfSize); } - public Stream getSupportedShortcuts() { + /** + * Gets the system shortcuts that are supported by launcher in a given container. + * + * @param container is the container of the item as derived from ItemInfo. + * @return a stream of supported system shortcuts. + */ + public Stream getSupportedShortcuts(int container) { + if (enableLongPressRemoveShortcut() + && (container == CONTAINER_DESKTOP || container == CONTAINER_HOTSEAT)) { + return Stream.of(APP_INFO, WIDGETS, INSTALL, REMOVE); + } return Stream.of(APP_INFO, WIDGETS, INSTALL); } diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 8a277c36dc..29969342eb 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -103,6 +103,7 @@ public class PopupContainerWithArrow protected PopupItemDragHandler mPopupItemDragHandler; protected LauncherAccessibilityDelegate mAccessibilityDelegate; + private float mCurrentHeight; public PopupContainerWithArrow(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); @@ -207,7 +208,7 @@ public class PopupContainerWithArrow PopupContainerWithArrow container; PopupDataProvider popupDataProvider = launcher.getPopupDataProvider(); int deepShortcutCount = popupDataProvider.getShortcutCountForItem(item); - List systemShortcuts = launcher.getSupportedShortcuts() + List systemShortcuts = launcher.getSupportedShortcuts(item.container) .map(s -> s.getShortcut(launcher, item, icon)) .filter(Objects::nonNull) .collect(Collectors.toList()); @@ -306,7 +307,51 @@ public class PopupContainerWithArrow return; } - float currentHeight = mShortcutHeight + mChildContainerMargin; + mCurrentHeight = mShortcutHeight + mChildContainerMargin; + + if (Flags.enableLongPressRemoveShortcut()) { + collapseEligibleSystemShortcutsIfOverThreshold(systemShortcuts); + } else { + collapseNonWidgetSystemShortcutsIfOverThreshold(systemShortcuts); + } + addDeepShortcuts(deepShortcutCount, mCurrentHeight); + } + + /** + * If the total amount of shortcuts is over threshold, we collapse the shortcuts that are + * eligible to be collapsible, and make sure the non-collapsible ones get their own container. + * + * @param systemShortcuts List of SystemShortcuts + */ + private void collapseEligibleSystemShortcutsIfOverThreshold( + List systemShortcuts) { + List collapsibleSystemShortcuts = + getCollapsibleSystemShortcuts(systemShortcuts); + // If total shortcuts over threshold, collapse system shortcuts to single row + addSystemShortcutsIconsOnly(collapsibleSystemShortcuts); + // May need to recalculate row width + mContainerWidth = Math.max(mContainerWidth, + collapsibleSystemShortcuts.size() * getResources() + .getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size)); + List nonCollapsibleSystemShortcuts = systemShortcuts.stream() + .filter(shortcut -> !shortcut.mIsCollapsible).toList(); + if (!nonCollapsibleSystemShortcuts.isEmpty()) { + addSystemShortcuts(nonCollapsibleSystemShortcuts, + R.layout.system_shortcut_rows_container, + R.layout.system_shortcut); + mCurrentHeight += (mShortcutHeight * nonCollapsibleSystemShortcuts.size()) + + mChildContainerMargin; + } + } + + /** + * If the total amount of shortcuts is over threshold, we collapse the shortcuts that are + * not the widget shortcut, and make sure widget gets its own container. + * + * @param systemShortcuts List of SystemShortcuts + */ + private void collapseNonWidgetSystemShortcutsIfOverThreshold( + List systemShortcuts) { List nonWidgetSystemShortcuts = getNonWidgetSystemShortcuts(systemShortcuts); // If total shortcuts over threshold, collapse system shortcuts to single row @@ -321,9 +366,8 @@ public class PopupContainerWithArrow mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container_material_u, this); initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get()); - currentHeight += mShortcutHeight + mChildContainerMargin; + mCurrentHeight += mShortcutHeight + mChildContainerMargin; } - addDeepShortcuts(deepShortcutCount, currentHeight); } /** @@ -341,9 +385,23 @@ public class PopupContainerWithArrow } /** - * Returns list of [systemShortcuts] without the Widgets shortcut instance if found - * @param systemShortcuts list of SystemShortcuts to filter from - * @return systemShortcuts without the Widgets Shortcut + * Returns list of [systemShortcuts] without the non-collapsible shortcuts. + * @param systemShortcuts list of SystemShortcuts to filter from. + * @return systemShortcuts without the Widgets Shortcut. + */ + private static List getCollapsibleSystemShortcuts( + List systemShortcuts) { + + return systemShortcuts + .stream() + .filter(shortcut -> shortcut.mIsCollapsible) + .collect(Collectors.toList()); + } + + /** + * Returns list of [systemShortcuts] without the non-collapsible shortcuts. + * @param systemShortcuts list of SystemShortcuts to filter from. + * @return systemShortcuts without the Widgets Shortcut. */ private static List getNonWidgetSystemShortcuts( List systemShortcuts) { diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index 0b68315a8f..9fefb9484a 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -26,6 +26,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingViewHelper; +import com.android.launcher3.DropTargetHandler; import com.android.launcher3.Flags; import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; @@ -67,17 +68,31 @@ public abstract class SystemShortcut extends ItemInfo protected final T mTarget; protected final ItemInfo mItemInfo; protected final View mOriginalView; + protected final boolean mIsCollapsible; private final AbstractFloatingViewHelper mAbstractFloatingViewHelper; public SystemShortcut(int iconResId, int labelResId, T target, ItemInfo itemInfo, View originalView) { this(iconResId, labelResId, target, itemInfo, originalView, - new AbstractFloatingViewHelper()); + new AbstractFloatingViewHelper(), /* isCollapsible */ true); + } + + public SystemShortcut(int iconResId, int labelResId, T target, ItemInfo itemInfo, + View originalView, boolean isCollapsible) { + this(iconResId, labelResId, target, itemInfo, originalView, + new AbstractFloatingViewHelper(), isCollapsible); } public SystemShortcut(int iconResId, int labelResId, T target, ItemInfo itemInfo, View originalView, AbstractFloatingViewHelper abstractFloatingViewHelper) { + this(iconResId, labelResId, target, itemInfo, originalView, abstractFloatingViewHelper, + /* isCollapsible */ true); + } + + public SystemShortcut(int iconResId, int labelResId, T target, ItemInfo itemInfo, + View originalView, AbstractFloatingViewHelper abstractFloatingViewHelper, + boolean isCollapsible) { mIconResId = iconResId; mLabelResId = labelResId; mAccessibilityActionId = labelResId; @@ -85,6 +100,7 @@ public abstract class SystemShortcut extends ItemInfo mItemInfo = itemInfo; mOriginalView = originalView; mAbstractFloatingViewHelper = abstractFloatingViewHelper; + mIsCollapsible = isCollapsible; } public void setIconAndLabelFor(View iconView, TextView labelView) { @@ -127,7 +143,8 @@ public abstract class SystemShortcut extends ItemInfo public static class Widgets extends SystemShortcut { public Widgets(T target, ItemInfo itemInfo, @NonNull View originalView) { - super(getDrawableId(), R.string.widget_button_text, target, itemInfo, originalView); + super(getDrawableId(), R.string.widget_button_text, target, itemInfo, originalView, + false); } /** @@ -231,6 +248,25 @@ public abstract class SystemShortcut extends ItemInfo } } + public static final Factory REMOVE = RemoveApp::new; + + public static class RemoveApp extends SystemShortcut { + + public RemoveApp(T target, ItemInfo itemInfo, @NonNull View originalView) { + super(R.drawable.ic_remove_no_shadow, R.string.remove_drop_target_label, target, + itemInfo, originalView, false); + } + + @Override + public void onClick(View view) { + AbstractFloatingView.closeAllOpenViews(mTarget); + DropTargetHandler dropTargetHandler = + ActivityContext.lookupContext(view.getContext()).getDropTargetHandler(); + dropTargetHandler.prepareToUndoDelete(); + dropTargetHandler.onDeleteComplete(mItemInfo, mOriginalView); + } + } + public static final Factory PRIVATE_PROFILE_INSTALL = (context, itemInfo, originalView) -> { if (originalView == null) {