Search in sources :

Example 76 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Trebuchet by LineageOS.

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 77 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Trebuchet by LineageOS.

the class FolderIcon method drawLeaveBehindIfExists.

public void drawLeaveBehindIfExists() {
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
    // While the folder is open, the position of the icon cannot change.
    lp.canReorder = false;
    if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) getParent().getParent();
        cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout)

Example 78 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Trebuchet by LineageOS.

the class FolderIcon method onDragEnter.

public void onDragEnter(ItemInfo dragInfo) {
    if (mFolder.isDestroyed() || !willAcceptItem(dragInfo))
        return;
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
    CellLayout cl = (CellLayout) getParent().getParent();
    mBackground.animateToAccept(cl, lp.cellX, lp.cellY);
    mOpenAlarm.setOnAlarmListener(mOnOpenListener);
    if (SPRING_LOADING_ENABLED && ((dragInfo instanceof AppInfo) || (dragInfo instanceof WorkspaceItemInfo) || (dragInfo instanceof PendingAddShortcutInfo))) {
        mOpenAlarm.setAlarm(ON_OPEN_DELAY);
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 79 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Trebuchet by LineageOS.

the class FolderIcon method onDrop.

private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect, float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) {
    item.cellX = -1;
    item.cellY = -1;
    DragView animateView = d.dragView;
    // will not have a view to animate
    if (animateView != null && mActivity instanceof Launcher) {
        final Launcher launcher = (Launcher) mActivity;
        DragLayer dragLayer = launcher.getDragLayer();
        Rect from = new Rect();
        dragLayer.getViewRectRelativeToSelf(animateView, from);
        Rect to = finalRect;
        if (to == null) {
            to = new Rect();
            Workspace workspace = launcher.getWorkspace();
            // Set cellLayout and this to it's final state to compute final animation locations
            workspace.setFinalTransitionTransform();
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
            // Finished computing final animation locations, restore current state
            setScaleX(scaleX);
            setScaleY(scaleY);
            workspace.resetTransitionTransform();
        }
        int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1);
        boolean itemAdded = false;
        if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) {
            List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems);
            mInfo.add(item, index, false);
            mCurrentPreviewItems.clear();
            mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
            if (!oldPreviewItems.equals(mCurrentPreviewItems)) {
                int newIndex = mCurrentPreviewItems.indexOf(item);
                if (newIndex >= 0) {
                    // If the item dropped is going to be in the preview, we update the
                    // index here to reflect its position in the preview.
                    index = newIndex;
                }
                mPreviewItemManager.hidePreviewItem(index, true);
                mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item);
                itemAdded = true;
            } else {
                removeItem(item, false);
            }
        }
        if (!itemAdded) {
            mInfo.add(item, index, true);
        }
        int[] center = new int[2];
        float scale = getLocalCenterForIndex(index, numItemsInPreview, center);
        center[0] = Math.round(scaleRelativeToDragLayer * center[0]);
        center[1] = Math.round(scaleRelativeToDragLayer * center[1]);
        to.offset(center[0] - animateView.getMeasuredWidth() / 2, center[1] - animateView.getMeasuredHeight() / 2);
        float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;
        float finalScale = scale * scaleRelativeToDragLayer;
        // Account for potentially different icon sizes with non-default grid settings
        if (d.dragSource instanceof AllAppsContainerView) {
            DeviceProfile grid = mActivity.getDeviceProfile();
            float containerScale = (1f * grid.iconSizePx / grid.allAppsIconSizePx);
            finalScale *= containerScale;
        }
        dragLayer.animateView(animateView, from, to, finalAlpha, 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, Interpolators.DEACCEL_2, Interpolators.ACCEL_2, null, DragLayer.ANIMATION_END_DISAPPEAR, null);
        mFolder.hideItem(item);
        if (!itemAdded)
            mPreviewItemManager.hidePreviewItem(index, true);
        final int finalIndex = index;
        FolderNameInfos nameInfos = new FolderNameInfos();
        if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
            Executors.MODEL_EXECUTOR.post(() -> {
                d.folderNameProvider.getSuggestedFolderName(getContext(), mInfo.contents, nameInfos);
                showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
            });
        } else {
            showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
        }
    } else {
        addItem(item);
    }
}
Also used : AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) DragView(com.android.launcher3.dragndrop.DragView) DeviceProfile(com.android.launcher3.DeviceProfile) DragLayer(com.android.launcher3.dragndrop.DragLayer) Launcher(com.android.launcher3.Launcher) Workspace(com.android.launcher3.Workspace) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 80 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Trebuchet by LineageOS.

the class FolderIcon method clearLeaveBehindIfExists.

public void clearLeaveBehindIfExists() {
    ((CellLayout.LayoutParams) getLayoutParams()).canReorder = true;
    if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) getParent().getParent();
        cl.clearFolderLeaveBehind();
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout)

Aggregations

CellLayout (com.android.launcher3.CellLayout)178 View (android.view.View)169 SuppressLint (android.annotation.SuppressLint)126 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)124 AppWidgetHostView (android.appwidget.AppWidgetHostView)105 Point (android.graphics.Point)95 DragView (com.android.launcher3.dragndrop.DragView)91 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)87 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)73 BubbleTextView (com.android.launcher3.BubbleTextView)62 Rect (android.graphics.Rect)60 FolderIcon (com.android.launcher3.folder.FolderIcon)52 DragLayer (com.android.launcher3.dragndrop.DragLayer)50 ArrayList (java.util.ArrayList)48 FolderInfo (com.android.launcher3.model.data.FolderInfo)45 Workspace (com.android.launcher3.Workspace)43 DraggableView (com.android.launcher3.dragndrop.DraggableView)43 Animator (android.animation.Animator)42 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)40