diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index d9d46d4f38..1e29cac248 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -85,6 +85,7 @@ import com.android.launcher3.taskbar.overlay.TaskbarOverlayController; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; import com.android.launcher3.touch.ItemClickHandler; +import com.android.launcher3.touch.ItemClickHandler.ItemClickProxy; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.NavigationMode; import com.android.launcher3.util.PackageManagerHelper; @@ -828,6 +829,8 @@ public class TaskbarActivityContext extends BaseTaskbarContext { mControllers.uiController.onTaskbarIconLaunched((AppInfo) tag); } mControllers.taskbarStashController.updateAndAnimateTransientTaskbar(true); + } else if (tag instanceof ItemClickProxy) { + ((ItemClickProxy) tag).onItemClicked(view); } else { Log.e(TAG, "Unknown type clicked: " + tag); } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index ce009a1375..b10256e53d 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -73,7 +73,6 @@ import com.android.launcher3.icons.ShortcutCachingLogic; import com.android.launcher3.icons.ThemedIconDrawable; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; -import com.android.launcher3.model.data.SearchActionItemInfo; import com.android.launcher3.pm.ShortcutConfigActivityInfo; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.shortcuts.ShortcutRequest; @@ -591,8 +590,8 @@ public final class Utilities { outObj[0] = icon; return icon; } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION - && info instanceof SearchActionItemInfo) { - return ((SearchActionItemInfo) info).bitmap.newIcon(context); + && info instanceof ItemInfoWithIcon) { + return ((ItemInfoWithIcon) info).bitmap.newIcon(context); } else { return null; } diff --git a/src/com/android/launcher3/model/data/SearchActionItemInfo.java b/src/com/android/launcher3/model/data/SearchActionItemInfo.java deleted file mode 100644 index 04042ea6fa..0000000000 --- a/src/com/android/launcher3/model/data/SearchActionItemInfo.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.launcher3.model.data; - -import static com.android.launcher3.LauncherSettings.Favorites.EXTENDED_CONTAINERS; - -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.graphics.drawable.Icon; -import android.os.Process; -import android.os.UserHandle; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherSettings; -import com.android.launcher3.logger.LauncherAtom.ItemInfo; -import com.android.launcher3.logger.LauncherAtom.SearchActionItem; - -/** - * Represents a SearchAction with in launcher - */ -public class SearchActionItemInfo extends ItemInfoWithIcon implements WorkspaceItemFactory { - - public static final int FLAG_SHOULD_START = 1 << 1; - public static final int FLAG_SHOULD_START_FOR_RESULT = FLAG_SHOULD_START | 1 << 2; - public static final int FLAG_BADGE_WITH_PACKAGE = 1 << 3; - public static final int FLAG_PRIMARY_ICON_FROM_TITLE = 1 << 4; - public static final int FLAG_BADGE_WITH_COMPONENT_NAME = 1 << 5; - public static final int FLAG_ALLOW_PINNING = 1 << 6; - public static final int FLAG_SEARCH_IN_APP = 1 << 7; - - private String mFallbackPackageName; - private int mFlags = 0; - private Icon mIcon; - - // If true title does not contain any personal info and eligible for logging. - private boolean mIsPersonalTitle; - private Intent mIntent; - - private PendingIntent mPendingIntent; - - public SearchActionItemInfo(Icon icon, String packageName, UserHandle user, - CharSequence title, boolean isPersonalTitle) { - mIsPersonalTitle = isPersonalTitle; - this.itemType = LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION; - this.user = user == null ? Process.myUserHandle() : user; - this.title = title; - this.container = EXTENDED_CONTAINERS; - mFallbackPackageName = packageName; - mIcon = icon; - } - - private SearchActionItemInfo(SearchActionItemInfo info) { - super(info); - } - - @Override - public void copyFrom(@NonNull com.android.launcher3.model.data.ItemInfo info) { - super.copyFrom(info); - SearchActionItemInfo itemInfo = (SearchActionItemInfo) info; - this.mFallbackPackageName = itemInfo.mFallbackPackageName; - this.mIcon = itemInfo.mIcon; - this.mFlags = itemInfo.mFlags; - this.mIsPersonalTitle = itemInfo.mIsPersonalTitle; - } - - /** - * Returns if multiple flags are all available. - */ - public boolean hasFlags(int flags) { - return (mFlags & flags) != 0; - } - - public void setFlags(int flags) { - mFlags |= flags; - } - - @Override - @Nullable - public Intent getIntent() { - return mIntent; - } - - /** - * Setter for mIntent with assertion for null value mPendingIntent - */ - public void setIntent(Intent intent) { - if (mPendingIntent != null && intent != null) { - throw new RuntimeException( - "SearchActionItemInfo can only have either an Intent or a PendingIntent"); - } - mIntent = intent; - } - - public PendingIntent getPendingIntent() { - return mPendingIntent; - } - - /** - * Setter of mPendingIntent with assertion for null value mIntent - */ - public void setPendingIntent(PendingIntent pendingIntent) { - if (mIntent != null && pendingIntent != null) { - throw new RuntimeException( - "SearchActionItemInfo can only have either an Intent or a PendingIntent"); - } - mPendingIntent = pendingIntent; - } - - @Nullable - public Icon getIcon() { - return mIcon; - } - - @Override - public ItemInfoWithIcon clone() { - return new SearchActionItemInfo(this); - } - - @NonNull - @Override - public ItemInfo buildProto(@Nullable FolderInfo fInfo) { - SearchActionItem.Builder itemBuilder = SearchActionItem.newBuilder() - .setPackageName(mFallbackPackageName); - - if (!mIsPersonalTitle) { - itemBuilder.setTitle(title.toString()); - } - return getDefaultItemInfoBuilder() - .setSearchActionItem(itemBuilder) - .setContainerInfo(getContainerInfo()) - .build(); - } - - /** - * Returns true if result supports drag/drop to home screen - */ - public boolean supportsPinning() { - return hasFlags(FLAG_ALLOW_PINNING) && getIntentPackageName() != null; - } - - /** - * Creates a {@link WorkspaceItemInfo} coorsponding to search action to be stored in launcher db - */ - @Override - public WorkspaceItemInfo makeWorkspaceItem(Context context) { - WorkspaceItemInfo info = new WorkspaceItemInfo(); - info.title = title; - info.bitmap = bitmap; - info.intent = mIntent; - - if (hasFlags(FLAG_SHOULD_START_FOR_RESULT)) { - info.options |= WorkspaceItemInfo.FLAG_START_FOR_RESULT; - } - LauncherAppState app = LauncherAppState.getInstance(context); - app.getModel().updateAndBindWorkspaceItem(() -> { - PackageItemInfo pkgInfo = new PackageItemInfo(getIntentPackageName(), user); - app.getIconCache().getTitleAndIconForApp(pkgInfo, false); - info.bitmap = info.bitmap.withBadgeInfo(pkgInfo.bitmap); - return info; - }); - return info; - } - - @Nullable - private String getIntentPackageName() { - if (mIntent != null) { - if (mIntent.getPackage() != null) return mIntent.getPackage(); - return mFallbackPackageName; - } - return null; - } -} diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java index dbab700a87..a2353d8259 100644 --- a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java +++ b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java @@ -51,6 +51,7 @@ import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.popup.PopupDataProvider; +import com.android.launcher3.touch.ItemClickHandler.ItemClickProxy; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.OnboardingPrefs; @@ -332,7 +333,9 @@ public class SecondaryDisplayLauncher extends BaseDraggingActivity if (v.getWindowToken() == null) return; Object tag = v.getTag(); - if (tag instanceof ItemInfo) { + if (tag instanceof ItemClickProxy) { + ((ItemClickProxy) tag).onItemClicked(v); + } else if (tag instanceof ItemInfo) { ItemInfo item = (ItemInfo) tag; Intent intent; if (item instanceof ItemInfoWithIcon diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java index 098cf80a3a..b7e01057b9 100644 --- a/src/com/android/launcher3/touch/ItemClickHandler.java +++ b/src/com/android/launcher3/touch/ItemClickHandler.java @@ -17,8 +17,6 @@ package com.android.launcher3.touch; import static com.android.launcher3.Launcher.REQUEST_BIND_PENDING_APPWIDGET; import static com.android.launcher3.Launcher.REQUEST_RECONFIGURE_APPWIDGET; -import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_SEARCHINAPP_LAUNCH; -import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_TAP; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_OPEN; import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_BY_PUBLISHER; import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER; @@ -27,11 +25,8 @@ import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_SA import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED; import android.app.AlertDialog; -import android.app.PendingIntent; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; -import android.content.IntentSender; import android.content.pm.LauncherApps; import android.content.pm.PackageInstaller.SessionInfo; import android.os.Process; @@ -57,7 +52,6 @@ import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.LauncherAppWidgetInfo; -import com.android.launcher3.model.data.SearchActionItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.pm.InstallSessionHelper; import com.android.launcher3.shortcuts.ShortcutKey; @@ -106,8 +100,8 @@ public class ItemClickHandler { if (v instanceof PendingAppWidgetHostView) { onClickPendingWidget((PendingAppWidgetHostView) v, launcher); } - } else if (tag instanceof SearchActionItemInfo) { - onClickSearchAction(launcher, (SearchActionItemInfo) tag); + } else if (tag instanceof ItemClickProxy) { + ((ItemClickProxy) tag).onItemClicked(v); } } @@ -311,48 +305,6 @@ public class ItemClickHandler { startAppShortcutOrInfoActivity(v, shortcut, launcher); } - /** - * Event handler for a {@link SearchActionItemInfo} click - */ - public static void onClickSearchAction(Launcher launcher, SearchActionItemInfo itemInfo) { - if (itemInfo.getIntent() != null) { - try { - if (itemInfo.hasFlags(SearchActionItemInfo.FLAG_SHOULD_START_FOR_RESULT)) { - launcher.startActivityForResult(itemInfo.getIntent(), 0); - } else { - launcher.startActivity(itemInfo.getIntent()); - } - } catch (ActivityNotFoundException e) { - Toast.makeText(launcher, - launcher.getResources().getText(R.string.shortcut_not_available), - Toast.LENGTH_SHORT).show(); - } - } else if (itemInfo.getPendingIntent() != null) { - try { - PendingIntent pendingIntent = itemInfo.getPendingIntent(); - if (!itemInfo.hasFlags(SearchActionItemInfo.FLAG_SHOULD_START)) { - pendingIntent.send(); - } else if (itemInfo.hasFlags(SearchActionItemInfo.FLAG_SHOULD_START_FOR_RESULT)) { - launcher.startIntentSenderForResult(pendingIntent.getIntentSender(), 0, null, 0, - 0, 0); - } else { - launcher.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0); - } - } catch (PendingIntent.CanceledException | IntentSender.SendIntentException e) { - Toast.makeText(launcher, - launcher.getResources().getText(R.string.shortcut_not_available), - Toast.LENGTH_SHORT).show(); - } - } - if (itemInfo.hasFlags(SearchActionItemInfo.FLAG_SEARCH_IN_APP)) { - launcher.getStatsLogManager().logger().withItemInfo(itemInfo).log( - LAUNCHER_ALLAPPS_SEARCHINAPP_LAUNCH); - } else { - launcher.getStatsLogManager().logger().withItemInfo(itemInfo).log( - LAUNCHER_APP_LAUNCH_TAP); - } - } - private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher) { TestLogging.recordEvent( TestProtocol.SEQUENCE_MAIN, "start: startAppShortcutOrInfoActivity"); @@ -393,4 +345,15 @@ public class ItemClickHandler { } launcher.startActivitySafely(v, intent, item); } + + /** + * Interface to indicate that an item will handle the click itself. + */ + public interface ItemClickProxy { + + /** + * Called when the item is clicked + */ + void onItemClicked(View view); + } }