Search in sources :

Example 1 with DropTarget

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

the class DragController method forceTouchMove.

public void forceTouchMove() {
    int[] placeholderCoordinates = mCoordinatesTemp;
    DropTarget dropTarget = findDropTarget(mLastTouch.x, mLastTouch.y, placeholderCoordinates);
    mDragObject.x = placeholderCoordinates[0];
    mDragObject.y = placeholderCoordinates[1];
    checkTouchMove(dropTarget);
}
Also used : DropTarget(com.android.launcher3.DropTarget)

Example 2 with DropTarget

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

the class DragController method findDropTarget.

private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
    mDragObject.x = x;
    mDragObject.y = y;
    final Rect r = mRectTemp;
    final ArrayList<DropTarget> dropTargets = mDropTargets;
    final int count = dropTargets.size();
    for (int i = count - 1; i >= 0; i--) {
        DropTarget target = dropTargets.get(i);
        if (!target.isDropEnabled())
            continue;
        target.getHitRectRelativeToDragLayer(r);
        if (r.contains(x, y)) {
            dropCoordinates[0] = x;
            dropCoordinates[1] = y;
            mActivity.getDragLayer().mapCoordInSelfToDescendant((View) target, dropCoordinates);
            return target;
        }
    }
    // Pass all unhandled drag to workspace. Workspace finds the correct
    // cell layout to drop to in the existing drag/drop logic.
    dropCoordinates[0] = x;
    dropCoordinates[1] = y;
    return getDefaultDropTarget(dropCoordinates);
}
Also used : Rect(android.graphics.Rect) DropTarget(com.android.launcher3.DropTarget) Point(android.graphics.Point)

Example 3 with DropTarget

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

the class DragController method completeAccessibleDrag.

/**
 * As above, since accessible drag and drop won't cause the same sequence of touch events,
 * we manually ensure appropriate drag and drop events get emulated for accessible drag.
 */
public void completeAccessibleDrag(int[] location) {
    final int[] coordinates = mCoordinatesTemp;
    // We make sure that we prime the target for drop.
    DropTarget dropTarget = findDropTarget(location[0], location[1], coordinates);
    mDragObject.x = coordinates[0];
    mDragObject.y = coordinates[1];
    checkTouchMove(dropTarget);
    dropTarget.prepareAccessibilityDrop();
    // Perform the drop
    drop(dropTarget, null);
    endDrag();
}
Also used : DropTarget(com.android.launcher3.DropTarget)

Example 4 with DropTarget

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

the class DragController method handleMoveEvent.

protected void handleMoveEvent(int x, int y) {
    mDragObject.dragView.move(x, y);
    // Drop on someone?
    final int[] coordinates = mCoordinatesTemp;
    DropTarget dropTarget = findDropTarget(x, y, coordinates);
    mDragObject.x = coordinates[0];
    mDragObject.y = coordinates[1];
    checkTouchMove(dropTarget);
    // Check if we are hovering over the scroll areas
    mDistanceSinceScroll += Math.hypot(mLastTouch.x - x, mLastTouch.y - y);
    mLastTouch.set(x, y);
    int distanceDragged = mDistanceSinceScroll;
    if (ATLEAST_Q && mLastTouchClassification == MotionEvent.CLASSIFICATION_DEEP_PRESS) {
        distanceDragged /= DEEP_PRESS_DISTANCE_FACTOR;
    }
    if (mIsInPreDrag && mOptions.preDragCondition != null && mOptions.preDragCondition.shouldStartDrag(distanceDragged)) {
        callOnDragStart();
    }
}
Also used : DropTarget(com.android.launcher3.DropTarget) Point(android.graphics.Point)

Example 5 with DropTarget

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

the class LauncherDelegate method replaceFolderWithFinalItem.

void replaceFolderWithFinalItem(Folder folder) {
    // Add the last remaining child to the workspace in place of the folder
    Runnable onCompleteRunnable = new Runnable() {

        @Override
        public void run() {
            int itemCount = folder.getItemCount();
            FolderInfo info = folder.mInfo;
            if (itemCount <= 1) {
                View newIcon = null;
                WorkspaceItemInfo finalItem = null;
                if (itemCount == 1) {
                    // Move the item from the folder to the workspace, in the position of the
                    // folder
                    CellLayout cellLayout = mLauncher.getCellLayout(info.container, info.screenId);
                    finalItem = info.contents.remove(0);
                    newIcon = mLauncher.createShortcut(cellLayout, finalItem);
                    mLauncher.getModelWriter().addOrMoveItemInDatabase(finalItem, info.container, info.screenId, info.cellX, info.cellY);
                }
                // Remove the folder
                mLauncher.removeItem(folder.mFolderIcon, info, true);
                if (folder.mFolderIcon instanceof DropTarget) {
                    folder.mDragController.removeDropTarget((DropTarget) folder.mFolderIcon);
                }
                if (newIcon != null) {
                    // We add the child after removing the folder to prevent both from existing
                    // at the same time in the CellLayout.  We need to add the new item with
                    // addInScreenFromBind() to ensure that hotseat items are placed correctly.
                    mLauncher.getWorkspace().addInScreenFromBind(newIcon, info);
                    // Focus the newly created child
                    newIcon.requestFocus();
                }
                if (finalItem != null) {
                    StatsLogger logger = mLauncher.getStatsLogManager().logger().withItemInfo(finalItem);
                    ((Optional<InstanceId>) folder.mDragController.getLogInstanceId()).map(logger::withInstanceId).orElse(logger).log(LAUNCHER_FOLDER_CONVERTED_TO_ICON);
                }
            }
        }
    };
    View finalChild = folder.mContent.getLastItem();
    if (finalChild != null) {
        folder.mFolderIcon.performDestroyAnimation(onCompleteRunnable);
    } else {
        onCompleteRunnable.run();
    }
}
Also used : StatsLogger(com.android.launcher3.logging.StatsLogManager.StatsLogger) CellLayout(com.android.launcher3.CellLayout) Optional(java.util.Optional) DropTarget(com.android.launcher3.DropTarget) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

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