Search in sources :

Example 1 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsPredictionUpdateTask method execute.

/**
 * Uses the app predication result to infer widgets that the user may want to use.
 *
 * <p>The algorithm uses the app prediction ranking to create a widgets ranking which only
 * includes one widget per app and excludes widgets that have already been added to the
 * workspace.
 */
@Override
public void execute(LauncherAppState appState, BgDataModel dataModel, AllAppsList apps) {
    Set<ComponentKey> widgetsInWorkspace = dataModel.appWidgets.stream().map(widget -> new ComponentKey(widget.providerName, widget.user)).collect(Collectors.toSet());
    Map<PackageUserKey, List<WidgetItem>> allWidgets = dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();
    FixedContainerItems fixedContainerItems = mPredictorState.items;
    fixedContainerItems.items.clear();
    if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
        for (AppTarget app : mTargets) {
            PackageUserKey packageUserKey = new PackageUserKey(app.getPackageName(), app.getUser());
            if (allWidgets.containsKey(packageUserKey)) {
                List<WidgetItem> notAddedWidgets = allWidgets.get(packageUserKey).stream().filter(item -> !widgetsInWorkspace.contains(new ComponentKey(item.componentName, item.user))).collect(Collectors.toList());
                if (notAddedWidgets.size() > 0) {
                    // Even an apps have more than one widgets, we only include one widget.
                    fixedContainerItems.items.add(new PendingAddWidgetInfo(notAddedWidgets.get(0).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
                }
            }
        }
    } else {
        Map<ComponentKey, WidgetItem> widgetItems = allWidgets.values().stream().flatMap(List::stream).collect(Collectors.toMap(widget -> (ComponentKey) widget, widget -> widget));
        for (AppTarget app : mTargets) {
            if (TextUtils.isEmpty(app.getClassName())) {
                continue;
            }
            ComponentKey targetWidget = new ComponentKey(new ComponentName(app.getPackageName(), app.getClassName()), app.getUser());
            if (widgetItems.containsKey(targetWidget)) {
                fixedContainerItems.items.add(new PendingAddWidgetInfo(widgetItems.get(targetWidget).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
            }
        }
    }
    bindExtraContainerItems(fixedContainerItems);
// Don't store widgets prediction to disk because it is not used frequently.
}
Also used : CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) Set(java.util.Set) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) List(java.util.List) ComponentKey(com.android.launcher3.util.ComponentKey) Map(java.util.Map) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ComponentKey(com.android.launcher3.util.ComponentKey) PackageUserKey(com.android.launcher3.util.PackageUserKey) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTarget(android.app.prediction.AppTarget) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) List(java.util.List) ComponentName(android.content.ComponentName)

Example 2 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsListAdapter method ensureAllPreviewsReady.

/**
 * Checks that all preview images are loaded and starts loading for those that aren't ready.
 *
 * @return true if all previews are ready and the data can be updated, false otherwise.
 */
