diff --git a/res/values/config.xml b/res/values/config.xml index 09456425c1..ef34dcd6d7 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -108,6 +108,7 @@ + diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java index 3f723d17f1..c99465c77c 100644 --- a/src/com/android/launcher3/ItemInfo.java +++ b/src/com/android/launcher3/ItemInfo.java @@ -214,4 +214,11 @@ public class ItemInfo { return id; } + /** + * Returns if an Item is a predicted item + */ + public boolean isPredictedItem() { + return container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION + || container == LauncherSettings.Favorites.CONTAINER_PREDICTION; + } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 445ebc08eb..cfbe2f182b 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -32,7 +32,6 @@ import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOA import static com.android.launcher3.logging.LoggerUtils.newContainerTarget; import static com.android.launcher3.logging.LoggerUtils.newTarget; import static com.android.launcher3.popup.SystemShortcut.APP_INFO; -import static com.android.launcher3.popup.SystemShortcut.DISMISS_PREDICTION; import static com.android.launcher3.popup.SystemShortcut.INSTALL; import static com.android.launcher3.popup.SystemShortcut.WIDGETS; import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; @@ -2691,7 +2690,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } public Stream getSupportedShortcuts() { - return Stream.of(APP_INFO, WIDGETS, INSTALL, DISMISS_PREDICTION); + return Stream.of(APP_INFO, WIDGETS, INSTALL); } public static Launcher getLauncher(Context context) { diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java index 3c2ed72592..1dbe195da3 100644 --- a/src/com/android/launcher3/SecondaryDropTarget.java +++ b/src/com/android/launcher3/SecondaryDropTarget.java @@ -6,6 +6,7 @@ import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURA import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_MASK; import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_NO; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; +import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL; @@ -29,9 +30,11 @@ import android.view.View; import android.widget.Toast; import com.android.launcher3.Launcher.OnResumeCallback; +import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.logging.FileLog; import com.android.launcher3.logging.LoggerUtils; +import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.PackageManagerHelper; @@ -43,6 +46,7 @@ import java.net.URISyntaxException; * Drop target which provides a secondary option for an item. * For app targets: shows as uninstall * For configurable widgets: shows as setup + * For predicted app icons: don't suggest app */ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmListener { @@ -81,7 +85,11 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList mHoverColor = getResources().getColor(R.color.uninstall_target_hover_tint); setDrawable(R.drawable.ic_uninstall_shadow); updateText(R.string.uninstall_drop_target_label); - } else { + } else if (action == DISMISS_PREDICTION) { + mHoverColor = Themes.getColorAccent(getContext()); + setDrawable(R.drawable.ic_block); + updateText(R.string.dismiss_prediction_label); + } else if (action == RECONFIGURE) { mHoverColor = Themes.getColorAccent(getContext()); setDrawable(R.drawable.ic_setup_shadow); updateText(R.string.gadget_setup_text); @@ -101,8 +109,13 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList @Override public Target getDropTargetForLogging() { Target t = LoggerUtils.newTarget(Target.Type.CONTROL); - t.controlType = mCurrentAccessibilityAction == UNINSTALL ? ControlType.UNINSTALL_TARGET - : ControlType.SETTINGS_BUTTON; + if (mCurrentAccessibilityAction == UNINSTALL) { + t.controlType = ControlType.UNINSTALL_TARGET; + } else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) { + t.controlType = ControlType.DISMISS_PREDICTION; + } else { + t.controlType = ControlType.SETTINGS_BUTTON; + } return t; } @@ -119,6 +132,9 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList return true; } return false; + } else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) { + setupUi(DISMISS_PREDICTION); + return true; } setupUi(UNINSTALL); @@ -229,6 +245,11 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList } return null; } + if (mCurrentAccessibilityAction == DISMISS_PREDICTION) { + AppLaunchTracker.INSTANCE.get(getContext()).onDismissApp(info.getTargetComponent(), + info.user, AppLaunchTracker.CONTAINER_PREDICTIONS); + return null; + } // else: mCurrentAccessibilityAction == UNINSTALL ComponentName cn = getUninstallTarget(info); diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index ed869bb09a..0b439ec362 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -54,6 +54,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme public static final int REMOVE = R.id.action_remove; public static final int UNINSTALL = R.id.action_uninstall; + public static final int DISMISS_PREDICTION = R.id.action_dismiss_prediction; public static final int RECONFIGURE = R.id.action_reconfigure; protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace; protected static final int MOVE = R.id.action_move; @@ -86,6 +87,8 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme launcher.getText(R.string.remove_drop_target_label))); mActions.put(UNINSTALL, new AccessibilityAction(UNINSTALL, launcher.getText(R.string.uninstall_drop_target_label))); + mActions.put(DISMISS_PREDICTION, new AccessibilityAction(DISMISS_PREDICTION, + launcher.getText(R.string.dismiss_prediction_label))); mActions.put(RECONFIGURE, new AccessibilityAction(RECONFIGURE, launcher.getText(R.string.gadget_setup_text))); mActions.put(ADD_TO_WORKSPACE, new AccessibilityAction(ADD_TO_WORKSPACE, diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index b1529546b2..21c5ac5cc2 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -16,14 +16,10 @@ import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; import com.android.launcher3.WorkspaceItemInfo; -import com.android.launcher3.config.FeatureFlags; -import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.userevent.nano.LauncherLogProto.Action; -import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; import com.android.launcher3.util.InstantAppResolver; import com.android.launcher3.util.PackageManagerHelper; @@ -176,33 +172,6 @@ public abstract class SystemShortcut extends Ite } } - public static final Factory DISMISS_PREDICTION = (launcher, itemInfo) -> { - if (!FeatureFlags.ENABLE_PREDICTION_DISMISS.get()) return null; - if (itemInfo.container != LauncherSettings.Favorites.CONTAINER_PREDICTION - && itemInfo.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) { - return null; - } - return new DismissPrediction(launcher, itemInfo); - }; - - public static class DismissPrediction extends SystemShortcut { - public DismissPrediction(Launcher launcher, ItemInfo itemInfo) { - super(R.drawable.ic_block, R.string.dismiss_prediction_label, launcher, - itemInfo); - } - - @Override - public void onClick(View view) { - PopupContainerWithArrow.closeAllOpenViews(mTarget); - mTarget.getUserEventDispatcher().logActionOnControl(Action.Touch.TAP, - ControlType.DISMISS_PREDICTION, ContainerType.DEEPSHORTCUTS); - AppLaunchTracker.INSTANCE.get(view.getContext()).onDismissApp( - mItemInfo.getTargetComponent(), - mItemInfo.user, - AppLaunchTracker.CONTAINER_PREDICTIONS); - } - } - public static void dismissTaskMenuView(BaseDraggingActivity activity) { AbstractFloatingView.closeOpenViews(activity, true, AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);