Search in sources :

Example 11 with DragOptions

use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.

the class ButtonDropTarget method onDrop.

/**
 * On drop animate the dropView to the icon.
 */
@Override
public void onDrop(final DragObject d, final DragOptions options) {
    if (options.isFlingToDelete) {
        // FlingAnimation handles the animation and then calls completeDrop().
        return;
    }
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final DragView dragView = d.dragView;
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    final Rect to = getIconRect(d);
    final float scale = (float) to.width() / from.width();
    dragView.disableColorExtraction();
    dragView.detachContentView(/* reattachToPreviousParent= */
    true);
    mDropTargetBar.deferOnDragEnd();
    Runnable onAnimationEndRunnable = () -> {
        completeDrop(d);
        mDropTargetBar.onDragEnd();
        mLauncher.getStateManager().goToState(NORMAL);
        // Only re-enable updates once the workspace is back to normal, which will be after the
        // current frame.
        post(dragView::resumeColorExtraction);
    };
    dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, DRAG_VIEW_DROP_DURATION, Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) DragView(com.android.launcher3.dragndrop.DragView)

Example 12 with DragOptions

use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method startDrag.

public void startDrag(CellLayout.CellInfo cellInfo, DragOptions options) {
    View child = cellInfo.cell;
    mDragInfo = cellInfo;
    child.setVisibility(INVISIBLE);
    if (options.isAccessibleDrag) {
        mDragController.addDragListener(new AccessibleDragListenerAdapter(this, WorkspaceAccessibilityHelper::new) {

            @Override
            protected void enableAccessibleDrag(boolean enable) {
                super.enableAccessibleDrag(enable);
                setEnableForLayout(mLauncher.getHotseat(), enable);
            }
        });
    }
    beginDragShared(child, this, options);
}
Also used : AccessibleDragListenerAdapter(com.android.launcher3.accessibility.AccessibleDragListenerAdapter) 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)

Example 13 with DragOptions

use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method onDragStart.

