use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by crdroidandroid.
the class ShortcutsChangedTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
final Context context = app.getContext();
// Find WorkspaceItemInfo's that have changed on the workspace.
ArrayList<WorkspaceItemInfo> matchingWorkspaceItems = new ArrayList<>();
synchronized (dataModel) {
dataModel.forAllWorkspaceItemInfos(mUser, si -> {
if ((si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) && mPackageName.equals(si.getIntent().getPackage())) {
matchingWorkspaceItems.add(si);
}
});
}
if (!matchingWorkspaceItems.isEmpty()) {
if (mShortcuts.isEmpty()) {
// Verify that the app is indeed installed.
if (!new PackageManagerHelper(app.getContext()).isAppInstalled(mPackageName, mUser)) {
// App is not installed, ignoring package events
return;
}
}
// Update the workspace to reflect the changes to updated shortcuts residing on it.
List<String> allLauncherKnownIds = matchingWorkspaceItems.stream().map(WorkspaceItemInfo::getDeepShortcutId).distinct().collect(Collectors.toList());
List<ShortcutInfo> shortcuts = new ShortcutRequest(context, mUser).forPackage(mPackageName, allLauncherKnownIds).query(ShortcutRequest.ALL);
Set<String> nonPinnedIds = new HashSet<>(allLauncherKnownIds);
ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
for (ShortcutInfo fullDetails : shortcuts) {
if (!fullDetails.isPinned()) {
continue;
}
String sid = fullDetails.getId();
nonPinnedIds.remove(sid);
matchingWorkspaceItems.stream().filter(itemInfo -> sid.equals(itemInfo.getDeepShortcutId())).forEach(workspaceItemInfo -> {
workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context);
app.getIconCache().getShortcutIcon(workspaceItemInfo, fullDetails);
updatedWorkspaceItemInfos.add(workspaceItemInfo);
});
}
bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
if (!nonPinnedIds.isEmpty()) {
deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(nonPinnedIds.stream().map(id -> new ShortcutKey(mPackageName, mUser, id)).collect(Collectors.toSet())));
}
}
if (mUpdateIdMap) {
// Update the deep shortcut map if the list of ids has changed for an activity.
dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts);
bindDeepShortcuts(dataModel);
}
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by crdroidandroid.
the class PreviewSurfaceRenderer method loadModelData.
@WorkerThread
private void loadModelData() {
final boolean migrated = doGridMigrationIfNecessary();
final Context inflationContext;
if (mWallpaperColors != null) {
// Create a themed context, without affecting the main application context
Context context = mContext.createDisplayContext(mDisplay);
if (Utilities.ATLEAST_R) {
context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
}
LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
} else {
inflationContext = new ContextThemeWrapper(mContext, R.style.AppTheme);
}
if (migrated) {
PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {
@Override
public void run() {
loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, LauncherSettings.Favorites.SCREEN + " = 0 or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT);
MAIN_EXECUTOR.execute(() -> {
renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
mOnDestroyCallbacks.add(previewContext::onDestroy);
});
}
}.run();
} else {
LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
if (dataModel != null) {
MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
} else {
Log.e(TAG, "Model loading failed");
}
});
}
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by crdroidandroid.
the class AddWorkspaceItemsTask method shortcutExists.
/**
* Returns true if the shortcuts already exists on the workspace. This must be called after
* the workspace has been loaded. We identify a shortcut by its intent.
*/
protected boolean shortcutExists(BgDataModel dataModel, Intent intent, UserHandle user) {
final String compPkgName, intentWithPkg, intentWithoutPkg;
if (intent == null) {
// Skip items with null intents
return true;
}
if (intent.getComponent() != null) {
// If component is not null, an intent with null package will produce
// the same result and should also be a match.
compPkgName = intent.getComponent().getPackageName();
if (intent.getPackage() != null) {
intentWithPkg = intent.toUri(0);
intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
} else {
intentWithPkg = new Intent(intent).setPackage(compPkgName).toUri(0);
intentWithoutPkg = intent.toUri(0);
}
} else {
compPkgName = null;
intentWithPkg = intent.toUri(0);
intentWithoutPkg = intent.toUri(0);
}
boolean isLauncherAppTarget = PackageManagerHelper.isLauncherAppTarget(intent);
synchronized (dataModel) {
for (ItemInfo item : dataModel.itemsIdMap) {
if (item instanceof WorkspaceItemInfo) {
WorkspaceItemInfo info = (WorkspaceItemInfo) item;
if (item.getIntent() != null && info.user.equals(user)) {
Intent copyIntent = new Intent(item.getIntent());
copyIntent.setSourceBounds(intent.getSourceBounds());
String s = copyIntent.toUri(0);
if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
return true;
}
// checking for existing promise icon with same package name
if (isLauncherAppTarget && info.isPromise() && info.hasStatusFlag(WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON) && info.getTargetComponent() != null && compPkgName != null && compPkgName.equals(info.getTargetComponent().getPackageName())) {
return true;
}
}
}
}
}
return false;
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by crdroidandroid.
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();
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by crdroidandroid.
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