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

Commit d07b5cd0 authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Better separation between DragDriver and DragController" into ub-launcher3-master

parents a454d4a3 ca51dcd6
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import java.util.HashSet;
/**
 * Class for initiating a drag within a view or across multiple views.
 */
public class DragController {
public class DragController implements DragDriver.EventListener {
    private static final String TAG = "Launcher.DragController";

    /** Indicates the drag is a move.  */
@@ -91,7 +91,7 @@ public class DragController {
    /** the area at the edge of the screen that makes the workspace go left
     *   or right while you're dragging.
     */
    private int mScrollZone;
    private final int mScrollZone;

    private DropTarget.DragObject mDragObject;

@@ -123,7 +123,7 @@ public class DragController {
    private int mTmpPoint[] = new int[2];
    private Rect mDragLayerRect = new Rect();

    protected int mFlingToDeleteThresholdVelocity;
    protected final int mFlingToDeleteThresholdVelocity;
    private VelocityTracker mVelocityTracker;

    /**
@@ -341,6 +341,7 @@ public class DragController {
        }
        endDrag();
    }

    public void onAppsRemoved(final ArrayList<String> packageNames, HashSet<ComponentName> cns) {
        // Cancel the current drag if we are removing an app that we are dragging
        if (mDragObject != null) {
@@ -428,18 +429,14 @@ public class DragController {
        mLastTouchUpTime = -1;
    }

    /**
     * Call this from the drag driver.
     */
    @Override
    public void onDriverDragMove(float x, float y) {
        final int[] dragLayerPos = getClampedDragLayerPos(x, y);

        handleMoveEvent(dragLayerPos[0], dragLayerPos[1]);
    }

    /**
     * Call this from the drag driver.
     */
    @Override
    public void onDriverDragEnd(float x, float y, DropTarget dropTargetOverride) {
        final int[] dragLayerPos = getClampedDragLayerPos(x, y);
        final int dragLayerX = dragLayerPos[0];
@@ -467,6 +464,11 @@ public class DragController {
        endDrag();
    }

    @Override
    public void onDriverDragCancel() {
        cancelDrag();
    }

    /**
     * Call this from a drag source view.
     */
+18 −12
Original line number Diff line number Diff line
@@ -28,10 +28,16 @@ import android.view.View;
 * Base class for driving a drag/drop operation.
 */
public abstract class DragDriver {
    protected final DragController mDragController;
    protected final EventListener mEventListener;

    public DragDriver(DragController dragController) {
        mDragController = dragController;
    public interface EventListener {
        void onDriverDragMove(float x, float y);
        void onDriverDragEnd(float x, float y, DropTarget dropTargetOverride);
        void onDriverDragCancel();
    }

    public DragDriver(EventListener eventListener) {
        mEventListener = eventListener;
    }

    /**
@@ -113,7 +119,7 @@ class SystemDragDriver extends DragDriver {

        if (!mDragView.startDrag(dragData, shadowBuilder, null, flags)) {
            mDragging = false;
            mDragController.cancelDrag();
            mEventListener.onDriverDragCancel();
            return;
        }

@@ -151,7 +157,7 @@ class SystemDragDriver extends DragDriver {
            case DragEvent.ACTION_DRAG_LOCATION:
                mLastX = event.getX();
                mLastY = event.getY();
                mDragController.onDriverDragMove(event.getX(), event.getY());
                mEventListener.onDriverDragMove(event.getX(), event.getY());
                return true;

            case DragEvent.ACTION_DROP:
@@ -172,7 +178,7 @@ class SystemDragDriver extends DragDriver {
                final DropTarget dropTargetOverride = acceptedByAnotherWindow ?
                        new AnotherWindowDropTarget(mDragView.getContext()) : null;

                mDragController.onDriverDragEnd(mLastX, mLastY, dropTargetOverride);
                mEventListener.onDriverDragEnd(mLastX, mLastY, dropTargetOverride);
                mDragging = false;
                return true;

@@ -199,14 +205,14 @@ class InternalDragDriver extends DragDriver {

        switch (action) {
            case MotionEvent.ACTION_MOVE:
                mDragController.onDriverDragMove(ev.getX(), ev.getY());
                mEventListener.onDriverDragMove(ev.getX(), ev.getY());
                break;
            case MotionEvent.ACTION_UP:
                mDragController.onDriverDragMove(ev.getX(), ev.getY());
                mDragController.onDriverDragEnd(ev.getX(), ev.getY(), null);
                mEventListener.onDriverDragMove(ev.getX(), ev.getY());
                mEventListener.onDriverDragEnd(ev.getX(), ev.getY(), null);
                break;
            case MotionEvent.ACTION_CANCEL:
                mDragController.cancelDrag();
                mEventListener.onDriverDragCancel();
                break;
        }

@@ -219,10 +225,10 @@ class InternalDragDriver extends DragDriver {

        switch (action) {
            case MotionEvent.ACTION_UP:
                mDragController.onDriverDragEnd(ev.getX(), ev.getY(), null);
                mEventListener.onDriverDragEnd(ev.getX(), ev.getY(), null);
                break;
            case MotionEvent.ACTION_CANCEL:
                mDragController.cancelDrag();
                mEventListener.onDriverDragCancel();
                break;
        }