Search in sources :

Example 76 with WorkspaceItemInfo

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

the class Workspace method onDropExternal.

/**
 * Drop an item that didn't originate on one of the workspace screens.
 * It may have come from Launcher (e.g. from all apps or customize), or it may have
 * come from another app altogether.
 *
 * NOTE: This can also be called when we are outside of a drag event, when we want
 * to add an item to one of the workspace screens.
 */
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
    if (d.dragInfo instanceof PendingAddShortcutInfo) {
        WorkspaceItemInfo si = ((PendingAddShortcutInfo) d.dragInfo).activityInfo.createWorkspaceItemInfo();
        if (si != null) {
            d.dragInfo = si;
        }
    }
    ItemInfo info = d.dragInfo;
    int spanX = info.spanX;
    int spanY = info.spanY;
    if (mDragInfo != null) {
        spanX = mDragInfo.spanX;
        spanY = mDragInfo.spanY;
    }
    final int container = mLauncher.isHotseatLayout(cellLayout) ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
    final int screenId = getIdForScreen(cellLayout);
    if (!mLauncher.isHotseatLayout(cellLayout) && screenId != getScreenIdForPageIndex(mCurrentPage) && !mLauncher.isInState(SPRING_LOADED)) {
        snapToPage(getPageIndexForScreenId(screenId));
    }
    if (info instanceof PendingAddItemInfo) {
        final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) info;
        boolean findNearestVacantCell = true;
        if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
            float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) || willAddToExistingUserFolder(d.dragInfo, cellLayout, mTargetCell, distance)) {
                findNearestVacantCell = false;
            }
        }
        final ItemInfo item = d.dragInfo;
        boolean updateWidgetSize = false;
        if (findNearestVacantCell) {
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }
            int[] resultSpan = new int[2];
            mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL);
            if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) {
                updateWidgetSize = true;
            }
            item.spanX = resultSpan[0];
            item.spanY = resultSpan[1];
        }
        Runnable onAnimationCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                // Normally removeExtraEmptyScreen is called in Workspace#onDragEnd, but when
                // adding an item that may not be dropped right away (due to a config activity)
                // we defer the removal until the activity returns.
                deferRemoveExtraEmptyScreen();
                // When dragging and dropping from customization tray, we deal with creating
                // widgets/shortcuts/folders in a slightly different way
                mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, item.spanX, item.spanY);
                mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
            }
        };
        boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
        AppWidgetHostView finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
        if (finalView != null && updateWidgetSize) {
            AppWidgetResizeFrame.updateWidgetSizeRanges(finalView, mLauncher, item.spanX, item.spanY);
        }
        int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
        if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null && ((PendingAddWidgetInfo) pendingInfo).getHandler().needsConfigure()) {
            animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN;
        }
        animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, animationStyle, finalView, true);
    } else {
        // This is for other drag/drop cases, like dragging from All Apps
        mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
        View view;
        switch(info.itemType) {
            case ITEM_TYPE_APPLICATION:
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                if (info instanceof AppInfo) {
                    // Came from all apps -- make a copy
                    info = ((AppInfo) info).makeWorkspaceItem();
                    d.dragInfo = info;
                }
                view = mLauncher.createShortcut(cellLayout, (WorkspaceItemInfo) info);
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, mLauncher, cellLayout, (FolderInfo) info);
                break;
            default:
                throw new IllegalStateException("Unknown item type: " + info.itemType);
        }
        // dropped, without any consideration to whether there is an item there.
        if (touchXY != null) {
            mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
            float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, true, d)) {
                return;
            }
            if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, true)) {
                return;
            }
        }
        if (touchXY != null) {
            // when dragging and dropping, just find the closest free spot
            mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], 1, 1, 1, 1, null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL);
        } else {
            cellLayout.findCellForSpan(mTargetCell, 1, 1);
        }
        // Add the item to DB before adding to screen ensures that the container and other
        // values of the info is properly updated.
        mLauncher.getModelWriter().addOrMoveItemInDatabase(info, container, screenId, mTargetCell[0], mTargetCell[1]);
        addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
        cellLayout.onDropChild(view);
        cellLayout.getShortcutsAndWidgets().measureChild(view);
        if (d.dragView != null) {
            // We wrap the animation call in the temporary set and reset of the current
            // cellLayout to its final transform -- this means we animate the drag view to
            // the correct final location.
            setFinalTransitionTransform();
            mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, this);
            resetTransitionTransform();
        }
        mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 77 with WorkspaceItemInfo

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

the class Workspace method removeItemsByMatcher.

/**
 * Removes items that match the {@param matcher}. When applications are removed
 * as a part of an update, this is called to ensure that other widgets and application
 * shortcuts are not removed.
 */
