Search in sources :

Example 1 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.

the class GridSizeMigrationTask method needsToMigrate.

/**
 * Check given a new IDP, if migration is necessary.
 */
public static boolean needsToMigrate(Context context, InvariantDeviceProfile idp) {
    SharedPreferences prefs = Utilities.getPrefs(context);
    String gridSizeString = getPointString(idp.numColumns, idp.numRows);
    return !gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, "")) || idp.numDatabaseHotseatIcons != prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, -1);
}
Also used : SharedPreferences(android.content.SharedPreferences) Utilities.getPointString(com.android.launcher3.Utilities.getPointString)

Example 2 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.

the class GridSizeMigrationTask method migrateGridIfNeeded.

/**
 * Run the migration algorithm if needed. For preview, we provide the intended idp because it
 * has not been changed. If idp is null, we read it from the context, for actual grid migration.
 *
 * @return false if the migration failed.
 */
public static boolean migrateGridIfNeeded(Context context, InvariantDeviceProfile idp) {
    boolean migrateForPreview = idp != null;
    if (!migrateForPreview) {
        idp = LauncherAppState.getIDP(context);
    }
    if (!needsToMigrate(context, idp)) {
        return true;
    }
    SharedPreferences prefs = Utilities.getPrefs(context);
    String gridSizeString = getPointString(idp.numColumns, idp.numRows);
    long migrationStartTime = SystemClock.elapsedRealtime();
    try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
        int srcHotseatCount = prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numDatabaseHotseatIcons);
        Point sourceSize = parsePoint(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString));
        boolean dbChanged = false;
        if (migrateForPreview) {
            copyTable(transaction.getDb(), Favorites.TABLE_NAME, transaction.getDb(), Favorites.PREVIEW_TABLE_NAME, context);
        }
        GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb(), srcHotseatCount, sourceSize.x, sourceSize.y);
        if (migrateForPreview ? backupTable.restoreToPreviewIfBackupExists() : backupTable.backupOrRestoreAsNeeded()) {
            dbChanged = true;
            srcHotseatCount = backupTable.getRestoreHotseatAndGridSize(sourceSize);
        }
        HashSet<String> validPackages = getValidPackages(context);
        // Hotseat.
        if (srcHotseatCount != idp.numDatabaseHotseatIcons && new GridSizeMigrationTask(context, transaction.getDb(), validPackages, migrateForPreview, srcHotseatCount, idp.numDatabaseHotseatIcons).migrateHotseat()) {
            dbChanged = true;
        }
        // Grid size
        Point targetSize = new Point(idp.numColumns, idp.numRows);
        if (new MultiStepMigrationTask(validPackages, context, transaction.getDb(), migrateForPreview).migrate(sourceSize, targetSize)) {
            dbChanged = true;
        }
        if (dbChanged) {
            // Make sure we haven't removed everything.
            final Cursor c = context.getContentResolver().query(migrateForPreview ? Favorites.PREVIEW_CONTENT_URI : Favorites.CONTENT_URI, null, null, null, null);
            boolean hasData = c.moveToNext();
            c.close();
            if (!hasData) {
                throw new Exception("Removed every thing during grid resize");
            }
        }
        transaction.commit();
        if (!migrateForPreview) {
            Settings.call(context.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);
        }
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error during preview grid migration", e);
        return false;
    } finally {
        Log.v(TAG, "Preview workspace migration completed in " + (SystemClock.elapsedRealtime() - migrationStartTime));
        if (!migrateForPreview) {
            // Save current configuration, so that the migration does not run again.
            prefs.edit().putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString).putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numDatabaseHotseatIcons).apply();
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) Utilities.getPointString(com.android.launcher3.Utilities.getPointString) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point) Cursor(android.database.Cursor) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point)

Example 3 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.

the class GridSizeMigrationTaskV2 method needsToMigrate.

/**
 * Check given a new IDP, if migration is necessary.
 */
public static boolean needsToMigrate(Context context, InvariantDeviceProfile idp) {
    SharedPreferences prefs = Utilities.getPrefs(context);
    String gridSizeString = getPointString(idp.numColumns, idp.numRows);
    return !gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, "")) || idp.numDatabaseHotseatIcons != prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, -1);
}
Also used : SharedPreferences(android.content.SharedPreferences) Utilities.getPointString(com.android.launcher3.Utilities.getPointString)

Example 4 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.

the class InvariantDeviceProfile method onConfigChanged.

private void onConfigChanged(Context context) {
    // Re-init grid
    String gridName = getCurrentGridName(context);
    initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, gridName));
    for (OnIDPChangeListener listener : mChangeListeners) {
        listener.onIdpChanged(this);
    }
}
Also used : Utilities.getPointString(com.android.launcher3.Utilities.getPointString)

Example 5 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by AOSPA.

the class RestoreDbTask method setPending.

/**
 * Marks the DB state as pending restoration
 */
public static void setPending(Context context) {
    FileLog.d(TAG, "Restore data received through full backup ");
    Utilities.getPrefs(context).edit().putInt(RESTORED_DEVICE_TYPE, new DeviceGridState(context).getDeviceType()).commit();
}
Also used : DeviceGridState(com.android.launcher3.model.DeviceGridState)

Aggregations

SharedPreferences (android.content.SharedPreferences)23 Point (android.graphics.Point)15 Utilities.getPointString (com.android.launcher3.Utilities.getPointString)11 SQLiteTransaction (com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)10 Intent (android.content.Intent)8 Configuration (android.content.res.Configuration)8 TargetApi (android.annotation.TargetApi)7 IntentFilter (android.content.IntentFilter)7 StrictMode (android.os.StrictMode)7 DragObject (com.android.launcher3.DropTarget.DragObject)7 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)7 PropertyListBuilder (com.android.launcher3.anim.PropertyListBuilder)7 PopupDataProvider (com.android.launcher3.popup.PopupDataProvider)7 RotationHelper (com.android.launcher3.states.RotationHelper)7 ArrayList (java.util.ArrayList)7 Resources (android.content.res.Resources)6 Notification (android.app.Notification)5 AppWidgetHost (android.appwidget.AppWidgetHost)5 LauncherAppWidgetHost (com.android.launcher3.widget.LauncherAppWidgetHost)5 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)5