From 16e04e29d2df1691b0ca27144dc8d6d4e98e69c6 Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Fri, 15 Oct 2021 14:43:54 -0700 Subject: [PATCH] Generalize the icon popup menu types. Generalized popup menu types and logic to allow wider uses outside of launcher. Bug: 198438631 Test: long pressed launcher icons and pressed menu options Change-Id: Iadcbb1796496c0061dcee362784e426ff55dc94a --- .../hybridhotseat/HotseatEduController.java | 3 ++- .../android/launcher3/model/WellbeingModel.java | 2 +- .../android/quickstep/TaskShortcutFactory.java | 4 ++-- .../android/launcher3/BaseDraggingActivity.java | 12 +++--------- src/com/android/launcher3/Utilities.java | 7 +++++++ src/com/android/launcher3/Workspace.java | 2 +- .../launcher3/popup/PopupContainerWithArrow.java | 13 +++++++------ .../android/launcher3/popup/PopupPopulator.java | 14 ++++++++------ .../android/launcher3/popup/SystemShortcut.java | 16 +++++++++------- .../android/launcher3/views/ActivityContext.java | 7 +++++++ 10 files changed, 47 insertions(+), 33 deletions(-) diff --git a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatEduController.java b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatEduController.java index 63e7390d34..680012ce28 100644 --- a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatEduController.java +++ b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatEduController.java @@ -30,6 +30,7 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.FolderInfo; @@ -298,7 +299,7 @@ public class HotseatEduController { Log.e(TAG, "Unable to find suitable view for ArrowTip"); return false; } - Rect bounds = mLauncher.getViewBounds(tipTargetView); + Rect bounds = Utilities.getViewBounds(tipTargetView); new ArrowTipView(mLauncher).show(message, Gravity.END, bounds.centerX(), bounds.top); return true; } diff --git a/quickstep/src/com/android/launcher3/model/WellbeingModel.java b/quickstep/src/com/android/launcher3/model/WellbeingModel.java index 154b78b1b9..e489cb3a71 100644 --- a/quickstep/src/com/android/launcher3/model/WellbeingModel.java +++ b/quickstep/src/com/android/launcher3/model/WellbeingModel.java @@ -377,7 +377,7 @@ public final class WellbeingModel extends BgObjectWithLooper { /** * Shortcut factory for generating wellbeing action */ - public static final SystemShortcut.Factory SHORTCUT_FACTORY = + public static final SystemShortcut.Factory SHORTCUT_FACTORY = (activity, info) -> (info.getTargetComponent() == null) ? null : INSTANCE.get(activity) .getShortcutForApp( info.getTargetComponent().getPackageName(), info.user.getIdentifier(), diff --git a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java index dcc7cccefc..8c4ba97c07 100644 --- a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java +++ b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java @@ -128,7 +128,7 @@ public interface TaskShortcutFactory { } } - class MultiWindowSystemShortcut extends SystemShortcut { + class MultiWindowSystemShortcut extends SystemShortcut { private Handler mHandler; @@ -305,7 +305,7 @@ public interface TaskShortcutFactory { return new PinSystemShortcut(activity, taskContainer); }; - class PinSystemShortcut extends SystemShortcut { + class PinSystemShortcut extends SystemShortcut { private static final String TAG = "PinSystemShortcut"; diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index 7954011e93..dd56ca3a23 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -41,7 +41,6 @@ import android.util.Log; import android.view.ActionMode; import android.view.Display; import android.view.View; -import android.view.View.OnClickListener; import android.view.WindowInsets.Type; import android.view.WindowMetrics; import android.widget.Toast; @@ -166,12 +165,6 @@ public abstract class BaseDraggingActivity extends BaseActivity // no-op } - public Rect getViewBounds(View v) { - int[] pos = new int[2]; - v.getLocationOnScreen(pos); - return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); - } - @NonNull public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) { int left = 0, top = 0; @@ -206,7 +199,7 @@ public abstract class BaseDraggingActivity extends BaseActivity // Prepare intent intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (v != null) { - intent.setSourceBounds(getViewBounds(v)); + intent.setSourceBounds(Utilities.getViewBounds(v)); } try { boolean isShortcut = (item instanceof WorkspaceItemInfo) @@ -316,7 +309,8 @@ public abstract class BaseDraggingActivity extends BaseActivity } } - public OnClickListener getItemOnClickListener() { + @Override + public View.OnClickListener getItemOnClickListener() { return ItemClickHandler.INSTANCE; } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 36faeee47a..7a38fe736a 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -69,6 +69,7 @@ import android.view.ViewConfiguration; import android.view.animation.Interpolator; import android.widget.LinearLayout; +import androidx.annotation.NonNull; import androidx.core.graphics.ColorUtils; import androidx.core.os.BuildCompat; @@ -846,6 +847,12 @@ public final class Utilities { view.setLayoutParams(lp); } + public static Rect getViewBounds(@NonNull View v) { + int[] pos = new int[2]; + v.getLocationOnScreen(pos); + return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); + } + private static class FixedSizeEmptyDrawable extends ColorDrawable { private final int mSize; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 8e76d82354..8095280f05 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1676,7 +1676,7 @@ public class Workspace extends PagedView } if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) { - PopupContainerWithArrow popupContainer = PopupContainerWithArrow + PopupContainerWithArrow popupContainer = PopupContainerWithArrow .showForIcon((BubbleTextView) child); if (popupContainer != null) { dragOptions.preDragCondition = popupContainer.createPreDragCondition(); diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index d6e927b28c..b96395052c 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -66,6 +66,7 @@ import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.launcher3.touch.ItemLongClickListener; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.ShortcutUtil; +import com.android.launcher3.views.ActivityContext; import com.android.launcher3.views.BaseDragLayer; import java.util.ArrayList; @@ -81,7 +82,7 @@ import java.util.stream.Collectors; * * @param The activity on with the popup shows */ -public class PopupContainerWithArrow +public class PopupContainerWithArrow extends ArrowPopup implements DragSource, DragController.DragListener { private final List mShortcuts = new ArrayList<>(); @@ -190,10 +191,10 @@ public class PopupContainerWithArrow } /** - * Shows the notifications and deep shortcuts associated with {@param icon}. + * Shows the notifications and deep shortcuts associated with a Launcher {@param icon}. * @return the container if shown or null. */ - public static PopupContainerWithArrow showForIcon(BubbleTextView icon) { + public static PopupContainerWithArrow showForIcon(BubbleTextView icon) { Launcher launcher = Launcher.getLauncher(icon.getContext()); if (getOpen(launcher) != null) { // There is already an items container open, so don't open this one. @@ -205,7 +206,7 @@ public class PopupContainerWithArrow return null; } - final PopupContainerWithArrow container = + final PopupContainerWithArrow container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( R.layout.popup_container, launcher.getDragLayer(), false); container.configureForLauncher(launcher); @@ -489,8 +490,8 @@ public class PopupContainerWithArrow /** * Returns a PopupContainerWithArrow which is already open or null */ - public static PopupContainerWithArrow getOpen(BaseDraggingActivity launcher) { - return getOpenView(launcher, TYPE_ACTION_POPUP); + public static PopupContainerWithArrow getOpen(T context) { + return getOpenView(context, TYPE_ACTION_POPUP); } /** diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java index 5ed6f2e37e..1dce1f25e8 100644 --- a/src/com/android/launcher3/popup/PopupPopulator.java +++ b/src/com/android/launcher3/popup/PopupPopulator.java @@ -19,6 +19,7 @@ package com.android.launcher3.popup; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS; import android.content.ComponentName; +import android.content.Context; import android.content.pm.ShortcutInfo; import android.os.Handler; import android.os.UserHandle; @@ -26,7 +27,6 @@ import android.os.UserHandle; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.LauncherAppState; import com.android.launcher3.icons.IconCache; import com.android.launcher3.model.data.ItemInfo; @@ -36,6 +36,7 @@ import com.android.launcher3.notification.NotificationKeyData; import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.ShortcutRequest; +import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; import java.util.Collections; @@ -128,7 +129,8 @@ public class PopupPopulator { /** * Returns a runnable to update the provided shortcuts and notifications */ - public static Runnable createUpdateRunnable(final BaseDraggingActivity launcher, + public static Runnable createUpdateRunnable( + final T context, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, final List shortcutViews, @@ -144,22 +146,22 @@ public class PopupPopulator { infos = Collections.emptyList(); } else { infos = notificationListener.getNotificationsForKeys(notificationKeys).stream() - .map(sbn -> new NotificationInfo(launcher, sbn, originalInfo)) + .map(sbn -> new NotificationInfo(context, sbn, originalInfo)) .collect(Collectors.toList()); } uiHandler.post(() -> container.applyNotificationInfos(infos)); } - List shortcuts = new ShortcutRequest(launcher, user) + List shortcuts = new ShortcutRequest(context, user) .withContainer(activity) .query(ShortcutRequest.PUBLISHED); String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId; shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe); - IconCache cache = LauncherAppState.getInstance(launcher).getIconCache(); + IconCache cache = LauncherAppState.getInstance(context).getIconCache(); for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) { final ShortcutInfo shortcut = shortcuts.get(i); - final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, launcher); + final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, context); cache.getUnbadgedShortcutIcon(si, shortcut); si.rank = i; si.container = CONTAINER_SHORTCUTS; diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index e5424cfe0a..826c79b289 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -18,12 +18,14 @@ import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.Launcher; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.InstantAppResolver; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.PackageUserKey; +import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.WidgetsBottomSheet; import java.util.List; @@ -35,7 +37,7 @@ import java.util.List; * Example system shortcuts, defined as inner classes, include Widgets and AppInfo. * @param */ -public abstract class SystemShortcut extends ItemInfo +public abstract class SystemShortcut extends ItemInfo implements View.OnClickListener { private final int mIconResId; @@ -100,7 +102,7 @@ public abstract class SystemShortcut extends Ite return mAccessibilityActionId == action; } - public interface Factory { + public interface Factory { @Nullable SystemShortcut getShortcut(T activity, ItemInfo itemInfo); } @@ -135,9 +137,9 @@ public abstract class SystemShortcut extends Ite public static final Factory APP_INFO = AppInfo::new; - public static class AppInfo extends SystemShortcut { + public static class AppInfo extends SystemShortcut { - public AppInfo(BaseDraggingActivity target, ItemInfo itemInfo) { + public AppInfo(T target, ItemInfo itemInfo) { super(R.drawable.ic_info_no_shadow, R.string.app_info_drop_target_label, target, itemInfo); } @@ -145,7 +147,7 @@ public abstract class SystemShortcut extends Ite @Override public void onClick(View view) { dismissTaskMenuView(mTarget); - Rect sourceBounds = mTarget.getViewBounds(view); + Rect sourceBounds = Utilities.getViewBounds(view); new PackageManagerHelper(mTarget).startDetailsActivityForInfo( mItemInfo, sourceBounds, ActivityOptions.makeBasic().toBundle()); mTarget.getStatsLogManager().logger().withItemInfo(mItemInfo) @@ -170,7 +172,7 @@ public abstract class SystemShortcut extends Ite return new Install(activity, itemInfo); }; - public static class Install extends SystemShortcut { + public static class Install extends SystemShortcut { public Install(BaseDraggingActivity target, ItemInfo itemInfo) { super(R.drawable.ic_install_no_shadow, R.string.install_drop_target_label, @@ -186,7 +188,7 @@ public abstract class SystemShortcut extends Ite } } - public static void dismissTaskMenuView(BaseDraggingActivity activity) { + public static void dismissTaskMenuView(T activity) { AbstractFloatingView.closeOpenViews(activity, true, AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE); } diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java index e07d71e3af..a2e4ad6809 100644 --- a/src/com/android/launcher3/views/ActivityContext.java +++ b/src/com/android/launcher3/views/ActivityContext.java @@ -19,6 +19,7 @@ import android.content.Context; import android.content.ContextWrapper; import android.graphics.Rect; import android.view.LayoutInflater; +import android.view.View; import android.view.View.AccessibilityDelegate; import androidx.annotation.Nullable; @@ -159,4 +160,10 @@ public interface ActivityContext { return null; } } + + default View.OnClickListener getItemOnClickListener() { + return v -> { + // No op. + }; + } }