public void removeItemsByMatcher(final ItemInfoMatcher matcher) {
    for (final CellLayout layoutParent : getWorkspaceAndHotseatCellLayouts()) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();
        IntSparseArrayMap<View> idToViewMap = new IntSparseArrayMap<>();
        ArrayList<ItemInfo> items = new ArrayList<>();
        for (int j = 0; j < layout.getChildCount(); j++) {
            final View view = layout.getChildAt(j);
            if (view.getTag() instanceof ItemInfo) {
                ItemInfo item = (ItemInfo) view.getTag();
                items.add(item);
                idToViewMap.put(item.id, view);
            }
        }
        for (ItemInfo itemToRemove : matcher.filterItemInfos(items)) {
            View child = idToViewMap.get(itemToRemove.id);
            if (child != null) {
                // Note: We can not remove the view directly from CellLayoutChildren as this
                // does not re-mark the spaces as unoccupied.
                layoutParent.removeViewInLayout(child);
                if (child instanceof DropTarget) {
                    mDragController.removeDropTarget((DropTarget) child);
                }
            } else if (itemToRemove.container >= 0) {
                // The item may belong to a folder.
                View parent = idToViewMap.get(itemToRemove.container);
                if (parent instanceof FolderIcon) {
                    FolderInfo folderInfo = (FolderInfo) parent.getTag();
                    folderInfo.remove((WorkspaceItemInfo) itemToRemove, false);
                    if (((FolderIcon) parent).getFolder().isOpen()) {
                        ((FolderIcon) parent).getFolder().close(false);
                    }
                }
            }
        }
    }
    // Strip all the empty screens
    stripEmptyScreens();
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) ViewGroup(android.view.ViewGroup) IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) ArrayList(java.util.ArrayList) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) FolderIcon(com.android.launcher3.folder.FolderIcon) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 78 with WorkspaceItemInfo

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

the class Workspace method updateShortcuts.

void updateShortcuts(ArrayList<WorkspaceItemInfo> shortcuts) {
    final HashSet<WorkspaceItemInfo> updates = new HashSet<>(shortcuts);
    ItemOperator op = (info, v) -> {
        if (v instanceof BubbleTextView && updates.contains(info)) {
            WorkspaceItemInfo si = (WorkspaceItemInfo) info;
            BubbleTextView shortcut = (BubbleTextView) v;
            Drawable oldIcon = shortcut.getIcon();
            boolean oldPromiseState = (oldIcon instanceof PreloadIconDrawable) && ((PreloadIconDrawable) oldIcon).hasNotCompleted();
            shortcut.applyFromWorkspaceItem(si, si.isPromise() != oldPromiseState);
        } else if (info instanceof FolderInfo && v instanceof FolderIcon) {
            ((FolderIcon) v).updatePreviewItems(updates::contains);
        }
        // Iterate all items
        return false;
    };
    mapOverItems(op);
    Folder openFolder = Folder.getOpen(mLauncher);
    if (openFolder != null) {
        openFolder.iterateOverItems(op);
    }
}
Also used : BitmapRenderer(com.android.launcher3.icons.BitmapRenderer) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) OVERVIEW(com.android.launcher3.LauncherState.OVERVIEW) LAUNCHER_SWIPELEFT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPELEFT) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) WallpaperManager(android.app.WallpaperManager) FolderDotInfo(com.android.launcher3.dot.FolderDotInfo) LayoutTransition(android.animation.LayoutTransition) Interpolators(com.android.launcher3.anim.Interpolators) LauncherAtom(com.android.launcher3.logger.LauncherAtom) Handler(android.os.Handler) Target(com.android.launcher3.userevent.nano.LauncherLogProto.Target) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) Log(android.util.Log) WallpaperOffsetInterpolator(com.android.launcher3.util.WallpaperOffsetInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Message(android.os.Message) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) NORMAL(com.android.launcher3.LauncherState.NORMAL) AccessibleDragListenerAdapter(com.android.launcher3.accessibility.AccessibleDragListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) UserEventDispatcher(com.android.launcher3.logging.UserEventDispatcher) SpringLoadedDragController(com.android.launcher3.dragndrop.SpringLoadedDragController) ArrayList(java.util.ArrayList) FLAG_MULTI_PAGE(com.android.launcher3.LauncherState.FLAG_MULTI_PAGE) PreviewBackground(com.android.launcher3.folder.PreviewBackground) AppWidgetHostView(android.appwidget.AppWidgetHostView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) Toast(android.widget.Toast) IntArray(com.android.launcher3.util.IntArray) Parcelable(android.os.Parcelable) DragController(com.android.launcher3.dragndrop.DragController) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) LAUNCHER_SWIPERIGHT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPERIGHT) WorkspaceTouchListener(com.android.launcher3.touch.WorkspaceTouchListener) DragPreviewProvider(com.android.launcher3.graphics.DragPreviewProvider) ValueAnimator(android.animation.ValueAnimator) WorkspaceAccessibilityHelper(com.android.launcher3.accessibility.WorkspaceAccessibilityHelper) Rect(android.graphics.Rect) SPRING_LOADED_EXIT_DELAY(com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY) Animator(android.animation.Animator) ProviderChangedListener(com.android.launcher3.LauncherAppWidgetHost.ProviderChangedListener) SPRING_LOADED(com.android.launcher3.LauncherState.SPRING_LOADED) FLAG_WORKSPACE_INACCESSIBLE(com.android.launcher3.LauncherState.FLAG_WORKSPACE_INACCESSIBLE) AttributeSet(android.util.AttributeSet) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) LauncherEvent(com.android.launcher3.logging.StatsLogManager.LauncherEvent) Predicate(java.util.function.Predicate) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) ViewGroup(android.view.ViewGroup) DragOptions(com.android.launcher3.dragndrop.DragOptions) SparseArray(android.util.SparseArray) ALL_APPS(com.android.launcher3.LauncherState.ALL_APPS) LAUNCHER_STATE_HOME(com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) ALPHA_INDEX_OVERLAY(com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_OVERLAY) Folder(com.android.launcher3.folder.Folder) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherOverlay(com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED(com.android.launcher3.LauncherState.FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) DragLayer(com.android.launcher3.dragndrop.DragLayer) Executors(com.android.launcher3.util.Executors) ADAPTIVE_ICON_WINDOW_ANIM(com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM) Action(com.android.launcher3.userevent.nano.LauncherLogProto.Action) ContainerType(com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType) LayoutInflater(android.view.LayoutInflater) PackageUserKey(com.android.launcher3.util.PackageUserKey) Point(android.graphics.Point) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) StatsLogManager(com.android.launcher3.logging.StatsLogManager) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) LoggerUtils.newContainerTarget(com.android.launcher3.logging.LoggerUtils.newContainerTarget) Bitmap(android.graphics.Bitmap) WorkspacePageIndicator(com.android.launcher3.pageindicators.WorkspacePageIndicator) StateHandler(com.android.launcher3.statemanager.StateManager.StateHandler) ViewTreeObserver(android.view.ViewTreeObserver) IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) Thunk(com.android.launcher3.util.Thunk) PendingAnimation(com.android.launcher3.anim.PendingAnimation) DragView(com.android.launcher3.dragndrop.DragView) Resources(android.content.res.Resources) FolderIcon(com.android.launcher3.folder.FolderIcon) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 79 with WorkspaceItemInfo

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

