Search in sources :

Example 1 with Hotseat

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

the class HotseatEduController method showEdu.

void showEdu() {
    int childCount = mHotseat.getShortcutsAndWidgets().getChildCount();
    CellLayout cellLayout = mLauncher.getWorkspace().getScreenWithId(Workspace.FIRST_SCREEN_ID);
    // hotseat is already empty and does not require migration. show edu tip
    boolean requiresMigration = IntStream.range(0, childCount).anyMatch(i -> {
        View v = mHotseat.getShortcutsAndWidgets().getChildAt(i);
        return v != null && v.getTag() != null && ((ItemInfo) v.getTag()).container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
    });
    boolean canMigrateToFirstPage = cellLayout.makeSpaceForHotseatMigration(false);
    if (requiresMigration && canMigrateToFirstPage) {
        showDialog();
    } else {
        new ArrowTipView(mLauncher).show(mLauncher.getString(requiresMigration ? R.string.hotseat_tip_no_empty_slots : R.string.hotseat_auto_enrolled), mHotseat.getTop());
        mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_ONLY_TIP);
        finishOnboarding();
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrowTipView(com.android.launcher3.views.ArrowTipView) View(android.view.View) ArrowTipView(com.android.launcher3.views.ArrowTipView)

Example 2 with Hotseat

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

the class HotseatEduController method migrateToFolder.

/**
 * This migration places all non folder items in the hotseat into a folder and then moves
 * all folders in the hotseat to a workspace page that has enough empty spots.
 *
 * @return pageId that has accepted the items.
 */
private int migrateToFolder() {
    ArrayDeque<FolderInfo> folders = new ArrayDeque<>();
    ArrayList<WorkspaceItemInfo> putIntoFolder = new ArrayList<>();
    // separate folders and items that can get in folders
    for (int i = 0; i < mLauncher.getDeviceProfile().numShownHotseatIcons; i++) {
        View view = mHotseat.getChildAt(i, 0);
        if (view == null)
            continue;
        ItemInfo info = (ItemInfo) view.getTag();
        if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
            folders.add((FolderInfo) info);
        } else if (info instanceof WorkspaceItemInfo && info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
            putIntoFolder.add((WorkspaceItemInfo) info);
        }
    }
    // create a temp folder and add non folder items to it
    if (!putIntoFolder.isEmpty()) {
        ItemInfo firstItem = putIntoFolder.get(0);
        FolderInfo folderInfo = new FolderInfo();
        mLauncher.getModelWriter().addItemToDatabase(folderInfo, firstItem.container, firstItem.screenId, firstItem.cellX, firstItem.cellY);
        folderInfo.setTitle("", mLauncher.getModelWriter());
        folderInfo.contents.addAll(putIntoFolder);
        for (int i = 0; i < folderInfo.contents.size(); i++) {
            ItemInfo item = folderInfo.contents.get(i);
            item.rank = i;
            mLauncher.getModelWriter().moveItemInDatabase(item, folderInfo.id, 0, item.cellX, item.cellY);
        }
        folders.add(folderInfo);
    }
    mNewItems.addAll(folders);
    return placeFoldersInWorkspace(folders);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) FolderInfo(com.android.launcher3.model.data.FolderInfo) ArrowTipView(com.android.launcher3.views.ArrowTipView) View(android.view.View) ArrayDeque(java.util.ArrayDeque) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 3 with Hotseat

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

the class QuickstepModelDelegate method recreatePredictors.

@WorkerThread
private void recreatePredictors() {
    destroyPredictors();
    if (!mActive) {
        return;
    }
    Context context = mApp.getContext();
    AppPredictionManager apm = context.getSystemService(AppPredictionManager.class);
    if (apm == null) {
        return;
    }
    TrustDatabaseHelper trustData = mApp.getTrustData();
    int totalPackageHidden = trustData != null ? trustData.getTotalPackageHidden() : 0;
    registerPredictor(mAllAppsState, apm.createAppPredictionSession(new AppPredictionContext.Builder(context).setUiSurface("home").setPredictedTargetCount(mIDP.numDatabaseAllAppsColumns + totalPackageHidden).build()));
    // TODO: get bundle
    registerPredictor(mHotseatState, apm.createAppPredictionSession(new AppPredictionContext.Builder(context).setUiSurface("hotseat").setPredictedTargetCount(mIDP.numDatabaseHotseatIcons + totalPackageHidden).setExtras(convertDataModelToAppTargetBundle(context, mDataModel)).build()));
    registerWidgetsPredictor(apm.createAppPredictionSession(new AppPredictionContext.Builder(context).setUiSurface("widgets").setPredictedTargetCount(NUM_OF_RECOMMENDED_WIDGETS_PREDICATION).build()));
}
Also used : Context(android.content.Context) AppPredictionContext(android.app.prediction.AppPredictionContext) TrustDatabaseHelper(com.android.launcher3.lineage.trust.db.TrustDatabaseHelper) AppPredictionManager(android.app.prediction.AppPredictionManager) AppPredictionContext(android.app.prediction.AppPredictionContext) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with Hotseat

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

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

