Merge "Generalize the icon popup menu types." into sc-v2-dev am: e9bd364390

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/16065857

Change-Id: I305a7f34346d90785d78e52222f1b9a2e764c04e
This commit is contained in:
Schneider Victor-tulias authored and Automerger Merge Worker committed 2021-10-20 18:51:39 +00:00
commit e650a048fa
10 files changed
+47 -33

No files matched your search

@@ -30,6 +30,7 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace; import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.FolderInfo;
@@ -298,7 +299,7 @@ public class HotseatEduController {
Log.e(TAG, "Unable to find suitable view for ArrowTip"); Log.e(TAG, "Unable to find suitable view for ArrowTip");
return false; return false;
} }
Rect bounds = mLauncher.getViewBounds(tipTargetView); Rect bounds = Utilities.getViewBounds(tipTargetView);
new ArrowTipView(mLauncher).show(message, Gravity.END, bounds.centerX(), bounds.top); new ArrowTipView(mLauncher).show(message, Gravity.END, bounds.centerX(), bounds.top);
return true; return true;
} }
@@ -377,7 +377,7 @@ public final class WellbeingModel extends BgObjectWithLooper {
/** /**
* Shortcut factory for generating wellbeing action * Shortcut factory for generating wellbeing action
*/ */
public static final SystemShortcut.Factory SHORTCUT_FACTORY = public static final SystemShortcut.Factory<BaseDraggingActivity> SHORTCUT_FACTORY =
(activity, info) -> (info.getTargetComponent() == null) ? null : INSTANCE.get(activity) (activity, info) -> (info.getTargetComponent() == null) ? null : INSTANCE.get(activity)
.getShortcutForApp( .getShortcutForApp(
info.getTargetComponent().getPackageName(), info.user.getIdentifier(), info.getTargetComponent().getPackageName(), info.user.getIdentifier(),
@@ -128,7 +128,7 @@ public interface TaskShortcutFactory {
} }
} }
class MultiWindowSystemShortcut extends SystemShortcut { class MultiWindowSystemShortcut extends SystemShortcut<BaseDraggingActivity> {
private Handler mHandler; private Handler mHandler;
@@ -305,7 +305,7 @@ public interface TaskShortcutFactory {
return new PinSystemShortcut(activity, taskContainer); return new PinSystemShortcut(activity, taskContainer);
}; };
class PinSystemShortcut extends SystemShortcut { class PinSystemShortcut extends SystemShortcut<BaseDraggingActivity> {
private static final String TAG = "PinSystemShortcut"; private static final String TAG = "PinSystemShortcut";
@@ -41,7 +41,6 @@ import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Display; import android.view.Display;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowInsets.Type; import android.view.WindowInsets.Type;
import android.view.WindowMetrics; import android.view.WindowMetrics;
import android.widget.Toast; import android.widget.Toast;
@@ -166,12 +165,6 @@ public abstract class BaseDraggingActivity extends BaseActivity
// no-op // 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 @NonNull
public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) { public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) {
int left = 0, top = 0; int left = 0, top = 0;
@@ -206,7 +199,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
// Prepare intent // Prepare intent
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (v != null) { if (v != null) {
intent.setSourceBounds(getViewBounds(v)); intent.setSourceBounds(Utilities.getViewBounds(v));
} }
try { try {
boolean isShortcut = (item instanceof WorkspaceItemInfo) 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; return ItemClickHandler.INSTANCE;
} }
+7
View File
@@ -69,6 +69,7 @@ import android.view.ViewConfiguration;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.core.os.BuildCompat; import androidx.core.os.BuildCompat;
@@ -846,6 +847,12 @@ public final class Utilities {
view.setLayoutParams(lp); 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 static class FixedSizeEmptyDrawable extends ColorDrawable {
private final int mSize; private final int mSize;
+1 -1
View File
@@ -1676,7 +1676,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
} }
if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) { if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
PopupContainerWithArrow popupContainer = PopupContainerWithArrow PopupContainerWithArrow<Launcher> popupContainer = PopupContainerWithArrow
.showForIcon((BubbleTextView) child); .showForIcon((BubbleTextView) child);
if (popupContainer != null) { if (popupContainer != null) {
dragOptions.preDragCondition = popupContainer.createPreDragCondition(); dragOptions.preDragCondition = popupContainer.createPreDragCondition();
@@ -66,6 +66,7 @@ import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider;
import com.android.launcher3.touch.ItemLongClickListener; import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.ShortcutUtil; import com.android.launcher3.util.ShortcutUtil;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.views.BaseDragLayer;
import java.util.ArrayList; import java.util.ArrayList;
@@ -81,7 +82,7 @@ import java.util.stream.Collectors;
* *
* @param <T> The activity on with the popup shows * @param <T> The activity on with the popup shows
*/ */
public class PopupContainerWithArrow<T extends BaseDraggingActivity> public class PopupContainerWithArrow<T extends Context & ActivityContext>
extends ArrowPopup<T> implements DragSource, DragController.DragListener { extends ArrowPopup<T> implements DragSource, DragController.DragListener {
private final List<DeepShortcutView> mShortcuts = new ArrayList<>(); private final List<DeepShortcutView> mShortcuts = new ArrayList<>();
@@ -190,10 +191,10 @@ public class PopupContainerWithArrow<T extends BaseDraggingActivity>
} }
/** /**
* 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. * @return the container if shown or null.
*/ */
public static PopupContainerWithArrow showForIcon(BubbleTextView icon) { public static PopupContainerWithArrow<Launcher> showForIcon(BubbleTextView icon) {
Launcher launcher = Launcher.getLauncher(icon.getContext()); Launcher launcher = Launcher.getLauncher(icon.getContext());
if (getOpen(launcher) != null) { if (getOpen(launcher) != null) {
// There is already an items container open, so don't open this one. // There is already an items container open, so don't open this one.
@@ -205,7 +206,7 @@ public class PopupContainerWithArrow<T extends BaseDraggingActivity>
return null; return null;
} }
final PopupContainerWithArrow container = final PopupContainerWithArrow<Launcher> container =
(PopupContainerWithArrow) launcher.getLayoutInflater().inflate( (PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
R.layout.popup_container, launcher.getDragLayer(), false); R.layout.popup_container, launcher.getDragLayer(), false);
container.configureForLauncher(launcher); container.configureForLauncher(launcher);
@@ -489,8 +490,8 @@ public class PopupContainerWithArrow<T extends BaseDraggingActivity>
/** /**
* Returns a PopupContainerWithArrow which is already open or null * Returns a PopupContainerWithArrow which is already open or null
*/ */
public static PopupContainerWithArrow getOpen(BaseDraggingActivity launcher) { public static <T extends Context & ActivityContext> PopupContainerWithArrow getOpen(T context) {
return getOpenView(launcher, TYPE_ACTION_POPUP); return getOpenView(context, TYPE_ACTION_POPUP);
} }
/** /**
@@ -19,6 +19,7 @@ package com.android.launcher3.popup;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutInfo;
import android.os.Handler; import android.os.Handler;
import android.os.UserHandle; import android.os.UserHandle;
@@ -26,7 +27,6 @@ import android.os.UserHandle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppState;
import com.android.launcher3.icons.IconCache; import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.data.ItemInfo; 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.notification.NotificationListener;
import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.ShortcutRequest; import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.views.ActivityContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -128,7 +129,8 @@ public class PopupPopulator {
/** /**
* Returns a runnable to update the provided shortcuts and notifications * Returns a runnable to update the provided shortcuts and notifications
*/ */
public static Runnable createUpdateRunnable(final BaseDraggingActivity launcher, public static <T extends Context & ActivityContext> Runnable createUpdateRunnable(
final T context,
final ItemInfo originalInfo, final ItemInfo originalInfo,
final Handler uiHandler, final PopupContainerWithArrow container, final Handler uiHandler, final PopupContainerWithArrow container,
final List<DeepShortcutView> shortcutViews, final List<DeepShortcutView> shortcutViews,
@@ -144,22 +146,22 @@ public class PopupPopulator {
infos = Collections.emptyList(); infos = Collections.emptyList();
} else { } else {
infos = notificationListener.getNotificationsForKeys(notificationKeys).stream() infos = notificationListener.getNotificationsForKeys(notificationKeys).stream()
.map(sbn -> new NotificationInfo(launcher, sbn, originalInfo)) .map(sbn -> new NotificationInfo(context, sbn, originalInfo))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
uiHandler.post(() -> container.applyNotificationInfos(infos)); uiHandler.post(() -> container.applyNotificationInfos(infos));
} }
List<ShortcutInfo> shortcuts = new ShortcutRequest(launcher, user) List<ShortcutInfo> shortcuts = new ShortcutRequest(context, user)
.withContainer(activity) .withContainer(activity)
.query(ShortcutRequest.PUBLISHED); .query(ShortcutRequest.PUBLISHED);
String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null
: notificationKeys.get(0).shortcutId; : notificationKeys.get(0).shortcutId;
shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe); 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++) { for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) {
final ShortcutInfo shortcut = shortcuts.get(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); cache.getUnbadgedShortcutIcon(si, shortcut);
si.rank = i; si.rank = i;
si.container = CONTAINER_SHORTCUTS; si.container = CONTAINER_SHORTCUTS;
@@ -18,12 +18,14 @@ import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.InstantAppResolver; import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.widget.WidgetsBottomSheet; import com.android.launcher3.widget.WidgetsBottomSheet;
import java.util.List; import java.util.List;
@@ -35,7 +37,7 @@ import java.util.List;
* Example system shortcuts, defined as inner classes, include Widgets and AppInfo. * Example system shortcuts, defined as inner classes, include Widgets and AppInfo.
* @param <T> * @param <T>
*/ */
public abstract class SystemShortcut<T extends BaseDraggingActivity> extends ItemInfo public abstract class SystemShortcut<T extends Context & ActivityContext> extends ItemInfo
implements View.OnClickListener { implements View.OnClickListener {
private final int mIconResId; private final int mIconResId;
@@ -100,7 +102,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
return mAccessibilityActionId == action; return mAccessibilityActionId == action;
} }
public interface Factory<T extends BaseDraggingActivity> { public interface Factory<T extends Context & ActivityContext> {
@Nullable SystemShortcut<T> getShortcut(T activity, ItemInfo itemInfo); @Nullable SystemShortcut<T> getShortcut(T activity, ItemInfo itemInfo);
} }
@@ -135,9 +137,9 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
public static final Factory<BaseDraggingActivity> APP_INFO = AppInfo::new; public static final Factory<BaseDraggingActivity> APP_INFO = AppInfo::new;
public static class AppInfo extends SystemShortcut { public static class AppInfo<T extends Context & ActivityContext> extends SystemShortcut<T> {
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, super(R.drawable.ic_info_no_shadow, R.string.app_info_drop_target_label, target,
itemInfo); itemInfo);
} }
@@ -145,7 +147,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
@Override @Override
public void onClick(View view) { public void onClick(View view) {
dismissTaskMenuView(mTarget); dismissTaskMenuView(mTarget);
Rect sourceBounds = mTarget.getViewBounds(view); Rect sourceBounds = Utilities.getViewBounds(view);
new PackageManagerHelper(mTarget).startDetailsActivityForInfo( new PackageManagerHelper(mTarget).startDetailsActivityForInfo(
mItemInfo, sourceBounds, ActivityOptions.makeBasic().toBundle()); mItemInfo, sourceBounds, ActivityOptions.makeBasic().toBundle());
mTarget.getStatsLogManager().logger().withItemInfo(mItemInfo) mTarget.getStatsLogManager().logger().withItemInfo(mItemInfo)
@@ -170,7 +172,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
return new Install(activity, itemInfo); return new Install(activity, itemInfo);
}; };
public static class Install extends SystemShortcut { public static class Install extends SystemShortcut<BaseDraggingActivity> {
public Install(BaseDraggingActivity target, ItemInfo itemInfo) { public Install(BaseDraggingActivity target, ItemInfo itemInfo) {
super(R.drawable.ic_install_no_shadow, R.string.install_drop_target_label, super(R.drawable.ic_install_no_shadow, R.string.install_drop_target_label,
@@ -186,7 +188,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
} }
} }
public static void dismissTaskMenuView(BaseDraggingActivity activity) { public static <T extends Context & ActivityContext> void dismissTaskMenuView(T activity) {
AbstractFloatingView.closeOpenViews(activity, true, AbstractFloatingView.closeOpenViews(activity, true,
AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE); AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
} }
@@ -19,6 +19,7 @@ import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.graphics.Rect; import android.graphics.Rect;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.view.View.AccessibilityDelegate; import android.view.View.AccessibilityDelegate;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@@ -159,4 +160,10 @@ public interface ActivityContext {
return null; return null;
} }
} }
default View.OnClickListener getItemOnClickListener() {
return v -> {
// No op.
};
}
} }