@Override
public void onDragStart(DragObject dragObject, DragOptions options) {
    if (ENFORCE_DRAG_EVENT_ORDER) {
        enforceDragParity("onDragStart", 0, 0);
    }
    if (mDragInfo != null && mDragInfo.cell != null) {
        CellLayout layout = (CellLayout) (mDragInfo.cell instanceof LauncherAppWidgetHostView ? dragObject.dragView.getContentViewParent().getParent() : mDragInfo.cell.getParent().getParent());
        layout.markCellsAsUnoccupiedForView(mDragInfo.cell);
    }
    updateChildrenLayersEnabled();
    // Do not add a new page if it is a accessible drag which was not started by the workspace.
    // We do not support accessibility drag from other sources and instead provide a direct
    // action for move/add to homescreen.
    // When a accessible drag is started by the folder, we only allow rearranging withing the
    // folder.
    boolean addNewPage = !(options.isAccessibleDrag && dragObject.dragSource != this);
    if (addNewPage) {
        mDeferRemoveExtraEmptyScreen = false;
        addExtraEmptyScreenOnDrag(dragObject);
        if (dragObject.dragInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && dragObject.dragSource != this) {
            // When dragging a widget from different source, move to a page which has
            // enough space to place this widget (after rearranging/resizing). We special case
            // widgets as they cannot be placed inside a folder.
            // Start at the current page and search right (on LTR) until finding a page with
            // enough space. Since an empty screen is the furthest right, a page must be found.
            int currentPage = getDestinationPage();
            for (int pageIndex = currentPage; pageIndex < getPageCount(); pageIndex++) {
                CellLayout page = (CellLayout) getPageAt(pageIndex);
                if (page.hasReorderSolution(dragObject.dragInfo)) {
                    setCurrentPage(pageIndex);
                    break;
                }
            }
        }
    }
    // Always enter the spring loaded mode
    mLauncher.getStateManager().goToState(SPRING_LOADED);
    mStatsLogManager.logger().withItemInfo(dragObject.dragInfo).withInstanceId(dragObject.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DRAG_STARTED);
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 14 with DragOptions

use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method beginDragShared.

/**
 * Core functionality for beginning a drag operation for an item that will be dropped within
 * the workspace
 */
public DragView beginDragShared(View child, DraggableView draggableView, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    // Clear the pressed state if necessary
    child.clearFocus();
    child.setPressed(false);
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    mOutlineProvider = previewProvider;
    if (draggableView == null && child instanceof DraggableView) {
        draggableView = (DraggableView) child;
    }
    final View contentView = previewProvider.getContentView();
    final float scale;
    // The draggable drawable follows the touch point around on the screen
    final Drawable drawable;
    if (contentView == null) {
        drawable = previewProvider.createDrawable();
        scale = previewProvider.getScaleAndPosition(drawable, mTempXY);
    } else {
        drawable = null;
        scale = previewProvider.getScaleAndPosition(contentView, mTempXY);
    }
    int halfPadding = previewProvider.previewPadding / 2;
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    Point dragVisualizeOffset = null;
    Rect dragRect = new Rect();
    if (draggableView != null) {
        draggableView.getSourceVisualDragBounds(dragRect);
        dragLayerY += dragRect.top;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
        }
    }
    final DragView dv;
    if (contentView instanceof View) {
        if (contentView instanceof LauncherAppWidgetHostView) {
            mDragController.addDragListener(new AppWidgetHostViewDragListener(mLauncher));
        }
        dv = mDragController.startDrag(contentView, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    } else {
        dv = mDragController.startDrag(drawable, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    }
    return dv;
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) 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) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) AppWidgetHostViewDragListener(com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 15 with DragOptions

use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherAccessibilityDelegate method beginAccessibleDrag.

private boolean beginAccessibleDrag(View item, ItemInfo info, boolean fromKeyboard) {
    if (!itemSupportsAccessibleDrag(info)) {
        return false;
    }
    mDragInfo = new DragInfo();
    mDragInfo.info = info;
    mDragInfo.item = item;
    mDragInfo.dragType = DragType.ICON;
    if (info instanceof FolderInfo) {
        mDragInfo.dragType = DragType.FOLDER;
    } else if (info instanceof LauncherAppWidgetInfo) {
        mDragInfo.dragType = DragType.WIDGET;
    }
    Rect pos = new Rect();
    mLauncher.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
    mLauncher.getDragController().addDragListener(this);
    DragOptions options = new DragOptions();
    options.isAccessibleDrag = true;
    options.isKeyboardDrag = fromKeyboard;
    options.simulatedDndStartPoint = new Point(pos.centerX(), pos.centerY());
    if (fromKeyboard) {
        KeyboardDragAndDropView popup = (KeyboardDragAndDropView) mLauncher.getLayoutInflater().inflate(R.layout.keyboard_drag_and_drop, mLauncher.getDragLayer(), false);
        popup.showForIcon(item, info, options);
    } else {
        ItemLongClickListener.beginDrag(item, mLauncher, info, options);
    }
    return true;
}
Also used : DragOptions(com.android.launcher3.dragndrop.DragOptions) Rect(android.graphics.Rect) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) KeyboardDragAndDropView(com.android.launcher3.keyboard.KeyboardDragAndDropView) Point(android.graphics.Point) FolderInfo(com.android.launcher3.model.data.FolderInfo)

Aggregations

Point (android.graphics.Point)7 Rect (android.graphics.Rect)6 View (android.view.View)5 AppWidgetHostView (android.appwidget.AppWidgetHostView)4 DragOptions (com.android.launcher3.dragndrop.DragOptions)4 DragView (com.android.launcher3.dragndrop.DragView)4 DraggableView (com.android.launcher3.dragndrop.DraggableView)4 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)4 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)4 SuppressLint (android.annotation.SuppressLint)3 Launcher (com.android.launcher3.Launcher)3 ItemInfo (com.android.launcher3.model.data.ItemInfo)3 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)3 Drawable (android.graphics.drawable.Drawable)2 CellLayout (com.android.launcher3.CellLayout)2 DeviceProfile (com.android.launcher3.DeviceProfile)2 DropTarget (com.android.launcher3.DropTarget)2 AccessibleDragListenerAdapter (com.android.launcher3.accessibility.AccessibleDragListenerAdapter)2 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)2 AppWidgetHostViewDragListener (com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener)2