Search in sources :

Example 1 with BaseModelUpdateTask

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

the class PredictionModel method cachePredictionComponentKeys.

/**
 * Formats and stores a list of component key in device preferences.
 */
@AnyThread
public void cachePredictionComponentKeys(List<ComponentKey> componentKeys) {
    MODEL_EXECUTOR.execute(() -> {
        LauncherAppState appState = LauncherAppState.getInstance(mContext);
        StringBuilder builder = new StringBuilder();
        int count = Math.min(componentKeys.size(), MAX_CACHE_ITEMS);
        for (int i = 0; i < count; i++) {
            builder.append(serializeComponentKeyToString(componentKeys.get(i)));
            builder.append("\n");
        }
        if (componentKeys.isEmpty()) /* should invalidate loader items */
        {
            appState.getModel().enqueueModelUpdateTask(new BaseModelUpdateTask() {

                @Override
                public void execute(LauncherAppState app, BgDataModel model, AllAppsList apps) {
                    model.cachedPredictedItems.clear();
                }
            });
        }
        mDevicePrefs.edit().putString(CACHED_ITEMS_KEY, builder.toString()).apply();
    });
}
Also used : LauncherAppState(com.android.launcher3.LauncherAppState) ResourceBasedOverride(com.android.launcher3.util.ResourceBasedOverride) AnyThread(androidx.annotation.AnyThread)

Example 2 with BaseModelUpdateTask

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

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 3 with BaseModelUpdateTask

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

the class HotseatPredictionModel method createBundle.

/**
 * Creates and returns bundle using workspace items and cached items
 */
public void createBundle(Consumer<Bundle> cb) {
    LauncherAppState appState = LauncherAppState.getInstance(mContext);
    appState.getModel().enqueueModelUpdateTask(new BaseModelUpdateTask() {

        @Override
        public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
            Bundle bundle = new Bundle();
            ArrayList<AppTargetEvent> events = new ArrayList<>();
            ArrayList<ItemInfo> workspaceItems = new ArrayList<>(dataModel.workspaceItems);
            workspaceItems.addAll(dataModel.appWidgets);
            for (ItemInfo item : workspaceItems) {
                AppTarget target = getAppTargetFromInfo(item);
                if (target != null && !isTrackedForPrediction(item))
                    continue;
                events.add(wrapAppTargetWithLocation(target, AppTargetEvent.ACTION_PIN, item));
            }
            ArrayList<AppTarget> currentTargets = new ArrayList<>();
            for (ItemInfo itemInfo : dataModel.cachedPredictedItems) {
                AppTarget target = getAppTargetFromInfo(itemInfo);
                if (target != null)
                    currentTargets.add(target);
            }
            bundle.putParcelableArrayList(BUNDLE_KEY_PIN_EVENTS, events);
            bundle.putParcelableArrayList(BUNDLE_KEY_CURRENT_ITEMS, currentTargets);
            MAIN_EXECUTOR.execute(() -> cb.accept(bundle));
        }
    });
}
Also used : BaseModelUpdateTask(com.android.launcher3.model.BaseModelUpdateTask) AppTarget(android.app.prediction.AppTarget) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) Bundle(android.os.Bundle) AllAppsList(com.android.launcher3.model.AllAppsList) ArrayList(java.util.ArrayList)

Example 4 with BaseModelUpdateTask

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

use of com.android.launcher3.model.BaseModelUpdateTask in project android_packages_apps_Launcher3 by ArrowOS.

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)

Aggregations

LauncherAppState (com.android.launcher3.LauncherAppState)6 AllAppsList (com.android.launcher3.model.AllAppsList)5 BaseModelUpdateTask (com.android.launcher3.model.BaseModelUpdateTask)5 BgDataModel (com.android.launcher3.model.BgDataModel)5 LauncherIcons (com.android.launcher3.icons.LauncherIcons)4 AppTarget (android.app.prediction.AppTarget)1 Bundle (android.os.Bundle)1 AnyThread (androidx.annotation.AnyThread)1 ItemInfo (com.android.launcher3.model.data.ItemInfo)1 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)1 ResourceBasedOverride (com.android.launcher3.util.ResourceBasedOverride)1 ArrayList (java.util.ArrayList)1