Search in sources :

Example 1 with InvariantDeviceProfile

use of com.android.launcher3.InvariantDeviceProfile in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatEduController method placeFoldersInWorkspace.

private int placeFoldersInWorkspace(ArrayDeque<FolderInfo> folders) {
    if (folders.isEmpty())
        return 0;
    Workspace workspace = mLauncher.getWorkspace();
    InvariantDeviceProfile idp = mLauncher.getDeviceProfile().inv;
    GridOccupancy[] occupancyList = new GridOccupancy[workspace.getChildCount()];
    for (int i = 0; i < occupancyList.length; i++) {
        occupancyList[i] = ((CellLayout) workspace.getChildAt(i)).cloneGridOccupancy();
    }
    // scan every screen to find available spots to place folders
    int occupancyIndex = 0;
    int[] itemXY = new int[2];
    while (occupancyIndex < occupancyList.length && !folders.isEmpty()) {
        GridOccupancy occupancy = occupancyList[occupancyIndex];
        if (occupancy.findVacantCell(itemXY, 1, 1)) {
            FolderInfo info = folders.poll();
            mLauncher.getModelWriter().moveItemInDatabase(info, LauncherSettings.Favorites.CONTAINER_DESKTOP, workspace.getScreenIdForPageIndex(occupancyIndex), itemXY[0], itemXY[1]);
            occupancy.markCells(info, true);
        } else {
            occupancyIndex++;
        }
    }
    if (folders.isEmpty())
        return workspace.getScreenIdForPageIndex(occupancyIndex);
    int screenId = LauncherSettings.Settings.call(mLauncher.getContentResolver(), LauncherSettings.Settings.METHOD_NEW_SCREEN_ID).getInt(LauncherSettings.Settings.EXTRA_VALUE);
    // if all screens are full and we still have folders left, put those on a new page
    FolderInfo folderInfo;
    int col = 0;
    while ((folderInfo = folders.poll()) != null) {
        mLauncher.getModelWriter().moveItemInDatabase(folderInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, col++, idp.numRows - 1);
    }
    mNewScreens = IntArray.wrap(screenId);
    return workspace.getPageCount();
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) GridOccupancy(com.android.launcher3.util.GridOccupancy) FolderInfo(com.android.launcher3.model.data.FolderInfo) Workspace(com.android.launcher3.Workspace)

Example 2 with InvariantDeviceProfile

use of com.android.launcher3.InvariantDeviceProfile in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsPredicationUpdateTaskTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    doAnswer(invocation -> {
        ComponentWithLabel componentWithLabel = invocation.getArgument(0);
        return componentWithLabel.getComponent().getShortClassName();
    }).when(mIconCache).getTitleNoCache(any());
    mContext = RuntimeEnvironment.application;
    mModelHelper = new LauncherModelHelper();
    mUserHandle = Process.myUserHandle();
    mTestProfile = new InvariantDeviceProfile();
    // 2 widgets, app4/provider1 & app5/provider1, have already been added to the workspace.
    mModelHelper.initializeData("/widgets_predication_update_task_data.txt");
    ShadowPackageManager packageManager = shadowOf(mContext.getPackageManager());
    mApp1Provider1.provider = ComponentName.createRelative("app1", "provider1");
    ReflectionHelpers.setField(mApp1Provider1, "providerInfo", packageManager.addReceiverIfNotPresent(mApp1Provider1.provider));
    mApp1Provider2.provider = ComponentName.createRelative("app1", "provider2");
    ReflectionHelpers.setField(mApp1Provider2, "providerInfo", packageManager.addReceiverIfNotPresent(mApp1Provider2.provider));
    mApp2Provider1.provider = ComponentName.createRelative("app2", "provider1");
    ReflectionHelpers.setField(mApp2Provider1, "providerInfo", packageManager.addReceiverIfNotPresent(mApp2Provider1.provider));
    mApp4Provider1.provider = ComponentName.createRelative("app4", "provider1");
    ReflectionHelpers.setField(mApp4Provider1, "providerInfo", packageManager.addReceiverIfNotPresent(mApp4Provider1.provider));
    mApp4Provider2.provider = ComponentName.createRelative("app4", ".provider2");
    ReflectionHelpers.setField(mApp4Provider2, "providerInfo", packageManager.addReceiverIfNotPresent(mApp4Provider2.provider));
    mApp5Provider1.provider = ComponentName.createRelative("app5", "provider1");
    ReflectionHelpers.setField(mApp5Provider1, "providerInfo", packageManager.addReceiverIfNotPresent(mApp5Provider1.provider));
    ShadowAppWidgetManager shadowAppWidgetManager = shadowOf(mContext.getSystemService(AppWidgetManager.class));
    shadowAppWidgetManager.addInstalledProvider(mApp1Provider1);
    shadowAppWidgetManager.addInstalledProvider(mApp1Provider2);
    shadowAppWidgetManager.addInstalledProvider(mApp2Provider1);
    shadowAppWidgetManager.addInstalledProvider(mApp4Provider1);
    shadowAppWidgetManager.addInstalledProvider(mApp4Provider2);
    shadowAppWidgetManager.addInstalledProvider(mApp5Provider1);
    mModelHelper.getModel().addCallbacks(mCallback);
    MODEL_EXECUTOR.post(() -> mModelHelper.getBgDataModel().widgetsModel.update(LauncherAppState.getInstance(mContext), /* packageUser= */
    null));
    waitUntilIdle();
}
Also used : ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) LauncherModelHelper(com.android.launcher3.util.LauncherModelHelper) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ShadowAppWidgetManager(org.robolectric.shadows.ShadowAppWidgetManager) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel) ShadowAppWidgetManager(org.robolectric.shadows.ShadowAppWidgetManager) Before(org.junit.Before)

Example 3 with InvariantDeviceProfile

use of com.android.launcher3.InvariantDeviceProfile 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 4 with InvariantDeviceProfile

use of com.android.launcher3.InvariantDeviceProfile 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 5 with InvariantDeviceProfile

use of com.android.launcher3.InvariantDeviceProfile 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)

Aggregations

InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)37 Test (org.junit.Test)13 Before (org.junit.Before)10 ComponentWithLabel (com.android.launcher3.icons.ComponentWithLabel)9 Point (android.graphics.Point)8 DeviceProfile (com.android.launcher3.DeviceProfile)6 SharedPreferences (android.content.SharedPreferences)4 Utilities.getPointString (com.android.launcher3.Utilities.getPointString)4 GridBackupTable (com.android.launcher3.model.GridBackupTable)4 TestActivity (com.android.launcher3.testing.TestActivity)4 Rect (android.graphics.Rect)3 Context (android.content.Context)2 PopupDataProvider (com.android.launcher3.popup.PopupDataProvider)2 LauncherDbUtils (com.android.launcher3.provider.LauncherDbUtils)2 SQLiteTransaction (com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)2 GridOccupancy (com.android.launcher3.util.GridOccupancy)2 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Notification (android.app.Notification)1