Merge "Add a bubble option to launcher long press menus" into main

This commit is contained in:
Mady Mellor
2024-08-09 17:25:02 +00:00
committed by Android (Google) Code Review
8 changed files with 179 additions and 8 deletions
@@ -25,6 +25,7 @@ import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.Flags;
import com.android.launcher3.LauncherSettings;
@@ -97,6 +98,8 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon {
public int options;
@Nullable
private ShortcutInfo mShortcutInfo = null;
public WorkspaceItemInfo() {
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
@@ -175,6 +178,9 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon {
public void updateFromDeepShortcutInfo(@NonNull final ShortcutInfo shortcutInfo,
@NonNull final Context context) {
if (com.android.wm.shell.Flags.enableBubbleAnything()) {
mShortcutInfo = shortcutInfo;
}
// {@link ShortcutInfo#getActivity} can change during an update. Recreate the intent
intent = ShortcutKey.makeIntent(shortcutInfo);
title = shortcutInfo.getShortLabel();
@@ -204,6 +210,11 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon {
: Arrays.stream(persons).map(Person::getKey).sorted().toArray(String[]::new);
}
@Nullable
public ShortcutInfo getDeepShortcutInfo() {
return mShortcutInfo;
}
/**
* {@code true} if the shortcut is disabled due to its app being a lower version.
*/
@@ -11,9 +11,11 @@ import android.app.ActivityOptions;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.graphics.Rect;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
@@ -25,6 +27,7 @@ import androidx.annotation.Nullable;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.AbstractFloatingViewHelper;
import com.android.launcher3.Flags;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.SecondaryDropTarget;
import com.android.launcher3.Utilities;
@@ -53,6 +56,7 @@ import java.util.Arrays;
*/
public abstract class SystemShortcut<T extends ActivityContext> extends ItemInfo
implements View.OnClickListener {
private static final String TAG = "SystemShortcut";
private final int mIconResId;
protected final int mLabelResId;
@@ -383,4 +387,63 @@ public abstract class SystemShortcut<T extends ActivityContext> extends ItemInfo
mAbstractFloatingViewHelper.closeOpenViews(mTarget, true,
AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
}
public static final Factory<ActivityContext> BUBBLE_SHORTCUT =
(activity, itemInfo, originalView) -> {
if ((itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)
&& (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION)
&& !(itemInfo instanceof WorkspaceItemInfo)) {
return null;
}
return new BubbleShortcut(activity, itemInfo, originalView);
};
public interface BubbleActivityStarter {
/** Tell SysUI to show the provided shortcut in a bubble. */
void showShortcutBubble(ShortcutInfo info);
/** Tell SysUI to show the provided intent in a bubble. */
void showAppBubble(Intent intent);
}
public static class BubbleShortcut<T extends ActivityContext> extends SystemShortcut<T> {
private BubbleActivityStarter mStarter;
public BubbleShortcut(T target, ItemInfo itemInfo, View originalView) {
super(R.drawable.ic_bubble_button, R.string.bubble, target,
itemInfo, originalView);
if (target instanceof BubbleActivityStarter) {
mStarter = (BubbleActivityStarter) target;
}
}
@Override
public void onClick(View view) {
dismissTaskMenuView();
if (mStarter == null) {
Log.w(TAG, "starter null!");
return;
}
// TODO: handle GroupTask (single) items so that recent items in taskbar work
if (mItemInfo instanceof WorkspaceItemInfo) {
WorkspaceItemInfo workspaceItemInfo = (WorkspaceItemInfo) mItemInfo;
ShortcutInfo shortcutInfo = workspaceItemInfo.getDeepShortcutInfo();
if (shortcutInfo != null) {
mStarter.showShortcutBubble(shortcutInfo);
return;
}
}
// If we're here check for an intent
Intent intent = mItemInfo.getIntent();
if (intent != null) {
if (intent.getPackage() == null) {
intent.setPackage(mItemInfo.getTargetPackage());
}
mStarter.showAppBubble(intent);
} else {
Log.w(TAG, "unable to bubble, no intent: " + mItemInfo);
}
}
}
}