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();
});
}
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;
}
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));
}
});
}
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;
}
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;
}
Aggregations