Search in sources :

Example 56 with Hotseat

use of com.android.launcher3.Hotseat in project Neo-Launcher by NeoApplications.

the class BaseLoaderResults method sortWorkspaceItemsSpatially.

/**
 * Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to
 * right)
 */
protected void sortWorkspaceItemsSpatially(ArrayList<ItemInfo> workspaceItems) {
    final InvariantDeviceProfile profile = mApp.getInvariantDeviceProfile();
    final int screenCols = profile.numColumns;
    final int screenCellCount = profile.numColumns * profile.numRows;
    Collections.sort(workspaceItems, new Comparator<ItemInfo>() {

        @Override
        public int compare(ItemInfo lhs, ItemInfo rhs) {
            if (lhs.container == rhs.container) {
                // Within containers, order by their spatial position in that container
                switch(lhs.container) {
                    case LauncherSettings.Favorites.CONTAINER_DESKTOP:
                        {
                            int lr = (lhs.screenId * screenCellCount + lhs.cellY * screenCols + lhs.cellX);
                            int rr = (rhs.screenId * screenCellCount + rhs.cellY * screenCols + rhs.cellX);
                            return Integer.compare(lr, rr);
                        }
                    case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
                        {
                            // We currently use the screen id as the rank
                            return Integer.compare(lhs.screenId, rhs.screenId);
                        }
                    default:
                        if (FeatureFlags.IS_DOGFOOD_BUILD) {
                            throw new RuntimeException("Unexpected container type when " + "sorting workspace items.");
                        }
                        return 0;
                }
            } else {
                // Between containers, order by hotseat, desktop
                return Integer.compare(lhs.container, rhs.container);
            }
        }
    });
}
Also used : ItemInfo(com.android.launcher3.ItemInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile)

Example 57 with Hotseat

use of com.android.launcher3.Hotseat in project Neo-Launcher by NeoApplications.

the class BaseLoaderResults method bindWorkspace.

/**
 * Binds all loaded data to actual views on the main thread.
 */
