Merge "Filter shortcuts in the widget picker activity." into main
diff --git a/go/src/com/android/launcher3/model/WidgetsModel.java b/go/src/com/android/launcher3/model/WidgetsModel.java
index 1aa5d03..3a28444 100644
--- a/go/src/com/android/launcher3/model/WidgetsModel.java
+++ b/go/src/com/android/launcher3/model/WidgetsModel.java
@@ -33,6 +33,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.Predicate;
/**
* Widgets data model that is used by the adapters of the widget views and controllers.
@@ -48,6 +49,19 @@
private static final ArrayList<WidgetsListBaseEntry> EMPTY_WIDGET_LIST = new ArrayList<>();
/**
+ * Returns a list of {@link WidgetsListBaseEntry} filtered using given widget item filter. All
+ * {@link WidgetItem}s in a single row are sorted (based on label and user), but the overall
+ * list of {@link WidgetsListBaseEntry}s is not sorted.
+ *
+ * @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
+ */
+ public synchronized ArrayList<WidgetsListBaseEntry> getFilteredWidgetsListForPicker(
+ Context context,
+ Predicate<WidgetItem> widgetItemFilter) {
+ return EMPTY_WIDGET_LIST;
+ }
+
+ /**
* Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row are
* sorted (based on label and user), but the overall list of {@link WidgetsListBaseEntry}s is
* not sorted. This list is sorted at the UI when using
@@ -88,4 +102,4 @@
Context context, ComponentName provider, UserHandle userHandle) {
return new PackageItemInfo(provider.getPackageName(), userHandle);
}
-}
\ No newline at end of file
+}
diff --git a/quickstep/src/com/android/launcher3/WidgetPickerActivity.java b/quickstep/src/com/android/launcher3/WidgetPickerActivity.java
index 575ad9e..b9b4461 100644
--- a/quickstep/src/com/android/launcher3/WidgetPickerActivity.java
+++ b/quickstep/src/com/android/launcher3/WidgetPickerActivity.java
@@ -158,7 +158,10 @@
LauncherAppState app = LauncherAppState.getInstance(this);
mModel.update(app, null);
final ArrayList<WidgetsListBaseEntry> widgets =
- mModel.getWidgetsListForPicker(app.getContext());
+ mModel.getFilteredWidgetsListForPicker(
+ app.getContext(),
+ /*widgetItemFilter=*/ item -> item.widgetInfo != null
+ );
MAIN_EXECUTOR.execute(() -> mPopupDataProvider.setAllWidgets(widgets));
});
}
diff --git a/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java b/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java
index 2f16065..4c5bfd8 100644
--- a/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java
+++ b/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java
@@ -70,6 +70,34 @@
private final Map<PackageItemInfo, List<WidgetItem>> mWidgetsList = new HashMap<>();
/**
+ * Returns a list of {@link WidgetsListBaseEntry} filtered using given widget item filter. All
+ * {@link WidgetItem}s in a single row are sorted (based on label and user), but the overall
+ * list of {@link WidgetsListBaseEntry}s is not sorted.
+ *
+ * @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
+ */
+ public synchronized ArrayList<WidgetsListBaseEntry> getFilteredWidgetsListForPicker(
+ Context context,
+ Predicate<WidgetItem> widgetItemFilter) {
+ ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
+ AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
+
+ for (Map.Entry<PackageItemInfo, List<WidgetItem>> entry : mWidgetsList.entrySet()) {
+ PackageItemInfo pkgItem = entry.getKey();
+ List<WidgetItem> widgetItems = entry.getValue()
+ .stream()
+ .filter(widgetItemFilter).toList();
+ if (!widgetItems.isEmpty()) {
+ String sectionName = (pkgItem.title == null) ? "" :
+ indexer.computeSectionName(pkgItem.title);
+ result.add(WidgetsListHeaderEntry.create(pkgItem, sectionName, widgetItems));
+ result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
+ }
+ }
+ return result;
+ }
+
+ /**
* Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row
* are sorted (based on label and user), but the overall list of
* {@link WidgetsListBaseEntry}s is not sorted.
@@ -77,18 +105,8 @@
* @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
*/
public synchronized ArrayList<WidgetsListBaseEntry> getWidgetsListForPicker(Context context) {
- ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
- AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
-
- for (Map.Entry<PackageItemInfo, List<WidgetItem>> entry : mWidgetsList.entrySet()) {
- PackageItemInfo pkgItem = entry.getKey();
- List<WidgetItem> widgetItems = entry.getValue();
- String sectionName = (pkgItem.title == null) ? "" :
- indexer.computeSectionName(pkgItem.title);
- result.add(WidgetsListHeaderEntry.create(pkgItem, sectionName, widgetItems));
- result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
- }
- return result;
+ // return all items
+ return getFilteredWidgetsListForPicker(context, /*widgetItemFilter=*/ item -> true);
}
/** Returns a mapping of packages to their widgets without static shortcuts. */