the class Workspace method createUserFolderIfNecessary.

boolean createUserFolderIfNecessary(View newView, int container, CellLayout target, int[] targetCell, float distance, boolean external, DragObject d) {
    if (distance > mMaxDistanceForFolderCreation)
        return false;
    View v = target.getChildAt(targetCell[0], targetCell[1]);
    boolean hasntMoved = false;
    if (mDragInfo != null) {
        CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell);
        hasntMoved = (mDragInfo.cellX == targetCell[0] && mDragInfo.cellY == targetCell[1]) && (cellParent == target);
    }
    if (v == null || hasntMoved || !mCreateUserFolderOnDrop)
        return false;
    mCreateUserFolderOnDrop = false;
    final int screenId = getIdForScreen(target);
    boolean aboveShortcut = (v.getTag() instanceof WorkspaceItemInfo);
    boolean willBecomeShortcut = (newView.getTag() instanceof WorkspaceItemInfo);
    if (aboveShortcut && willBecomeShortcut) {
        WorkspaceItemInfo sourceInfo = (WorkspaceItemInfo) newView.getTag();
        WorkspaceItemInfo destInfo = (WorkspaceItemInfo) v.getTag();
        // if the drag started here, we need to remove it from the workspace
        if (!external) {
            getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell);
        }
        Rect folderLocation = new Rect();
        float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation);
        target.removeView(v);
        mStatsLogManager.logger().withItemInfo(destInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_FOLDER_CREATED);
        FolderIcon fi = mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]);
        destInfo.cellX = -1;
        destInfo.cellY = -1;
        sourceInfo.cellX = -1;
        sourceInfo.cellY = -1;
        // If the dragView is null, we can't animate
        boolean animate = d != null;
        if (animate) {
            // In order to keep everything continuous, we hand off the currently rendered
            // folder background to the newly created icon. This preserves animation state.
            fi.setFolderBackground(mFolderCreateBg);
            mFolderCreateBg = new PreviewBackground();
            fi.performCreateAnimation(destInfo, v, sourceInfo, d, folderLocation, scale);
        } else {
            fi.prepareCreateAnimation(v);
            fi.addItem(destInfo);
            fi.addItem(sourceInfo);
        }
        mLauncher.folderCreatedFromItem(fi.getFolder(), destInfo);
        return true;
    }
    return false;
}
Also used : Rect(android.graphics.Rect) PreviewBackground(com.android.launcher3.folder.PreviewBackground) FolderIcon(com.android.launcher3.folder.FolderIcon) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 80 with WorkspaceItemInfo

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