public void bindWorkspace() {
    Callbacks callbacks = mCallbacks.get();
    // Otherwise we hold a reference to them.
    if (callbacks == null) {
        // This launcher has exited and nobody bothered to tell us.  Just bail.
        Log.w(TAG, "LoaderTask running with no launcher");
        return;
    }
    // Save a copy of all the bg-thread collections
    ArrayList<ItemInfo> workspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> appWidgets = new ArrayList<>();
    final IntArray orderedScreenIds = new IntArray();
    synchronized (mBgDataModel) {
        workspaceItems.addAll(mBgDataModel.workspaceItems);
        appWidgets.addAll(mBgDataModel.appWidgets);
        orderedScreenIds.addAll(mBgDataModel.collectWorkspaceScreens());
        mBgDataModel.lastBindId++;
        mMyBindingId = mBgDataModel.lastBindId;
    }
    final int currentScreen;
    {
        int currScreen = mPageToBindFirst != PagedView.INVALID_RESTORE_PAGE ? mPageToBindFirst : callbacks.getCurrentWorkspaceScreen();
        if (currScreen >= orderedScreenIds.size()) {
            // There may be no workspace screens (just hotseat items and an empty page).
            currScreen = PagedView.INVALID_RESTORE_PAGE;
        }
        currentScreen = currScreen;
    }
    final boolean validFirstPage = currentScreen >= 0;
    final int currentScreenId = validFirstPage ? orderedScreenIds.get(currentScreen) : INVALID_SCREEN_ID;
    // Separate the items that are on the current screen, and all the other remaining items
    ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
    ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
    filterCurrentWorkspaceItems(currentScreenId, workspaceItems, currentWorkspaceItems, otherWorkspaceItems);
    filterCurrentWorkspaceItems(currentScreenId, appWidgets, currentAppWidgets, otherAppWidgets);
    sortWorkspaceItemsSpatially(currentWorkspaceItems);
    sortWorkspaceItemsSpatially(otherWorkspaceItems);
    // Tell the workspace that we're about to start binding items
    executeCallbacksTask(c -> {
        c.clearPendingBinds();
        c.startBinding();
    }, mUiExecutor);
    // Bind workspace screens
    executeCallbacksTask(c -> c.bindScreens(orderedScreenIds), mUiExecutor);
    Executor mainExecutor = mUiExecutor;
    // Load items on the current page.
    bindWorkspaceItems(currentWorkspaceItems, mainExecutor);
    bindAppWidgets(currentAppWidgets, mainExecutor);
    // In case of validFirstPage, only bind the first screen, and defer binding the
    // remaining screens after first onDraw (and an optional the fade animation whichever
    // happens later).
    // This ensures that the first screen is immediately visible (eg. during rotation)
    // In case of !validFirstPage, bind all pages one after other.
    final Executor deferredExecutor = validFirstPage ? new ViewOnDrawExecutor() : mainExecutor;
    executeCallbacksTask(c -> c.finishFirstPageBind(validFirstPage ? (ViewOnDrawExecutor) deferredExecutor : null), mainExecutor);
    bindWorkspaceItems(otherWorkspaceItems, deferredExecutor);
    bindAppWidgets(otherAppWidgets, deferredExecutor);
    // Tell the workspace that we're done binding items
    executeCallbacksTask(c -> c.finishBindingItems(mPageToBindFirst), deferredExecutor);
    if (validFirstPage) {
        executeCallbacksTask(c -> {
            // not complete, and schedule the remaining pages.
            if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
                c.onPageBoundSynchronously(currentScreen);
            }
            c.executeOnNextDraw((ViewOnDrawExecutor) deferredExecutor);
        }, mUiExecutor);
    }
}
Also used : ViewOnDrawExecutor(com.android.launcher3.util.ViewOnDrawExecutor) Executor(java.util.concurrent.Executor) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) IntArray(com.android.launcher3.util.IntArray) ItemInfo(com.android.launcher3.ItemInfo) ArrayList(java.util.ArrayList) ViewOnDrawExecutor(com.android.launcher3.util.ViewOnDrawExecutor) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo)

Example 58 with Hotseat

use of com.android.launcher3.Hotseat in project Neo-Launcher by NeoApplications.

the class GridSizeMigrationTask method migrateGridIfNeeded.

/**
 * Migrates the workspace and hotseat in case their sizes changed.
 *
 * @return false if the migration failed.
 */
