Search in sources :

Example 1 with CONTAINER_WIDGETS_PREDICTION

use of com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION 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 CONTAINER_WIDGETS_PREDICTION

use of com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsRecommendationTableLayout method addItemCell.

private WidgetCell addItemCell(ViewGroup parent) {
    WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate(R.layout.widget_cell, parent, false);
    widget.setOnTouchListener(mWidgetCellOnTouchListener);
    View previewContainer = widget.findViewById(R.id.widget_preview_container);
    previewContainer.setOnClickListener(mWidgetCellOnClickListener);
    previewContainer.setOnLongClickListener(mWidgetCellOnLongClickListener);
    widget.setAnimatePreview(false);
    widget.setSourceContainer(CONTAINER_WIDGETS_PREDICTION);
    parent.addView(widget);
    return widget;
}
Also used : WidgetCell(com.android.launcher3.widget.WidgetCell) View(android.view.View)

Aggregations

AppTarget (android.app.prediction.AppTarget)1 ComponentName (android.content.ComponentName)1 TextUtils (android.text.TextUtils)1 View (android.view.View)1 LauncherAppState (com.android.launcher3.LauncherAppState)1 CONTAINER_WIDGETS_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION)1 FeatureFlags (com.android.launcher3.config.FeatureFlags)1 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)1 PredictorState (com.android.launcher3.model.QuickstepModelDelegate.PredictorState)1 ComponentKey (com.android.launcher3.util.ComponentKey)1 PackageUserKey (com.android.launcher3.util.PackageUserKey)1 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)1 WidgetCell (com.android.launcher3.widget.WidgetCell)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1