Search in sources :

Example 11 with DragView

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

the class DragLayer method animateViewIntoPosition.

public void animateViewIntoPosition(DragView dragView, final View child, int duration, View anchorView) {
    ShortcutAndWidgetContainer parentChildren = (ShortcutAndWidgetContainer) child.getParent();
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    parentChildren.measureChild(child);
    parentChildren.layoutChild(child);
    Rect dragViewBounds = new Rect();
    getViewRectRelativeToSelf(dragView, dragViewBounds);
    final int fromX = dragViewBounds.left;
    final int fromY = dragViewBounds.top;
    float[] coord = new float[2];
    float childScale = child.getScaleX();
    coord[0] = lp.x + (child.getMeasuredWidth() * (1 - childScale) / 2);
    coord[1] = lp.y + (child.getMeasuredHeight() * (1 - childScale) / 2);
    // Since the child hasn't necessarily been laid out, we force the lp to be updated with
    // the correct coordinates (above) and use these to determine the final location
    float scale = getDescendantCoordRelativeToSelf((View) child.getParent(), coord);
    // We need to account for the scale of the child itself, as the above only accounts for
    // for the scale in parents.
    scale *= childScale;
    int toX = Math.round(coord[0]);
    int toY = Math.round(coord[1]);
    float toScale = scale;
    if (child instanceof DraggableView) {
        // This code is fairly subtle. Please verify drag and drop is pixel-perfect in a number
        // of scenarios before modifying (from all apps, from workspace, different grid-sizes,
        // shortcuts from in and out of Launcher etc).
        DraggableView d = (DraggableView) child;
        Rect destRect = new Rect();
        d.getWorkspaceVisualDragBounds(destRect);
        // In most cases this additional scale factor should be a no-op (1). It mainly accounts
        // for alternate grids where the source and destination icon sizes are different
        toScale *= ((1f * destRect.width()) / (dragView.getMeasuredWidth() - dragView.getBlurSizeOutline()));
        // This accounts for the offset of the DragView created by scaling it about its
        // center as it animates into place.
        float scaleShiftX = dragView.getMeasuredWidth() * (1 - toScale) / 2;
        float scaleShiftY = dragView.getMeasuredHeight() * (1 - toScale) / 2;
        toX += scale * destRect.left - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftX;
        toY += scale * destRect.top - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftY;
    }
    child.setVisibility(INVISIBLE);
    Runnable onCompleteRunnable = () -> child.setVisibility(VISIBLE);
    animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale, onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView);
}
Also used : Rect(android.graphics.Rect) CellLayout(com.android.launcher3.CellLayout) ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer)

Example 12 with DragView

use of com.android.launcher3.dragndrop.DragView 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 13 with DragView

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

the class CellLayout method getViewsIntersectingRegion.

// For a given cell and span, fetch the set of views intersecting the region.
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) {
    if (boundingRect != null) {
        boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
    }
    intersectingViews.clear();
    Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
    Rect r1 = new Rect();
    final int count = mShortcutsAndWidgets.getChildCount();
    for (int i = 0; i < count; i++) {
        View child = mShortcutsAndWidgets.getChildAt(i);
        if (child == dragView)
            continue;
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan);
        if (Rect.intersects(r0, r1)) {
            mIntersectingViews.add(child);
            if (boundingRect != null) {
                boundingRect.union(r1);
            }
        }
    }
}
Also used : Rect(android.graphics.Rect) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 14 with DragView

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

the class CellLayout method animateItemsToSolution.

private void animateItemsToSolution(ItemConfiguration solution, View dragView, boolean commitDragView) {
    GridOccupancy occupied = DESTRUCTIVE_REORDER ? mOccupied : mTmpOccupied;
    occupied.clear();
    int childCount = mShortcutsAndWidgets.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = mShortcutsAndWidgets.getChildAt(i);
        if (child == dragView)
            continue;
        CellAndSpan c = solution.map.get(child);
        if (c != null) {
            animateChildToPosition(child, c.cellX, c.cellY, REORDER_ANIMATION_DURATION, 0, DESTRUCTIVE_REORDER, false);
            occupied.markCells(c, true);
        }
    }
    if (commitDragView) {
        occupied.markCells(solution, true);
    }
}
Also used : CellAndSpan(com.android.launcher3.util.CellAndSpan) GridOccupancy(com.android.launcher3.util.GridOccupancy) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 15 with DragView

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

the class CellLayout method copySolutionToTempState.

private void copySolutionToTempState(ItemConfiguration solution, View dragView) {
    mTmpOccupied.clear();
    int childCount = mShortcutsAndWidgets.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = mShortcutsAndWidgets.getChildAt(i);
        if (child == dragView)
            continue;
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        CellAndSpan c = solution.map.get(child);
        if (c != null) {
            lp.tmpCellX = c.cellX;
            lp.tmpCellY = c.cellY;
            lp.cellHSpan = c.spanX;
            lp.cellVSpan = c.spanY;
            mTmpOccupied.markCells(c, true);
        }
    }
    mTmpOccupied.markCells(solution, true);
}
Also used : CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)14 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)13 SuppressLint (android.annotation.SuppressLint)12 Rect (android.graphics.Rect)11 View (android.view.View)11 DragView (com.android.launcher3.dragndrop.DragView)8 Paint (android.graphics.Paint)7 CellAndSpan (com.android.launcher3.util.CellAndSpan)5 AppWidgetHostView (android.appwidget.AppWidgetHostView)4 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)4 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)4 Drawable (android.graphics.drawable.Drawable)3 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)3 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)3 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 Resources (android.content.res.Resources)2 BubbleTextView (com.android.launcher3.BubbleTextView)2 CellLayout (com.android.launcher3.CellLayout)2 Launcher (com.android.launcher3.Launcher)2 Workspace (com.android.launcher3.Workspace)2