Search in sources :

Example 71 with PackageItemInfo

use of com.android.launcher3.model.PackageItemInfo in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetsModel method getWidgetsList.

/**
 * Returns a list of {@link WidgetListRowEntry}. All {@link WidgetItem} in a single row
 * are sorted (based on label and user), but the overall list of {@link WidgetListRowEntry}s
 * is not sorted. This list is sorted at the UI when using
 * {@link com.android.launcher3.widget.WidgetsDiffReporter}
 *
 * @see com.android.launcher3.widget.WidgetsListAdapter#setWidgets(ArrayList)
 */
public synchronized ArrayList<WidgetListRowEntry> getWidgetsList(Context context) {
    ArrayList<WidgetListRowEntry> result = new ArrayList<>();
    AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
    WidgetItemComparator widgetComparator = new WidgetItemComparator();
    for (Map.Entry<PackageItemInfo, ArrayList<WidgetItem>> entry : mWidgetsList.entrySet()) {
        WidgetListRowEntry row = new WidgetListRowEntry(entry.getKey(), entry.getValue());
        row.titleSectionName = (row.pkgItem.title == null) ? "" : indexer.computeSectionName(row.pkgItem.title);
        Collections.sort(row.widgets, widgetComparator);
        result.add(row);
    }
    return result;
}
Also used : AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) WidgetItemComparator(com.android.launcher3.widget.WidgetItemComparator) ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetListRowEntry(com.android.launcher3.widget.WidgetListRowEntry) HashMap(java.util.HashMap) Map(java.util.Map) MultiHashMap(com.android.launcher3.util.MultiHashMap)

Example 72 with PackageItemInfo

use of com.android.launcher3.model.PackageItemInfo in project android_packages_apps_Trebuchet by LineageOS.

the class IconCache method getShortcutInfoBadge.

/**
 * Returns the badging info for the shortcut
 */
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
    ComponentName cn = shortcutInfo.getActivity();
    if (cn != null) {
        // Get the app info for the source activity.
        AppInfo appInfo = new AppInfo();
        appInfo.user = shortcutInfo.getUserHandle();
        appInfo.componentName = cn;
        appInfo.intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn);
        getTitleAndIcon(appInfo, false);
        return appInfo.bitmap;
    } else {
        PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
        getTitleAndIconForApp(pkgInfo, false);
        return pkgInfo.bitmap;
    }
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 73 with PackageItemInfo

use of com.android.launcher3.model.PackageItemInfo in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetsListAdapterTest method generateSampleMap.

/**
 * Helper method to generate the sample widget model map that can be used for the tests
 * @param num the number of WidgetItem the map should contain
 */
private ArrayList<WidgetListRowEntry> generateSampleMap(int num) {
    ArrayList<WidgetListRowEntry> result = new ArrayList<>();
    if (num <= 0)
        return result;
    ShadowPackageManager spm = shadowOf(mContext.getPackageManager());
    for (int i = 0; i < num; i++) {
        ComponentName cn = new ComponentName("com.dummy.apk" + i, "DummyWidet");
        AppWidgetProviderInfo widgetInfo = new AppWidgetProviderInfo();
        widgetInfo.provider = cn;
        ReflectionHelpers.setField(widgetInfo, "providerInfo", spm.addReceiverIfNotPresent(cn));
        WidgetItem wi = new WidgetItem(LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo), mTestProfile, mIconCache);
        PackageItemInfo pInfo = new PackageItemInfo(wi.componentName.getPackageName());
        pInfo.title = pInfo.packageName;
        pInfo.user = wi.user;
        pInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
        result.add(new WidgetListRowEntry(pInfo, new ArrayList<>(Collections.singleton(wi))));
    }
    return result;
}
Also used : ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 74 with PackageItemInfo

use of com.android.launcher3.model.PackageItemInfo in project android_packages_apps_Launcher3 by AOSPA.

the class SearchActionItemInfo method createWorkspaceItem.

/**
 * Creates a {@link WorkspaceItemInfo} coorsponding to search action to be stored in launcher db
 */
public WorkspaceItemInfo createWorkspaceItem(LauncherModel model) {
    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;
    }
    model.enqueueModelUpdateTask(new BaseModelUpdateTask() {

        @Override
        public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
            model.updateAndBindWorkspaceItem(() -> {
                PackageItemInfo pkgInfo = new PackageItemInfo(getIntentPackageName(), user);
                app.getIconCache().getTitleAndIconForApp(pkgInfo, false);
                try (LauncherIcons li = LauncherIcons.obtain(app.getContext())) {
                    info.bitmap = li.badgeBitmap(info.bitmap.icon, pkgInfo.bitmap);
                }
                return info;
            });
        }
    });
    return info;
}
Also used : BaseModelUpdateTask(com.android.launcher3.model.BaseModelUpdateTask) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) LauncherIcons(com.android.launcher3.icons.LauncherIcons) AllAppsList(com.android.launcher3.model.AllAppsList)

Example 75 with PackageItemInfo

use of com.android.launcher3.model.PackageItemInfo in project android_packages_apps_Launcher3 by AOSPA.

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)

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