Search in sources :

Example 41 with PackageItemInfo

use of com.android.launcher3.model.data.PackageItemInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetsModel method setWidgetsAndShortcuts.

private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
    if (DEBUG) {
        Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
    }
    // Temporary cache for {@link PackageItemInfos} to avoid having to go through
    // {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
    PackageItemInfoCache packageItemInfoCache = new PackageItemInfoCache();
    if (packageUser == null) {
        // Clear the list if this is an update on all widgets and shortcuts.
        mWidgetsList.clear();
    } else {
        // Otherwise, only clear the widgets and shortcuts for the changed package.
        mWidgetsList.remove(packageItemInfoCache.getOrCreate(packageUser));
    }
    // add and update.
    mWidgetsList.putAll(rawWidgetsShortcuts.stream().filter(new WidgetValidityCheck(app)).flatMap(widgetItem -> getPackageUserKeys(app.getContext(), widgetItem).stream().map(key -> new Pair<>(packageItemInfoCache.getOrCreate(key), widgetItem))).collect(groupingBy(pair -> pair.first, mapping(pair -> pair.second, toList()))));
    // Update each package entry
    IconCache iconCache = app.getIconCache();
    for (PackageItemInfo p : packageItemInfoCache.values()) {
        iconCache.getTitleAndIconForApp(p, true);
    }
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) NO_CATEGORY(com.android.launcher3.widget.WidgetSections.NO_CATEGORY) PackageManager(android.content.pm.PackageManager) AppFilter(com.android.launcher3.AppFilter) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pair(android.util.Pair) Preconditions(com.android.launcher3.util.Preconditions) HashMap(java.util.HashMap) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) IconCache(com.android.launcher3.icons.IconCache) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ArrayList(java.util.ArrayList) Collectors.mapping(java.util.stream.Collectors.mapping) UserHandle(android.os.UserHandle) Map(java.util.Map) Log(android.util.Log) ArrayMap(androidx.collection.ArrayMap) ShortcutConfigActivityInfo.queryList(com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList) Utilities(com.android.launcher3.Utilities) WidgetsDiffReporter(com.android.launcher3.widget.picker.WidgetsDiffReporter) Iterator(java.util.Iterator) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) ComponentName(android.content.ComponentName) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) LauncherAppState(com.android.launcher3.LauncherAppState) Collection(java.util.Collection) PackageUserKey(com.android.launcher3.util.PackageUserKey) WIDGET_FEATURE_HIDE_FROM_PICKER(android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_HIDE_FROM_PICKER) Set(java.util.Set) FeatureFlags(com.android.launcher3.config.FeatureFlags) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) IntSet(com.android.launcher3.util.IntSet) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) WidgetSections(com.android.launcher3.widget.WidgetSections) Entry(java.util.Map.Entry) IconCache(com.android.launcher3.icons.IconCache) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) Pair(android.util.Pair)

Example 42 with PackageItemInfo

use of com.android.launcher3.model.data.PackageItemInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetsDiffReporterTest method createWidgetsContentEntry.

private WidgetsListContentEntry createWidgetsContentEntry(String packageName, String appName, int numOfWidgets) {
    List<WidgetItem> widgetItems = generateWidgetItems(packageName, numOfWidgets);
    PackageItemInfo pInfo = createPackageItemInfo(packageName, appName, widgetItems.get(0).user);
    return new WidgetsListContentEntry(pInfo, /* titleSectionName= */
    "", widgetItems);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 43 with PackageItemInfo

use of com.android.launcher3.model.data.PackageItemInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetsDiffReporterTest method createWidgetsHeaderEntry.

private WidgetsListHeaderEntry createWidgetsHeaderEntry(String packageName, String appName, int numOfWidgets) {
    List<WidgetItem> widgetItems = generateWidgetItems(packageName, numOfWidgets);
    PackageItemInfo pInfo = createPackageItemInfo(packageName, appName, widgetItems.get(0).user);
    return new WidgetsListHeaderEntry(pInfo, /* titleSectionName= */
    "", widgetItems);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 44 with PackageItemInfo

use of com.android.launcher3.model.data.PackageItemInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetsListAdapterTest method generateSampleMap.

/**
 * Generates a list of sample widget entries.
 *
 * <p>Each sample app has 1 widget only. An app is represented by 2 entries,
 * {@link WidgetsListHeaderEntry} & {@link WidgetsListContentEntry}. Only
 * {@link WidgetsListHeaderEntry} is always visible in the {@link WidgetsListAdapter}.
 * {@link WidgetsListContentEntry} is only shown upon clicking the corresponding app's
 * {@link WidgetsListHeaderEntry}. Only at most one {@link WidgetsListContentEntry} is shown at
 * a time.
 *
 * @param num the number of apps that have widgets.
 */
private ArrayList<WidgetsListBaseEntry> generateSampleMap(int num) {
    ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
    if (num <= 0)
        return result;
    for (int i = 0; i < num; i++) {
        String packageName = TEST_PACKAGE_PLACEHOLDER + i;
        List<WidgetItem> widgetItems = generateWidgetItems(packageName, /* numOfWidgets= */
        1);
        PackageItemInfo pInfo = new PackageItemInfo(packageName, widgetItems.get(0).user);
        pInfo.title = pInfo.packageName;
        pInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
        result.add(new WidgetsListHeaderEntry(pInfo, /* titleSectionName= */
        "", widgetItems));
        result.add(new WidgetsListContentEntry(pInfo, /* titleSectionName= */
        "", widgetItems));
    }
    return result;
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 45 with PackageItemInfo

use of com.android.launcher3.model.data.PackageItemInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetsListTableViewHolderBinderTest method generateSampleAppWithWidgets.

private WidgetsListContentEntry generateSampleAppWithWidgets(String appName, String packageName, int numOfWidgets) {
    PackageItemInfo appInfo = new PackageItemInfo(packageName, UserHandle.CURRENT);
    appInfo.title = appName;
    appInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
    return new WidgetsListContentEntry(appInfo, /* titleSectionName= */
    "", generateWidgetItems(packageName, numOfWidgets), Integer.MAX_VALUE);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry)

Aggregations

PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)94 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)39 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)39 WidgetItem (com.android.launcher3.model.WidgetItem)28 ArrayList (java.util.ArrayList)28 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)24 Map (java.util.Map)22 HashMap (java.util.HashMap)20 ComponentName (android.content.ComponentName)19 List (java.util.List)19 IconCache (com.android.launcher3.icons.IconCache)17 Context (android.content.Context)16 AlphabeticIndexCompat (com.android.launcher3.compat.AlphabeticIndexCompat)16 PackageUserKey (com.android.launcher3.util.PackageUserKey)16 Log (android.util.Log)14 Nullable (androidx.annotation.Nullable)14 ArrayMap (androidx.collection.ArrayMap)14 ShortcutConfigActivityInfo.queryList (com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList)14 Arrays (java.util.Arrays)14 Predicate (java.util.function.Predicate)14