From ca51dcd6ca154b2fb97c79ab0846e58a6ca0623b Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Tue, 4 Aug 2015 16:10:19 -0700 Subject: [PATCH] Better separation between DragDriver and DragController Now DragDriver uses DragController through DragDriver.EventListener interface. I hope that this will make relations between 2 classes clearer, and will help avoiding mess during future development. Also, some small cleanups. Bug: 22609426 Change-Id: Ibaf61804ab931743f2f913fac11bf24ebf9a36c8 --- src/com/android/launcher3/DragController.java | 20 +++++++------ src/com/android/launcher3/DragDriver.java | 30 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/com/android/launcher3/DragController.java b/src/com/android/launcher3/DragController.java index 53e90fcbca..2b4f019c28 100644 --- a/src/com/android/launcher3/DragController.java +++ b/src/com/android/launcher3/DragController.java @@ -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 packageNames, HashSet 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. */ diff --git a/src/com/android/launcher3/DragDriver.java b/src/com/android/launcher3/DragDriver.java index b4e7bda402..6cd52bd2c1 100644 --- a/src/com/android/launcher3/DragDriver.java +++ b/src/com/android/launcher3/DragDriver.java @@ -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; }