Search in sources :

Example 6 with DropTarget

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

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 (CellLayout layout : getWorkspaceAndHotseatCellLayouts()) {
        ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets();
        // Iterate in reverse order as we are removing items
        for (int i = container.getChildCount() - 1; i >= 0; i--) {
            View child = container.getChildAt(i);
            ItemInfo info = (ItemInfo) child.getTag();
            if (matcher.matchesInfo(info)) {
                layout.removeViewInLayout(child);
                if (child instanceof DropTarget) {
                    mDragController.removeDropTarget((DropTarget) child);
                }
            } else if (child instanceof FolderIcon) {
                FolderInfo folderInfo = (FolderInfo) info;
                List<WorkspaceItemInfo> matches = folderInfo.contents.stream().filter(matcher::matchesInfo).collect(Collectors.toList());
                if (!matches.isEmpty()) {
                    folderInfo.removeAll(matches, false);
                    if (((FolderIcon) child).getFolder().isOpen()) {
                        ((FolderIcon) child).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) FolderIcon(com.android.launcher3.folder.FolderIcon) ArrayList(java.util.ArrayList) RunnableList(com.android.launcher3.util.RunnableList) List(java.util.List) 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)

Example 7 with DropTarget

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

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 (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }
    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)

Example 8 with DropTarget

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

the class LauncherAccessibilityDelegate method performAction.

/**
 * Performs the provided action on the host
 */
protected boolean performAction(final View host, final ItemInfo item, int action, boolean fromKeyboard) {
    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 if (action == MOVE) {
        return beginAccessibleDrag(host, item, fromKeyboard);
    } else if (action == ADD_TO_WORKSPACE) {
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        mLauncher.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
            if (item instanceof AppInfo) {
                WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
                mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
                mLauncher.bindItems(Collections.singletonList(info), /* forceAnimateIcons= */
                true, /* focusFirstItemForAccessibility= */
                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, 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(() -> {
            mLauncher.bindItems(Collections.singletonList(item), true);
            announceConfirmation(R.string.item_moved);
        });
        return true;
    } else if (action == RESIZE) {
        final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
        List<OptionItem> actions = getSupportedResizeActions(host, info);
        Rect pos = new Rect();
        mLauncher.getDragLayer().getDescendantRectRelativeToSelf(host, pos);
        ArrowPopup popup = OptionsPopupView.show(mLauncher, new RectF(pos), actions, false);
        popup.requestFocus();
        popup.setOnCloseCallback(host::requestFocus);
        return true;
    } else if (action == DEEP_SHORTCUTS || action == SHORTCUTS_AND_NOTIFICATIONS) {
        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 : Rect(android.graphics.Rect) OptionItem(com.android.launcher3.views.OptionsPopupView.OptionItem) ArrowPopup(com.android.launcher3.popup.ArrowPopup) 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) RectF(android.graphics.RectF) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Aggregations

DropTarget (com.android.launcher3.DropTarget)5 Point (android.graphics.Point)4 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3 Rect (android.graphics.Rect)2 View (android.view.View)2 Folder (com.android.launcher3.folder.Folder)2 FolderIcon (com.android.launcher3.folder.FolderIcon)2 FolderInfo (com.android.launcher3.model.data.FolderInfo)2 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 SuppressLint (android.annotation.SuppressLint)1 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 RectF (android.graphics.RectF)1 Handler (android.os.Handler)1 ViewGroup (android.view.ViewGroup)1 ButtonDropTarget (com.android.launcher3.ButtonDropTarget)1 CellLayout (com.android.launcher3.CellLayout)1 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)1 Workspace (com.android.launcher3.Workspace)1 DragView (com.android.launcher3.dragndrop.DragView)1 DraggableView (com.android.launcher3.dragndrop.DraggableView)1