Search in sources :

Example 66 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_404Launcher by P-404.

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).distinct().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 67 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_404Launcher by P-404.

the class BgDataModel method updateDeepShortcutCounts.

/**
 * Clear all the deep shortcut counts for the given package, and re-add the new shortcut counts.
 */
public synchronized void updateDeepShortcutCounts(String packageName, UserHandle user, List<ShortcutInfo> shortcuts) {
    if (packageName != null) {
        Iterator<ComponentKey> keysIter = deepShortcutMap.keySet().iterator();
        while (keysIter.hasNext()) {
            ComponentKey next = keysIter.next();
            if (next.componentName.getPackageName().equals(packageName) && next.user.equals(user)) {
                keysIter.remove();
            }
        }
    }
    // Now add the new shortcuts to the map.
    for (ShortcutInfo shortcut : shortcuts) {
        boolean shouldShowInContainer = shortcut.isEnabled() && (shortcut.isDeclaredInManifest() || shortcut.isDynamic()) && shortcut.getActivity() != null;
        if (shouldShowInContainer) {
            ComponentKey targetComponent = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
            Integer previousCount = deepShortcutMap.get(targetComponent);
            deepShortcutMap.put(targetComponent, previousCount == null ? 1 : previousCount + 1);
        }
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentKey(com.android.launcher3.util.ComponentKey)

Example 68 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_404Launcher by P-404.

the class PopupDataProvider method getShortcutCountForItem.

public int getShortcutCountForItem(ItemInfo info) {
    if (!ShortcutUtil.supportsDeepShortcuts(info)) {
        return 0;
    }
    ComponentName component = info.getTargetComponent();
    if (component == null) {
        return 0;
    }
    Integer count = mDeepShortcutMap.get(new ComponentKey(component, info.user));
    return count == null ? 0 : count;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName)

Example 69 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupDataProvider method getRecommendedWidgets.

/**
 * Returns a list of recommended widgets.
 */
public List<WidgetItem> getRecommendedWidgets() {
    HashMap<ComponentKey, WidgetItem> allWidgetItems = new HashMap<>();
    mAllWidgets.stream().filter(entry -> entry instanceof WidgetsListContentEntry).forEach(entry -> ((WidgetsListContentEntry) entry).mWidgets.forEach(widget -> allWidgetItems.put(new ComponentKey(widget.componentName, widget.user), widget)));
    return mRecommendedWidgets.stream().map(recommendedWidget -> allWidgetItems.get(new ComponentKey(recommendedWidget.getTargetComponent(), recommendedWidget.user))).filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) HashMap(java.util.HashMap) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) WidgetItem(com.android.launcher3.model.WidgetItem) Map(java.util.Map) Log(android.util.Log) PrintWriter(java.io.PrintWriter) ComponentName(android.content.ComponentName) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) PackageUserKey(com.android.launcher3.util.PackageUserKey) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) NotificationListener(com.android.launcher3.notification.NotificationListener) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) ComponentKey(com.android.launcher3.util.ComponentKey) Collections(java.util.Collections) StatusBarNotification(android.service.notification.StatusBarNotification) DotInfo(com.android.launcher3.dot.DotInfo) HashMap(java.util.HashMap) ComponentKey(com.android.launcher3.util.ComponentKey) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 70 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupDataProvider method getShortcutCountForItem.

public int getShortcutCountForItem(ItemInfo info) {
    if (!ShortcutUtil.supportsDeepShortcuts(info)) {
        return 0;
    }
    ComponentName component = info.getTargetComponent();
    if (component == null) {
        return 0;
    }
    Integer count = mDeepShortcutMap.get(new ComponentKey(component, info.user));
    return count == null ? 0 : count;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName)

Aggregations

ComponentKey (com.android.launcher3.util.ComponentKey)98 ComponentName (android.content.ComponentName)40 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 ArrayList (java.util.ArrayList)26 ShortcutInfo (android.content.pm.ShortcutInfo)21 UserHandle (android.os.UserHandle)20 HashMap (java.util.HashMap)19 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)17 PackageUserKey (com.android.launcher3.util.PackageUserKey)17 Intent (android.content.Intent)16 HashSet (java.util.HashSet)16 Context (android.content.Context)15 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 List (java.util.List)13 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)11 AppTarget (android.app.prediction.AppTarget)10 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)10 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)10 QueryResult (com.android.launcher3.shortcuts.ShortcutRequest.QueryResult)10