Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 125e1218 authored by Brandon Dayauon's avatar Brandon Dayauon Committed by Android (Google) Code Review
Browse files

Merge "Separate animations and add dragOffSet points in dragOptions" into udc-dev

parents 5ed0d0ce e63401e7
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im

                @Override
                public boolean shouldStartDrag(double distanceDragged) {
                    return mDragView != null && mDragView.isAnimationFinished();
                    return mDragView != null && mDragView.isScaleAnimationFinished();
                }

                @Override
@@ -231,7 +231,6 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
                dragLayerY,
                (View target, DropTarget.DragObject d, boolean success) -> {} /* DragSource */,
                (ItemInfo) btv.getTag(),
                /* dragVisualizeOffset = */ null,
                dragRect,
                scale * iconScale,
                scale,
@@ -241,7 +240,7 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
    @Override
    protected DragView startDrag(@Nullable Drawable drawable, @Nullable View view,
            DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source,
            ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale,
            ItemInfo dragInfo, Rect dragRegion, float initialDragViewScale,
            float dragViewScaleOnDrop, DragOptions options) {
        mOptions = options;

+9 −5
Original line number Diff line number Diff line
@@ -1661,17 +1661,14 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
            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);
        }


@@ -1689,6 +1686,15 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
            }
        }

        if (dragOptions.preDragCondition != null) {
            int xDragOffSet = dragOptions.preDragCondition.getDragOffset().x;
            int yDragOffSet = dragOptions.preDragCondition.getDragOffset().y;
            if (xDragOffSet != 0 || yDragOffSet != 0) {
                dragLayerX += xDragOffSet;
                dragLayerY += yDragOffSet;
            }
        }

        final DragView dv;
        if (contentView instanceof View) {
            if (contentView instanceof LauncherAppWidgetHostView) {
@@ -1701,7 +1707,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
                    dragLayerY,
                    source,
                    dragObject,
                    dragVisualizeOffset,
                    dragRect,
                    scale * iconScale,
                    scale,
@@ -1714,7 +1719,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
                    dragLayerY,
                    source,
                    dragObject,
                    dragVisualizeOffset,
                    dragRect,
                    scale * iconScale,
                    scale,
+4 −9
Original line number Diff line number Diff line
@@ -143,14 +143,12 @@ public abstract class DragController<T extends ActivityContext>
            int dragLayerY,
            DragSource source,
            ItemInfo dragInfo,
            Point dragOffset,
            Rect dragRegion,
            float initialDragViewScale,
            float dragViewScaleOnDrop,
            DragOptions options) {
        return startDrag(drawable, /* view= */ null, originalView, dragLayerX, dragLayerY,
                source, dragInfo, dragOffset, dragRegion, initialDragViewScale, dragViewScaleOnDrop,
                options);
        return startDrag(drawable, /* view= */ null, originalView, dragLayerX, dragLayerY, source,
                dragInfo, dragRegion, initialDragViewScale, dragViewScaleOnDrop, options);
    }

    /**
@@ -180,14 +178,12 @@ public abstract class DragController<T extends ActivityContext>
            int dragLayerY,
            DragSource source,
            ItemInfo dragInfo,
            Point dragOffset,
            Rect dragRegion,
            float initialDragViewScale,
            float dragViewScaleOnDrop,
            DragOptions options) {
        return startDrag(/* drawable= */ null, view, originalView, dragLayerX, dragLayerY,
                source, dragInfo, dragOffset, dragRegion, initialDragViewScale, dragViewScaleOnDrop,
                options);
        return startDrag(/* drawable= */ null, view, originalView, dragLayerX, dragLayerY, source,
                dragInfo, dragRegion, initialDragViewScale, dragViewScaleOnDrop, options);
    }

    protected abstract DragView startDrag(
@@ -198,7 +194,6 @@ public abstract class DragController<T extends ActivityContext>
            int dragLayerY,
            DragSource source,
            ItemInfo dragInfo,
            Point dragOffset,
            Rect dragRegion,
            float initialDragViewScale,
            float dragViewScaleOnDrop,
+7 −0
Original line number Diff line number Diff line
@@ -78,5 +78,12 @@ public class DragOptions {
         *                    This will be true if the condition was met, otherwise false.
         */
        void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted);

        /**
         * The offset points that should be overridden to update the dragLayer.
         */
        default Point getDragOffset() {
            return new Point(0,0);
        }
    }
}
+36 −23
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Path;
import android.graphics.Picture;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
@@ -89,15 +88,17 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram

    private final RunnableList mOnDragStartCallback = new RunnableList();

    private Point mDragVisualizeOffset = null;
    private boolean mHasDragOffset;
    private Rect mDragRegion = null;
    protected final T mActivity;
    private final BaseDragLayer<T> mDragLayer;
    private boolean mHasDrawn = false;

    final ValueAnimator mAnim;
    final ValueAnimator mScaleAnim;
    final ValueAnimator mShiftAnim;

    // Whether mAnim has started. Unlike mAnim.isStarted(), this is true even after mAnim ends.
    private boolean mAnimStarted;
    private boolean mScaleAnimStarted;
    private Runnable mOnAnimEndCallback = null;

    private int mLastTouchX;
