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

This commit is contained in:
Schneider Victor-tulias
2021-10-20 18:32:56 +00:00
committed by Android (Google) Code Review
10 changed files with 47 additions and 33 deletions

View File

@@ -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;
}

View File

@@ -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<BaseDraggingActivity> SHORTCUT_FACTORY =
(activity, info) -> (info.getTargetComponent() == null) ? null : INSTANCE.get(activity)
.getShortcutForApp(
info.getTargetComponent().getPackageName(), info.user.getIdentifier(),

View File

@@ -128,7 +128,7 @@ public interface TaskShortcutFactory {
}
}
class MultiWindowSystemShortcut extends SystemShortcut {
class MultiWindowSystemShortcut extends SystemShortcut<BaseDraggingActivity> {
private Handler mHandler;
@@ -305,7 +305,7 @@ public interface TaskShortcutFactory {
return new PinSystemShortcut(activity, taskContainer);
};
class PinSystemShortcut extends SystemShortcut {
class PinSystemShortcut extends SystemShortcut<BaseDraggingActivity> {
private static final String TAG = "PinSystemShortcut";

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -1676,7 +1676,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
PopupContainerWithArrow popupContainer = PopupContainerWithArrow
PopupContainerWithArrow<Launcher> popupContainer = PopupContainerWithArrow
.showForIcon((BubbleTextView) child);
if (popupContainer != null) {
dragOptions.preDragCondition = popupContainer.createPreDragCondition();

View File

@@ -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 <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 {
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.
*/
public static PopupContainerWithArrow showForIcon(BubbleTextView icon) {
public static PopupContainerWithArrow<Launcher> 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<T extends BaseDraggingActivity>
return null;
}
final PopupContainerWithArrow container =
final PopupContainerWithArrow<Launcher> container =
(PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
R.layout.popup_container, launcher.getDragLayer(), false);
container.configureForLauncher(launcher);
@@ -489,8 +490,8 @@ public class PopupContainerWithArrow<T extends BaseDraggingActivity>
/**
* Returns a PopupContainerWithArrow which is already open or null
*/
public static PopupContainerWithArrow getOpen(BaseDraggingActivity launcher) {
return getOpenView(launcher, TYPE_ACTION_POPUP);
public static <T extends Context & ActivityContext> PopupContainerWithArrow getOpen(T context) {
return getOpenView(context, TYPE_ACTION_POPUP);
}
/**

View File

@@ -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 <T extends Context & ActivityContext> Runnable createUpdateRunnable(
final T context,
final ItemInfo originalInfo,
final Handler uiHandler, final PopupContainerWithArrow container,
final List<DeepShortcutView> 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<ShortcutInfo> shortcuts = new ShortcutRequest(launcher, user)
List<ShortcutInfo> 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;

View File

@@ -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 <T>
*/
public abstract class SystemShortcut<T extends BaseDraggingActivity> extends ItemInfo
public abstract class SystemShortcut<T extends Context & ActivityContext> extends ItemInfo
implements View.OnClickListener {
private final int mIconResId;
@@ -100,7 +102,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
return mAccessibilityActionId == action;
}
public interface Factory<T extends BaseDraggingActivity> {
public interface Factory<T extends Context & ActivityContext> {
@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 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,
itemInfo);
}
@@ -145,7 +147,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> 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<T extends BaseDraggingActivity> extends Ite
return new Install(activity, itemInfo);
};
public static class Install extends SystemShortcut {
public static class Install extends SystemShortcut<BaseDraggingActivity> {
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<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.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
}

View File

@@ -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.
};
}
}