use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by crdroidandroid.
the class ModelWriter method addItemToDatabase.
/**
* Add an item to the database in a specified container. Sets the container, screen, cellX and
* cellY fields of the item. Also assigns an ID to the item.
*/
public void addItemToDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY) {
updateItemInfoProps(item, container, screenId, cellX, cellY);
final ContentResolver cr = mContext.getContentResolver();
item.id = Settings.call(cr, Settings.METHOD_NEW_ITEM_ID).getInt(Settings.EXTRA_VALUE);
ModelVerifier verifier = new ModelVerifier();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
((Executor) MODEL_EXECUTOR).execute(() -> {
// Write the item on background thread, as some properties might have been updated in
// the background.
final ContentWriter writer = new ContentWriter(mContext);
item.onAddToDatabase(writer);
writer.put(Favorites._ID, item.id);
cr.insert(Favorites.CONTENT_URI, writer.getValues(mContext));
synchronized (mBgDataModel) {
checkItemInfoLocked(item.id, item, stackTrace);
mBgDataModel.addItem(mContext, item, true);
verifier.verifyModel();
}
});
}
use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetUtils method addItemToScreen.
/**
* Adds {@param item} on the homescreen on the 0th screen
*/
public static void addItemToScreen(ItemInfo item, Context targetContext) {
ContentResolver resolver = targetContext.getContentResolver();
int screenId = FIRST_SCREEN_ID;
// Update the screen id counter for the provider.
LauncherSettings.Settings.call(resolver, LauncherSettings.Settings.METHOD_NEW_SCREEN_ID);
if (screenId > FIRST_SCREEN_ID) {
screenId = FIRST_SCREEN_ID;
}
// Insert the item
ContentWriter writer = new ContentWriter(targetContext);
item.id = LauncherSettings.Settings.call(resolver, LauncherSettings.Settings.METHOD_NEW_ITEM_ID).getInt(LauncherSettings.Settings.EXTRA_VALUE);
item.screenId = screenId;
item.onAddToDatabase(writer);
writer.put(LauncherSettings.Favorites._ID, item.id);
resolver.insert(LauncherSettings.Favorites.CONTENT_URI, writer.getValues(targetContext));
}
use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by AOSPA.
the class ModelWriter method updateItemInDatabase.
/**
* Update an item to the database in a specified container.
*/
public void updateItemInDatabase(ItemInfo item) {
notifyItemModified(item);
MODEL_EXECUTOR.execute(new UpdateItemRunnable(item, () -> {
ContentWriter writer = new ContentWriter(mContext);
item.onAddToDatabase(writer);
return writer;
}));
}
use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Trebuchet by LineageOS.
the class WidgetUtils method addItemToScreen.
/**
* Adds {@param item} on the homescreen on the 0th screen
*/
public static void addItemToScreen(ItemInfo item, Context targetContext) {
ContentResolver resolver = targetContext.getContentResolver();
int screenId = FIRST_SCREEN_ID;
// Update the screen id counter for the provider.
LauncherSettings.Settings.call(resolver, LauncherSettings.Settings.METHOD_NEW_SCREEN_ID);
if (screenId > FIRST_SCREEN_ID) {
screenId = FIRST_SCREEN_ID;
}
// Insert the item
ContentWriter writer = new ContentWriter(targetContext);
item.id = LauncherSettings.Settings.call(resolver, LauncherSettings.Settings.METHOD_NEW_ITEM_ID).getInt(LauncherSettings.Settings.EXTRA_VALUE);
item.screenId = screenId;
item.onAddToDatabase(writer);
writer.put(LauncherSettings.Favorites._ID, item.id);
resolver.insert(LauncherSettings.Favorites.CONTENT_URI, writer.getValues(targetContext));
}
use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Trebuchet by LineageOS.
the class AppWidgetsRestoredReceiver method restoreAppWidgetIds.
/**
* Updates the app widgets whose id has changed during the restore process.
*/
@WorkerThread
public static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds) {
AppWidgetHost appWidgetHost = new LauncherAppWidgetHost(context);
if (WidgetsModel.GO_DISABLE_WIDGETS) {
Log.e(TAG, "Skipping widget ID remap as widgets not supported");
appWidgetHost.deleteHost();
return;
}
if (!RestoreDbTask.isPending(context)) {
// Someone has already gone through our DB once, probably LoaderTask. Skip any further
// modifications of the DB.
Log.e(TAG, "Skipping widget ID remap as DB already in use");
for (int widgetId : newWidgetIds) {
Log.d(TAG, "Deleting widgetId: " + widgetId);
appWidgetHost.deleteAppWidgetId(widgetId);
}
return;
}
final ContentResolver cr = context.getContentResolver();
final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
for (int i = 0; i < oldWidgetIds.length; i++) {
Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);
final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
final int state;
if (LoaderTask.isValidProvider(provider)) {
// This will ensure that we show 'Click to setup' UI if required.
state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
} else {
state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
}
// b/135926478: Work profile widget restore is broken in platform. This forces us to
// recreate the widget during loading with the correct host provider.
long mainProfileId = UserCache.INSTANCE.get(context).getSerialNumberForUser(myUserHandle());
String oldWidgetId = Integer.toString(oldWidgetIds[i]);
int result = new ContentWriter(context, new ContentWriter.CommitParams("appWidgetId=? and (restored & 1) = 1 and profileId=?", new String[] { oldWidgetId, Long.toString(mainProfileId) })).put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]).put(LauncherSettings.Favorites.RESTORED, state).commit();
if (result == 0) {
Cursor cursor = cr.query(Favorites.CONTENT_URI, new String[] { Favorites.APPWIDGET_ID }, "appWidgetId=?", new String[] { oldWidgetId }, null);
try {
if (!cursor.moveToFirst()) {
// The widget no long exists.
appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);
}
} finally {
cursor.close();
}
}
}
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
if (app != null) {
app.getModel().forceReload();
}
}
Aggregations