use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class PredictionUpdateTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
Context context = app.getContext();
// TODO: remove this
Utilities.getDevicePrefs(context).edit().putBoolean(LAST_PREDICTION_ENABLED_STATE, !mTargets.isEmpty()).apply();
FixedContainerItems fci = mPredictorState.items;
Set<UserHandle> usersForChangedShortcuts = new HashSet<>(fci.items.stream().filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT).map(info -> info.user).collect(Collectors.toSet()));
fci.items.clear();
for (AppTarget target : mTargets) {
WorkspaceItemInfo itemInfo;
ShortcutInfo si = target.getShortcutInfo();
if (si != null) {
usersForChangedShortcuts.add(si.getUserHandle());
itemInfo = new WorkspaceItemInfo(si, context);
app.getIconCache().getShortcutIcon(itemInfo, si);
} else {
String className = target.getClassName();
if (COMPONENT_CLASS_MARKER.equals(className)) {
// TODO: Implement this
continue;
}
ComponentName cn = new ComponentName(target.getPackageName(), className);
UserHandle user = target.getUser();
itemInfo = apps.data.stream().filter(info -> user.equals(info.user) && cn.equals(info.componentName)).map(ai -> {
app.getIconCache().getTitleAndIcon(ai, false);
return ai.makeWorkspaceItem();
}).findAny().orElseGet(() -> {
LauncherActivityInfo lai = context.getSystemService(LauncherApps.class).resolveActivity(AppInfo.makeLaunchIntent(cn), user);
if (lai == null) {
return null;
}
AppInfo ai = new AppInfo(context, lai, user);
app.getIconCache().getTitleAndIcon(ai, lai, false);
return ai.makeWorkspaceItem();
});
if (itemInfo == null) {
continue;
}
}
itemInfo.container = fci.containerId;
fci.items.add(itemInfo);
}
bindExtraContainerItems(fci);
usersForChangedShortcuts.forEach(u -> dataModel.updateShortcutPinnedState(app.getContext(), u));
// Save to disk
mPredictorState.storage.write(context, fci.items);
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
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;
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
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.
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
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;
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class AddWorkspaceItemsTaskTest method writeWorkspaceWithHoles.
private int writeWorkspaceWithHoles(BgDataModel bgDataModel, int startId, int screenId, Rect... holes) {
GridOccupancy occupancy = new GridOccupancy(mIdp.numColumns, mIdp.numRows);
occupancy.markCells(0, 0, mIdp.numColumns, mIdp.numRows, true);
for (Rect r : holes) {
occupancy.markCells(r, false);
}
mExistingScreens.add(screenId);
mScreenOccupancy.append(screenId, occupancy);
for (int x = 0; x < mIdp.numColumns; x++) {
for (int y = 0; y < mIdp.numRows; y++) {
if (!occupancy.cells[x][y]) {
continue;
}
WorkspaceItemInfo info = new WorkspaceItemInfo();
info.intent = new Intent().setComponent(mComponent1);
info.id = startId++;
info.screenId = screenId;
info.cellX = x;
info.cellY = y;
info.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
bgDataModel.addItem(mTargetContext, info, false);
ContentWriter writer = new ContentWriter(mTargetContext);
info.writeToValues(writer);
writer.put(Favorites._ID, info.id);
mTargetContext.getContentResolver().insert(Favorites.CONTENT_URI, writer.getValues(mTargetContext));
}
}
return startId;
}
Aggregations