Search in sources :

Example 1 with MODEL_EXECUTOR

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

Example 2 with MODEL_EXECUTOR

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

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)

Aggregations

ContentWriter (com.android.launcher3.util.ContentWriter)2 Executor (java.util.concurrent.Executor)2 ContentResolver (android.content.ContentResolver)1