the class GridSizeMigrationTask method migrateScreen.

/**
 * Migrate a particular screen id.
 * Strategy:
 *  1) For all possible combinations of row and column, pick the one which causes the least
 *    data loss: {@link #tryRemove(int, int, int, ArrayList, float[])}
 *  2) Maintain a list of all lost items before this screen, and add any new item lost from
 *    this screen to that list as well.
 *  3) If all those items from the above list can be placed on this screen, place them
 *    (otherwise they are placed on a new screen).
 */
protected void migrateScreen(int screenId) {
    // If we are migrating the first screen, do not touch the first row.
    int startY = (FeatureFlags.QSB_ON_FIRST_SCREEN && screenId == Workspace.FIRST_SCREEN_ID) ? 1 : 0;
    ArrayList<DbEntry> items = loadWorkspaceEntries(screenId);
    int removedCol = Integer.MAX_VALUE;
    int removedRow = Integer.MAX_VALUE;
    // removeWt represents the cost function for loss of items during migration, and moveWt
    // represents the cost function for repositioning the items. moveWt is only considered if
    // removeWt is same for two different configurations.
    // Start with Float.MAX_VALUE (assuming full data) and pick the configuration with least
    // cost.
    float removeWt = Float.MAX_VALUE;
    float moveWt = Float.MAX_VALUE;
    float[] outLoss = new float[2];
    ArrayList<DbEntry> finalItems = null;
    // Try removing all possible combinations
    for (int x = 0; x < mSrcX; x++) {
        // nicely aligned with hotseat.
        for (int y = mSrcY - 1; y >= startY; y--) {
            // Use a deep copy when trying out a particular combination as it can change
            // the underlying object.
            ArrayList<DbEntry> itemsOnScreen = tryRemove(x, y, startY, deepCopy(items), outLoss);
            if ((outLoss[0] < removeWt) || ((outLoss[0] == removeWt) && (outLoss[1] < moveWt))) {
                removeWt = outLoss[0];
                moveWt = outLoss[1];
                removedCol = mShouldRemoveX ? x : removedCol;
                removedRow = mShouldRemoveY ? y : removedRow;
                finalItems = itemsOnScreen;
            }
            // No need to loop over all rows, if a row removal is not needed.
            if (!mShouldRemoveY) {
                break;
            }
        }
        if (!mShouldRemoveX) {
            break;
        }
    }
    if (DEBUG) {
        Log.d(TAG, String.format("Removing row %d, column %d on screen %d", removedRow, removedCol, screenId));
    }
    IntSparseArrayMap<DbEntry> itemMap = new IntSparseArrayMap<>();
    for (DbEntry e : deepCopy(items)) {
        itemMap.put(e.id, e);
    }
    for (DbEntry item : finalItems) {
        DbEntry org = itemMap.get(item.id);
        itemMap.remove(item.id);
        // Check if update is required
        if (!item.columnsSame(org)) {
            update(item);
        }
    }
    // The remaining items in {@link #itemMap} are those which didn't get placed.
    for (DbEntry item : itemMap) {
        mCarryOver.add(item);
    }
    if (!mCarryOver.isEmpty() && removeWt == 0) {
        // No new items were removed in this step. Try placing all the items on this screen.
        GridOccupancy occupied = new GridOccupancy(mTrgX, mTrgY);
        occupied.markCells(0, 0, mTrgX, startY, true);
        for (DbEntry item : finalItems) {
            occupied.markCells(item, true);
        }
        OptimalPlacementSolution placement = new OptimalPlacementSolution(occupied, deepCopy(mCarryOver), startY, true);
        placement.find();
        if (placement.lowestWeightLoss == 0) {
            for (DbEntry item : placement.finalPlacedItems) {
                item.screenId = screenId;
                update(item);
            }
            mCarryOver.clear();
        }
    }
}
Also used : IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) GridOccupancy(com.android.launcher3.util.GridOccupancy) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point)

Aggregations

ItemInfo (com.android.launcher3.model.data.ItemInfo)11 View (android.view.View)8 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)7 CellLayout (com.android.launcher3.CellLayout)5 Point (android.graphics.Point)4 FolderInfo (com.android.launcher3.model.data.FolderInfo)4 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)3 Utilities.parsePoint (com.android.launcher3.Utilities.parsePoint)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Cursor (android.database.Cursor)2 ViewGroup (android.view.ViewGroup)2 Workspace (com.android.launcher3.Workspace)2 FolderIcon (com.android.launcher3.folder.FolderIcon)2 StatsLogger (com.android.launcher3.logging.StatsLogManager.StatsLogger)2 GridOccupancy (com.android.launcher3.util.GridOccupancy)2 ArrowTipView (com.android.launcher3.views.ArrowTipView)2 HashSet (java.util.HashSet)2 ValueAnimator (android.animation.ValueAnimator)1