Search in sources :

Example 1 with ButtonDropTarget

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

the class FlingToDeleteHelper method isFlingingToDelete.

/**
 * Determines whether the user flung the current item to delete it.
 *
 * @return the vector at which the item was flung, or null if no fling was detected.
 */
private PointF isFlingingToDelete() {
    if (mVelocityTracker == null)
        return null;
    if (mDropTarget == null) {
        mDropTarget = (ButtonDropTarget) mLauncher.findViewById(R.id.delete_target_text);
    }
    if (mDropTarget == null || !mDropTarget.isDropEnabled())
        return null;
    ViewConfiguration config = ViewConfiguration.get(mLauncher);
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
    PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
    float theta = MAX_FLING_DEGREES + 1;
    DeviceProfile deviceProfile = mLauncher.getDeviceProfile();
    if (mVelocityTracker.getYVelocity() < deviceProfile.flingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF upVec = new PointF(0f, -1f);
        theta = getAngleBetweenVectors(vel, upVec);
    } else if (mLauncher.getDeviceProfile().isVerticalBarLayout() && mVelocityTracker.getXVelocity() < deviceProfile.flingToDeleteThresholdVelocity) {
        // Remove icon is on left side instead of top, so check if we are flinging to the left.
        PointF leftVec = new PointF(-1f, 0f);
        theta = getAngleBetweenVectors(vel, leftVec);
    }
    if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
        return vel;
    }
    return null;
}
Also used : ViewConfiguration(android.view.ViewConfiguration) DeviceProfile(com.android.launcher3.DeviceProfile) PointF(android.graphics.PointF)

Example 2 with ButtonDropTarget

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

Point (android.graphics.Point)1 PointF (android.graphics.PointF)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 Handler (android.os.Handler)1 ViewConfiguration (android.view.ViewConfiguration)1 ButtonDropTarget (com.android.launcher3.ButtonDropTarget)1 DeviceProfile (com.android.launcher3.DeviceProfile)1 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)1 Workspace (com.android.launcher3.Workspace)1 Folder (com.android.launcher3.folder.Folder)1 AppInfo (com.android.launcher3.model.data.AppInfo)1 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)1 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)1 ArrowPopup (com.android.launcher3.popup.ArrowPopup)1 OptionItem (com.android.launcher3.views.OptionsPopupView.OptionItem)1