@@ -166,9 +167,9 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
        setScaleY(initialScale);

        // Animate the view into the correct position
        mAnim = ValueAnimator.ofFloat(0f, 1f);
        mAnim.setDuration(VIEW_ZOOM_DURATION);
        mAnim.addUpdateListener(animation -> {
        mScaleAnim = ValueAnimator.ofFloat(0f, 1f);
        mScaleAnim.setDuration(VIEW_ZOOM_DURATION);
        mScaleAnim.addUpdateListener(animation -> {
            final float value = (Float) animation.getAnimatedValue();
            setScaleX(Utilities.mapRange(value, initialScale, mEndScale));
            setScaleY(Utilities.mapRange(value, initialScale, mEndScale));
@@ -176,10 +177,10 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
                animation.cancel();
            }
        });
        mAnim.addListener(new AnimatorListenerAdapter() {
        mScaleAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                mAnimStarted = true;
                mScaleAnimStarted = true;
            }

            @Override
@@ -190,6 +191,8 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
                }
            }
        });
        // Set up the shift animator.
        mShiftAnim = ValueAnimator.ofFloat(0f, 1f);

        setDragRegion(new Rect(0, 0, width, height));

@@ -319,12 +322,12 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
        return mDragRegion.height();
    }

    public void setDragVisualizeOffset(Point p) {
        mDragVisualizeOffset = p;
    public void setHasDragOffset(boolean hasDragOffset) {
        mHasDragOffset = hasDragOffset;
    }

    public Point getDragVisualizeOffset() {
        return mDragVisualizeOffset;
    public boolean getHasDragOffset() {
        return mHasDragOffset;
    }

    public void setDragRegion(Rect r) {
@@ -392,22 +395,29 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram

        if (mContent != null) {
            // At the drag start, the source view visibility is set to invisible.
            if (getHasDragOffset()) {
                // If there is any dragOffset, this means the content will show away of the original
                // icon location, otherwise it's fine since original content would just show at the
                // same spot.
                mContent.setVisibility(INVISIBLE);
            } else {
                mContent.setVisibility(VISIBLE);
            }
        }

        move(touchX, touchY);
        // Post the animation to skip other expensive work happening on the first frame
        post(mAnim::start);
        post(mScaleAnim::start);
    }

    public void cancelAnimation() {
        if (mAnim != null && mAnim.isRunning()) {
            mAnim.cancel();
        if (mScaleAnim != null && mScaleAnim.isRunning()) {
            mScaleAnim.cancel();
        }
    }

    public boolean isAnimationFinished() {
        return mAnimStarted && !mAnim.isRunning();
    public boolean isScaleAnimationFinished() {
        return mScaleAnimStarted && !mScaleAnim.isRunning();
    }

    /**
@@ -434,13 +444,15 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
            int duration);

    public void animateShift(final int shiftX, final int shiftY) {
        if (mAnim.isStarted()) {
            return;
        }
        if (mShiftAnim.isStarted()) return;

        // Set mContent visibility to visible to show icon regardless in case it is INVISIBLE.
        if (mContent != null) mContent.setVisibility(VISIBLE);

        mAnimatedShiftX = shiftX;
        mAnimatedShiftY = shiftY;
        applyTranslation();
        mAnim.addUpdateListener(new AnimatorUpdateListener() {
        mShiftAnim.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float fraction = 1 - animation.getAnimatedFraction();
@@ -449,6 +461,7 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
                applyTranslation();
            }
        });
        mShiftAnim.start();
    }

    private void applyTranslation() {
Loading