Search in sources :

Example 31 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)

Example 32 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Trebuchet by LineageOS.

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 33 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Trebuchet by LineageOS.

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();
        }
    });
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter) Executor(java.util.concurrent.Executor) ContentResolver(android.content.ContentResolver)

Example 34 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Trebuchet by LineageOS.

the class ModelWriter method modifyItemInDatabase.

/**
 * Move and/or resize item in the DB to a new <container, screen, cellX, cellY, spanX, spanY>
 */
public void modifyItemInDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY, int spanX, int spanY) {
    updateItemInfoProps(item, container, screenId, cellX, cellY);
    item.spanX = spanX;
    item.spanY = spanY;
    ((Executor) MODEL_EXECUTOR).execute(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.SPANX, item.spanX).put(Favorites.SPANY, item.spanY).put(Favorites.SCREEN, item.screenId)));
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter) Executor(java.util.concurrent.Executor)

Example 35 with ContentWriter

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

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)

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