the class LauncherAccessibilityDelegate method performAction.

public boolean performAction(final View host, final ItemInfo item, int action) {
    if (action == ACTION_LONG_CLICK) {
        if (PopupContainerWithArrow.canShow(host, item)) {
            // Long press should be consumed for workspace items, and it should invoke the
            // Shortcuts / Notifications / Actions pop-up menu, and not start a drag as the
            // standard long press path does.
            PopupContainerWithArrow.showForIcon((BubbleTextView) host);
            return true;
        } else {
            CustomActionsPopup popup = new CustomActionsPopup(mLauncher, host);
            if (popup.canShow()) {
                popup.show();
                return true;
            }
        }
    }
    if (host instanceof AccessibilityActionHandler && ((AccessibilityActionHandler) host).performAccessibilityAction(action, item)) {
        return true;
    }
    if (action == MOVE) {
        beginAccessibleDrag(host, item);
    } else if (action == ADD_TO_WORKSPACE) {
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {

            @Override
            public void run() {
                if (item instanceof AppInfo) {
                    WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
                    mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
                    ArrayList<ItemInfo> itemList = new ArrayList<>();
                    itemList.add(info);
                    mLauncher.bindItems(itemList, true);
                    announceConfirmation(R.string.item_added_to_workspace);
                } else if (item instanceof PendingAddItemInfo) {
                    PendingAddItemInfo info = (PendingAddItemInfo) item;
                    Workspace workspace = mLauncher.getWorkspace();
                    workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
                    mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates, info.spanX, info.spanY);
                }
            }
        });
        return true;
    } else if (action == MOVE_TO_WORKSPACE) {
        Folder folder = Folder.getOpen(mLauncher);
        folder.close(true);
        WorkspaceItemInfo info = (WorkspaceItemInfo) item;
        folder.getInfo().remove(info, false);
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        mLauncher.getModelWriter().moveItemInDatabase(info, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
        // Bind the item in next frame so that if a new workspace page was created,
        // it will get laid out.
        new Handler().post(new Runnable() {

            @Override
            public void run() {
                ArrayList<ItemInfo> itemList = new ArrayList<>();
                itemList.add(item);
                mLauncher.bindItems(itemList, true);
                announceConfirmation(R.string.item_moved);
            }
        });
    } else if (action == RESIZE) {
        final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
        final IntArray actions = getSupportedResizeActions(host, info);
        CharSequence[] labels = new CharSequence[actions.size()];
        for (int i = 0; i < actions.size(); i++) {
            labels[i] = mLauncher.getText(actions.get(i));
        }
        new AlertDialog.Builder(mLauncher).setTitle(R.string.action_resize).setItems(labels, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                performResizeAction(actions.get(which), host, info);
                dialog.dismiss();
            }
        }).show();
        return true;
    } else if (action == DEEP_SHORTCUTS) {
        return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
    } else {
        for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
            if (dropTarget.supportsAccessibilityDrop(item, host) && action == dropTarget.getAccessibilityAction()) {
                dropTarget.onAccessibilityDrop(host, item);
                return true;
            }
        }
    }
    return false;
}
Also used : CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Handler(android.os.Handler) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) Folder(com.android.launcher3.folder.Folder) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) IntArray(com.android.launcher3.util.IntArray) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) BubbleTextView(com.android.launcher3.BubbleTextView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)418 View (android.view.View)168 ArrayList (java.util.ArrayList)145 ItemInfo (com.android.launcher3.model.data.ItemInfo)125 Intent (android.content.Intent)119 FolderInfo (com.android.launcher3.model.data.FolderInfo)100 AppInfo (com.android.launcher3.model.data.AppInfo)94 BubbleTextView (com.android.launcher3.BubbleTextView)87 AppWidgetHostView (android.appwidget.AppWidgetHostView)84 SuppressLint (android.annotation.SuppressLint)78 DragView (com.android.launcher3.dragndrop.DragView)78 ComponentName (android.content.ComponentName)76 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)73 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)72 Rect (android.graphics.Rect)68 FolderIcon (com.android.launcher3.folder.FolderIcon)68 Context (android.content.Context)62 HashSet (java.util.HashSet)62 Point (android.graphics.Point)59 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)57