public static boolean migrateGridIfNeeded(Context context) {
    SharedPreferences prefs = Utilities.getPrefs(context);
    InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
    String gridSizeString = getPointString(idp.numColumns, idp.numRows);
    if (gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, "")) && idp.numHotseatIcons == prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons)) {
        // Skip if workspace and hotseat sizes have not changed.
        return true;
    }
    long migrationStartTime = System.currentTimeMillis();
    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.numHotseatIcons);
        Point sourceSize = parsePoint(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString));
        boolean dbChanged = false;
        GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb(), srcHotseatCount, sourceSize.x, sourceSize.y);
        if (backupTable.backupOrRestoreAsNeeded()) {
            dbChanged = true;
            srcHotseatCount = backupTable.getRestoreHotseatAndGridSize(sourceSize);
        }
        HashSet<String> validPackages = getValidPackages(context);
        // Hotseat
        if (srcHotseatCount != idp.numHotseatIcons) {
            // Migrate hotseat.
            dbChanged = new GridSizeMigrationTask(context, transaction.getDb(), validPackages, srcHotseatCount, idp.numHotseatIcons).migrateHotseat();
        }
        // Grid size
        Point targetSize = new Point(idp.numColumns, idp.numRows);
        if (new MultiStepMigrationTask(validPackages, context, transaction.getDb()).migrate(sourceSize, targetSize)) {
            dbChanged = true;
        }
        if (dbChanged) {
            // Make sure we haven't removed everything.
            final Cursor c = context.getContentResolver().query(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();
        Settings.call(context.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error during grid migration", e);
        return false;
    } finally {
        Log.v(TAG, "Workspace migration completed in " + (System.currentTimeMillis() - migrationStartTime));
        // 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.numHotseatIcons).apply();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) 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 59 with Hotseat

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

the class Workspace method addExtraEmptyScreenOnDrag.

private void addExtraEmptyScreenOnDrag(DragObject dragObject) {
    boolean lastChildOnScreen = false;
    boolean childOnFinalScreen = false;
    if (mDragSourceInternal != null) {
        int dragSourceChildCount = mDragSourceInternal.getChildCount();
        // If the icon was dragged from Hotseat, there is no page pair
        if (isTwoPanelEnabled() && !(mDragSourceInternal.getParent() instanceof Hotseat)) {
            int pagePairScreenId = getScreenPair(dragObject.dragInfo.screenId);
            CellLayout pagePair = mWorkspaceScreens.get(pagePairScreenId);
            dragSourceChildCount += pagePair.getShortcutsAndWidgets().getChildCount();
        }
        // original parent, ShortcutAndWidgetContainer, and reattached to the DragView.
        if (dragObject.dragView.getContentView() instanceof LauncherAppWidgetHostView) {
            dragSourceChildCount++;
        }
        if (dragSourceChildCount == 1) {
            lastChildOnScreen = true;
        }
        CellLayout cl = (CellLayout) mDragSourceInternal.getParent();
        if (getLeftmostVisiblePageForIndex(indexOfChild(cl)) == getLeftmostVisiblePageForIndex(getPageCount() - 1)) {
            childOnFinalScreen = true;
        }
    }
    // If this is the last item on the final screen
    if (lastChildOnScreen && childOnFinalScreen) {
        return;
    }
    forEachExtraEmptyPageId(extraEmptyPageId -> {
        if (!mWorkspaceScreens.containsKey(extraEmptyPageId)) {
            insertNewWorkspaceScreen(extraEmptyPageId);
        }
    });
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 60 with Hotseat

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

the class WorkspaceLayoutManager method addInScreen.

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 */
default void addInScreen(View child, int container, int screenId, int x, int y, int spanX, int spanY) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (EXTRA_EMPTY_SCREEN_IDS.contains(screenId)) {
        // This should never happen
        throw new RuntimeException("Screen id should not be extra empty screen: " + screenId);
    }
    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT || container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
        layout = getHotseat();
        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
    }
    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }
    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }
    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = info.getViewId();
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Log.e(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout");
    }
    child.setHapticFeedbackEnabled(false);
    child.setOnLongClickListener(getWorkspaceChildOnLongClickListener());
    if (child instanceof DropTarget) {
        onAddDropTarget((DropTarget) child);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) ViewGroup(android.view.ViewGroup) Folder(com.android.launcher3.folder.Folder)

Aggregations

ItemInfo (com.android.launcher3.model.data.ItemInfo)67 View (android.view.View)66 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)46 Point (android.graphics.Point)27 ArrayList (java.util.ArrayList)27 CellLayout (com.android.launcher3.CellLayout)26 ViewGroup (android.view.ViewGroup)23 BubbleTextView (com.android.launcher3.BubbleTextView)23 FolderInfo (com.android.launcher3.model.data.FolderInfo)23 ArrowTipView (com.android.launcher3.views.ArrowTipView)22 FolderIcon (com.android.launcher3.folder.FolderIcon)20 SuppressLint (android.annotation.SuppressLint)19 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)19 Hotseat (com.android.launcher3.Hotseat)16 Intent (android.content.Intent)15 IntArray (com.android.launcher3.util.IntArray)13 Workspace (com.android.launcher3.Workspace)12 DraggableView (com.android.launcher3.dragndrop.DraggableView)12 HashSet (java.util.HashSet)12 AppWidgetHostView (android.appwidget.AppWidgetHostView)11