private boolean ensureAllPreviewsReady() {
    boolean allReady = true;
    BaseActivity activity = BaseActivity.fromContext(mContext);
    for (WidgetsListBaseEntry entry : mAllEntries) {
        if (!(entry instanceof WidgetsListContentEntry))
            continue;
        WidgetsListContentEntry contentEntry = (WidgetsListContentEntry) entry;
        if (!matchesKey(entry, mWidgetsContentVisiblePackageUserKey)) {
            // If the entry isn't visible, clear any loaded previews.
            mCachingPreviewLoader.clearPreviews(contentEntry.mWidgets);
            continue;
        }
        for (int i = 0; i < entry.mWidgets.size(); i++) {
            WidgetItem widgetItem = entry.mWidgets.get(i);
            DeviceProfile deviceProfile = activity.getDeviceProfile();
            Size widgetSize = WidgetSizes.getWidgetItemSizePx(mContext, deviceProfile, widgetItem);
            if (widgetItem.isShortcut()) {
                widgetSize = new Size(widgetSize.getWidth() + mShortcutPreviewPadding, widgetSize.getHeight() + mShortcutPreviewPadding);
            }
            if (widgetItem.hasPreviewLayout() || mCachingPreviewLoader.isPreviewLoaded(widgetItem, widgetSize)) {
                // preview bitmap is in the cache.
                continue;
            }
            // If we've reached this point, we should load the preview for the widget.
            allReady = false;
            mCachingPreviewLoader.loadPreview(activity, widgetItem, widgetSize, mPreviewLoadedCallback);
        }
    }
    return allReady;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) BaseActivity(com.android.launcher3.BaseActivity) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 3 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

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(new WidgetPackageOrCategoryKey(packageUser)));
    }
    // add and update.
    mWidgetsList.putAll(rawWidgetsShortcuts.stream().filter(new WidgetValidityCheck(app)).collect(Collectors.groupingBy(item -> packageItemInfoCache.getOrCreate(getWidgetPackageOrCategoryKey(item)))));
    // Update each package entry
    IconCache iconCache = app.getIconCache();
    for (PackageItemInfo p : packageItemInfoCache.values()) {
        iconCache.getTitleAndIconForApp(p, true);
    }
}
Also used : IconCache(com.android.launcher3.icons.IconCache) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo)

Example 4 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsModel method getAllWidgetsWithoutShortcuts.

/**
 * Returns a mapping of packages to their widgets without static shortcuts.
 */
public synchronized Map<PackageUserKey, List<WidgetItem>> getAllWidgetsWithoutShortcuts() {
    Map<PackageUserKey, List<WidgetItem>> packagesToWidgets = new HashMap<>();
    mWidgetsList.forEach((packageItemInfo, widgetsAndShortcuts) -> {
        List<WidgetItem> widgets = widgetsAndShortcuts.stream().filter(item -> item.widgetInfo != null).collect(toList());
        if (widgets.size() > 0) {
            packagesToWidgets.put(new PackageUserKey(packageItemInfo.packageName, packageItemInfo.user), widgets);
        }
    });
    return packagesToWidgets;
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) PackageManager(android.content.pm.PackageManager) AppFilter(com.android.launcher3.AppFilter) 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) UserHandle(android.os.UserHandle) Map(java.util.Map) Log(android.util.Log) ArrayMap(androidx.collection.ArrayMap) TrustDatabaseHelper(com.android.launcher3.lineage.trust.db.TrustDatabaseHelper) ShortcutConfigActivityInfo.queryList(com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList) Utilities(com.android.launcher3.Utilities) WidgetsDiffReporter(com.android.launcher3.widget.picker.WidgetsDiffReporter) 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) Collectors(java.util.stream.Collectors) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) 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) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) PackageUserKey(com.android.launcher3.util.PackageUserKey) ArrayList(java.util.ArrayList) ShortcutConfigActivityInfo.queryList(com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List)

Example 5 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsModel method getWidgetsListForPicker.

/**
 * 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
 * {@link WidgetsDiffReporter}
 *
 * @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(new WidgetsListHeaderEntry(pkgItem, sectionName, widgetItems));
        result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
    }
    return result;
}
Also used : AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ArrayList(java.util.ArrayList) ShortcutConfigActivityInfo.queryList(com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ArrayMap(androidx.collection.ArrayMap) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Aggregations

WidgetItem (com.android.launcher3.model.WidgetItem)37 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)17 ArrayList (java.util.ArrayList)15 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)11 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)10 ComponentName (android.content.ComponentName)9 Test (org.junit.Test)9 ShadowPackageManager (org.robolectric.shadows.ShadowPackageManager)9 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)8 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)7 Size (android.util.Size)6 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)5 TableRow (android.widget.TableRow)4 PackageUserKey (com.android.launcher3.util.PackageUserKey)4 PackageManager (android.content.pm.PackageManager)3 Nullable (androidx.annotation.Nullable)3 DeviceProfile (com.android.launcher3.DeviceProfile)3 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)3