Search in sources :

Example 56 with BgDataModel

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

the class HotseatPredictionModel method convertDataModelToAppTargetBundle.

/**
 * Creates and returns bundle using workspace items
 */
public static Bundle convertDataModelToAppTargetBundle(Context context, BgDataModel dataModel) {
    Bundle bundle = new Bundle();
    ArrayList<AppTargetEvent> events = new ArrayList<>();
    ArrayList<ItemInfo> workspaceItems = dataModel.getAllWorkspaceItems();
    for (ItemInfo item : workspaceItems) {
        AppTarget target = getAppTargetFromItemInfo(context, item);
        if (target != null && !isTrackedForHotseatPrediction(item))
            continue;
        events.add(wrapAppTargetWithItemLocation(target, AppTargetEvent.ACTION_PIN, item));
    }
    ArrayList<AppTarget> currentTargets = new ArrayList<>();
    FixedContainerItems hotseatItems = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
    if (hotseatItems != null) {
        for (ItemInfo itemInfo : hotseatItems.items) {
            AppTarget target = getAppTargetFromItemInfo(context, itemInfo);
            if (target != null)
                currentTargets.add(target);
        }
    }
    bundle.putParcelableArrayList(BUNDLE_KEY_PIN_EVENTS, events);
    bundle.putParcelableArrayList(BUNDLE_KEY_CURRENT_ITEMS, currentTargets);
    return bundle;
}
Also used : AppTarget(android.app.prediction.AppTarget) PredictionHelper.getAppTargetFromItemInfo(com.android.launcher3.model.PredictionHelper.getAppTargetFromItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTargetEvent(android.app.prediction.AppTargetEvent)

Example 57 with BgDataModel

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

the class QuickstepModelDelegate method getBundleForWidgetsOnWorkspace.

private Bundle getBundleForWidgetsOnWorkspace(Context context, BgDataModel dataModel) {
    Bundle bundle = new Bundle();
    ArrayList<AppTargetEvent> widgetEvents = dataModel.getAllWorkspaceItems().stream().filter(PredictionHelper::isTrackedForWidgetPrediction).map(item -> {
        AppTarget target = getAppTargetFromItemInfo(context, item);
        if (target == null)
            return null;
        return wrapAppTargetWithItemLocation(target, AppTargetEvent.ACTION_PIN, item);
    }).filter(Objects::nonNull).collect(toCollection(ArrayList::new));
    bundle.putParcelableArrayList(BUNDLE_KEY_ADDED_APP_WIDGETS, widgetEvents);
    return bundle;
}
Also used : AppTarget(android.app.prediction.AppTarget) Bundle(android.os.Bundle) HotseatPredictionModel.convertDataModelToAppTargetBundle(com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle) AppTargetEvent(android.app.prediction.AppTargetEvent)

Example 58 with BgDataModel

use of com.android.launcher3.model.BgDataModel 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 59 with BgDataModel

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

the class CacheDataUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    IconCache iconCache = app.getIconCache();
    ArrayList<WorkspaceItemInfo> updatedShortcuts = new ArrayList<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            ComponentName cn = si.getTargetComponent();
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && isValidShortcut(si) && cn != null && mPackages.contains(cn.getPackageName())) {
                iconCache.getTitleAndIcon(si, si.usingLowResIcon());
                updatedShortcuts.add(si);
            }
        });
        apps.updateIconsAndLabels(mPackages, mUser);
    }
    bindUpdatedWorkspaceItems(updatedShortcuts);
    bindApplicationsIfNeeded();
}
Also used : IconCache(com.android.launcher3.icons.IconCache) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 60 with BgDataModel

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

the class PackageInstallStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
        try {
            // For instant apps we do not get package-add. Use setting events to update
            // any pinned icons.
            ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
            if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
                app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
            }
        } catch (PackageManager.NameNotFoundException e) {
        // Ignore
        }
        // Ignore install success events as they are handled by Package add events.
        return;
    }
    synchronized (apps) {
        List<AppInfo> updatedAppInfos = apps.updatePromiseInstallInfo(mInstallInfo);
        if (!updatedAppInfos.isEmpty()) {
            for (AppInfo appInfo : updatedAppInfos) {
                scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
            }
        }
        bindApplicationsIfNeeded();
    }
    synchronized (dataModel) {
        final HashSet<ItemInfo> updates = new HashSet<>();
        dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
            if (si.hasPromiseIconUi() && mInstallInfo.packageName.equals(si.getTargetPackage())) {
                si.setProgressLevel(mInstallInfo);
                updates.add(si);
            }
        });
        for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
            if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
                widget.installProgress = mInstallInfo.progress;
                updates.add(widget);
            }
        }
        if (!updates.isEmpty()) {
            scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ItemInfo(com.android.launcher3.model.data.ItemInfo) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AppInfo(com.android.launcher3.model.data.AppInfo) HashSet(java.util.HashSet)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)66 ArrayList (java.util.ArrayList)63 ItemInfo (com.android.launcher3.model.data.ItemInfo)45 Context (android.content.Context)33 HashSet (java.util.HashSet)33 LauncherAppState (com.android.launcher3.LauncherAppState)28 AppInfo (com.android.launcher3.model.data.AppInfo)27 ComponentName (android.content.ComponentName)26 ShortcutInfo (android.content.pm.ShortcutInfo)26 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)23 BgDataModel (com.android.launcher3.model.BgDataModel)22 AppTarget (android.app.prediction.AppTarget)20 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)20 List (java.util.List)20 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)18 HashMap (java.util.HashMap)18 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)17 LauncherApps (android.content.pm.LauncherApps)17 AllAppsList (com.android.launcher3.model.AllAppsList)17 Set (java.util.Set)15