Search in sources :

Example 26 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by crdroidandroid.

the class ModelWriter method moveItemInDatabase.

/**
 * Move an item in the DB to a new <container, screen, cellX, cellY>
 */
public void moveItemInDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY) {
    updateItemInfoProps(item, container, screenId, cellX, cellY);
    enqueueDeleteRunnable(new UpdateItemRunnable(item, () -> new ContentWriter(mContext).put(Favorites.CONTAINER, item.container).put(Favorites.CELLX, item.cellX).put(Favorites.CELLY, item.cellY).put(Favorites.RANK, item.rank).put(Favorites.SCREEN, item.screenId)));
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter)

Example 27 with ContentWriter

use of com.android.launcher3.util.ContentWriter 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;
}
Also used : Rect(android.graphics.Rect) ContentWriter(com.android.launcher3.util.ContentWriter) Intent(android.content.Intent) GridOccupancy(com.android.launcher3.util.GridOccupancy) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 28 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by crdroidandroid.

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]);
        final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?";
        final String[] args = new String[] { oldWidgetId, Long.toString(mainProfileId) };
        int result = new ContentWriter(context, new ContentWriter.CommitParams(where, args)).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();
            }
        }
        // attempt to update widget id in backup table as well
        new ContentWriter(context, ContentWriter.CommitParams.backupCommitParams("appWidgetId=? and profileId=?", args)).put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]).put(LauncherSettings.Favorites.RESTORED, state).commit();
    }
    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.getModel().forceReload();
    }
}
Also used : AppWidgetHost(android.appwidget.AppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) AppWidgetManager(android.appwidget.AppWidgetManager) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) ContentWriter(com.android.launcher3.util.ContentWriter) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 29 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project Neo-Launcher by NeoApplications.

the class AddWorkspaceItemsTaskTest method setupWorkspaceWithHoles.

private int setupWorkspaceWithHoles(int startId, int screenId, Rect... holes) throws Exception {
    GridOccupancy occupancy = new GridOccupancy(idp.numColumns, idp.numRows);
    occupancy.markCells(0, 0, idp.numColumns, idp.numRows, true);
    for (Rect r : holes) {
        occupancy.markCells(r, false);
    }
    existingScreens.add(screenId);
    screenOccupancy.append(screenId, occupancy);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    for (int x = 0; x < idp.numColumns; x++) {
        for (int y = 0; y < idp.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(targetContext, info, false);
            executor.execute(() -> {
                ContentWriter writer = new ContentWriter(targetContext);
                info.writeToValues(writer);
                writer.put(Favorites._ID, info.id);
                targetContext.getContentResolver().insert(Favorites.CONTENT_URI, writer.getValues(targetContext));
            });
        }
    }
    executor.submit(() -> null).get();
    executor.shutdown();
    return startId;
}
Also used : Rect(android.graphics.Rect) ContentWriter(com.android.launcher3.util.ContentWriter) ExecutorService(java.util.concurrent.ExecutorService) Intent(android.content.Intent) GridOccupancy(com.android.launcher3.util.GridOccupancy) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 30 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project Neo-Launcher by NeoApplications.

the class ModelWriter method moveItemInDatabase.

/**
 * Move an item in the DB to a new <container, screen, cellX, cellY>
 */
public void moveItemInDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY) {
    updateItemInfoProps(item, container, screenId, cellX, cellY);
    enqueueDeleteRunnable(new UpdateItemRunnable(item, () -> new ContentWriter(mContext).put(Favorites.CONTAINER, item.container).put(Favorites.CELLX, item.cellX).put(Favorites.CELLY, item.cellY).put(Favorites.RANK, item.rank).put(Favorites.SCREEN, item.screenId)));
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter)

Aggregations

ContentWriter (com.android.launcher3.util.ContentWriter)43 ContentResolver (android.content.ContentResolver)16 AppWidgetHost (android.appwidget.AppWidgetHost)7 AppWidgetManager (android.appwidget.AppWidgetManager)7 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)7 Intent (android.content.Intent)7 Cursor (android.database.Cursor)7 Rect (android.graphics.Rect)7 WorkerThread (androidx.annotation.WorkerThread)7 GridOccupancy (com.android.launcher3.util.GridOccupancy)7 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)6 Executor (java.util.concurrent.Executor)6 LauncherAppWidgetHost (com.android.launcher3.widget.LauncherAppWidgetHost)5 WorkspaceItemInfo (com.android.launcher3.WorkspaceItemInfo)1 ExecutorService (java.util.concurrent.ExecutorService)1