use of com.android.launcher3.model.BgDataModel 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;
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class LauncherModelHelper method executeTaskForTest.
/**
* Synchronously executes the task and returns all the UI callbacks posted.
*/
public List<Runnable> executeTaskForTest(ModelUpdateTask task) throws Exception {
LauncherModel model = getModel();
if (!model.isModelLoaded()) {
ReflectionHelpers.setField(model, "mModelLoaded", true);
}
Executor mockExecutor = mock(Executor.class);
model.enqueueModelUpdateTask(new ModelUpdateTask() {
@Override
public void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, AllAppsList allAppsList, Executor uiExecutor) {
task.init(app, model, dataModel, allAppsList, mockExecutor);
}
@Override
public void run() {
task.run();
}
});
MODEL_EXECUTOR.submit(() -> null).get();
ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
verify(mockExecutor, atLeast(0)).execute(captor.capture());
return captor.getAllValues();
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
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 ArrowOS.
the class AddWorkspaceItemsTask method findSpaceForItem.
/**
* Find a position on the screen for the given size or adds a new screen.
* @return screenId and the coordinates for the item in an int array of size 3.
*/
protected int[] findSpaceForItem(LauncherAppState app, BgDataModel dataModel, IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
// Use sBgItemsIdMap as all the items are already loaded.
synchronized (dataModel) {
for (ItemInfo info : dataModel.itemsIdMap) {
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
ArrayList<ItemInfo> items = screenItems.get(info.screenId);
if (items == null) {
items = new ArrayList<>();
screenItems.put(info.screenId, items);
}
items.add(info);
}
}
}
// Find appropriate space for the item.
int screenId = 0;
int[] coordinates = new int[2];
boolean found = false;
int screenCount = workspaceScreens.size();
// First check the preferred screen.
IntSet screensToExclude = new IntSet();
if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
screensToExclude.add(FIRST_SCREEN_ID);
}
for (int screen = 0; screen < screenCount; screen++) {
screenId = workspaceScreens.get(screen);
if (!screensToExclude.contains(screenId) && findNextAvailableIconSpaceInScreen(app, screenItems.get(screenId), coordinates, spanX, spanY)) {
// We found a space for it
found = true;
break;
}
}
if (!found) {
// Still no position found. Add a new screen to the end.
screenId = LauncherSettings.Settings.call(app.getContext().getContentResolver(), LauncherSettings.Settings.METHOD_NEW_SCREEN_ID).getInt(LauncherSettings.Settings.EXTRA_VALUE);
// Save the screen id for binding in the workspace
workspaceScreens.add(screenId);
addedWorkspaceScreensFinal.add(screenId);
// If we still can't find an empty space, then God help us all!!!
if (!findNextAvailableIconSpaceInScreen(app, screenItems.get(screenId), coordinates, spanX, spanY)) {
throw new RuntimeException("Can't find space to add the item");
}
}
return new int[] { screenId, coordinates[0], coordinates[1] };
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
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;
}
Aggregations