diff options
Diffstat (limited to 'src/com/android/launcher3/dragndrop/DragController.java')
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragController.java | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index 9da1cb313..a93ee9019 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -25,7 +25,6 @@ import android.graphics.PointF; import android.graphics.Rect; import android.os.Handler; import android.os.IBinder; -import android.util.Log; import android.view.DragEvent; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; @@ -43,7 +42,6 @@ import com.android.launcher3.PagedView; import com.android.launcher3.R; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.Utilities; -import com.android.launcher3.Workspace; import com.android.launcher3.accessibility.DragViewStateAnnouncer; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.ItemInfoMatcher; @@ -51,7 +49,6 @@ import com.android.launcher3.util.Thunk; import com.android.launcher3.util.TouchController; import java.util.ArrayList; -import java.util.HashSet; /** * Class for initiating a drag within a view or across multiple views. @@ -59,12 +56,6 @@ import java.util.HashSet; public class DragController implements DragDriver.EventListener, TouchController { private static final String TAG = "Launcher.DragController"; - /** Indicates the drag is a move. */ - public static int DRAG_ACTION_MOVE = 0; - - /** Indicates the drag is a copy. */ - public static int DRAG_ACTION_COPY = 1; - public static final int SCROLL_DELAY = 500; public static final int RESCROLL_DELAY = PagedView.PAGE_SNAP_ANIMATION_DURATION + 150; @@ -93,8 +84,8 @@ public class DragController implements DragDriver.EventListener, TouchController */ private DragDriver mDragDriver = null; - /** Whether or not an accessible drag operation is in progress. */ - private boolean mIsAccessibleDrag; + /** Options controlling the drag behavior. */ + private DragOptions mOptions; /** X coordinate of the down event. */ private int mMotionDownX; @@ -147,12 +138,10 @@ public class DragController implements DragDriver.EventListener, TouchController /** * A drag has begun * - * @param source An object representing where the drag originated - * @param info The data associated with the object that is being dragged - * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE} - * or {@link DragController#DRAG_ACTION_COPY} + * @param dragObject The object being dragged + * @param options Options used to start the drag */ - void onDragStart(DragSource source, ItemInfo info, int dragAction); + void onDragStart(DropTarget.DragObject dragObject, DragOptions options); /** * The drag has ended @@ -162,8 +151,6 @@ public class DragController implements DragDriver.EventListener, TouchController /** * Used to create a new DragLayer from XML. - * - * @param context The application's context. */ public DragController(Launcher launcher) { Resources r = launcher.getResources(); @@ -185,11 +172,9 @@ public class DragController implements DragDriver.EventListener, TouchController * @param source An object representing where the drag originated * @param dragInfo The data associated with the object that is being dragged * @param viewImageBounds the position of the image inside the view - * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or - * {@link #DRAG_ACTION_COPY} */ public void startDrag(View v, Bitmap bmp, DragSource source, ItemInfo dragInfo, - Rect viewImageBounds, int dragAction, float initialDragViewScale) { + Rect viewImageBounds, float initialDragViewScale, DragOptions options) { int[] loc = mCoordinatesTemp; mLauncher.getDragLayer().getLocationInDragLayer(v, loc); int dragLayerX = loc[0] + viewImageBounds.left @@ -197,12 +182,8 @@ public class DragController implements DragDriver.EventListener, TouchController int dragLayerY = loc[1] + viewImageBounds.top + (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2); - startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, - null, initialDragViewScale, false); - - if (dragAction == DRAG_ACTION_MOVE) { - v.setVisibility(View.GONE); - } + startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, null, + null, initialDragViewScale, options); } /** @@ -214,15 +195,12 @@ public class DragController implements DragDriver.EventListener, TouchController * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap. * @param source An object representing where the drag originated * @param dragInfo The data associated with the object that is being dragged - * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or - * {@link #DRAG_ACTION_COPY} * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. * Makes dragging feel more precise, e.g. you can clip out a transparent border - * @param accessible whether this drag should occur in accessibility mode */ public DragView startDrag(Bitmap b, int dragLayerX, int dragLayerY, - DragSource source, ItemInfo dragInfo, int dragAction, Point dragOffset, Rect dragRegion, - float initialDragViewScale, boolean accessible) { + DragSource source, ItemInfo dragInfo, Point dragOffset, Rect dragRegion, + float initialDragViewScale, DragOptions options) { if (PROFILE_DRAWING_DURING_DRAG) { android.os.Debug.startMethodTracing("Launcher"); } @@ -234,8 +212,10 @@ public class DragController implements DragDriver.EventListener, TouchController } mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0); - for (DragListener listener : mListeners) { - listener.onDragStart(source, dragInfo, dragAction); + mOptions = options; + if (mOptions.systemDndStartPoint != null) { + mMotionDownX = mOptions.systemDndStartPoint.x; + mMotionDownY = mOptions.systemDndStartPoint.y; } final int registrationX = mMotionDownX - dragLayerX; @@ -244,7 +224,6 @@ public class DragController implements DragDriver.EventListener, TouchController final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left; final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top; - mIsAccessibleDrag = accessible; mLastDropTarget = null; mDragObject = new DropTarget.DragObject(); @@ -256,7 +235,7 @@ public class DragController implements DragDriver.EventListener, TouchController registrationY, initialDragViewScale, scaleDps); mDragObject.dragComplete = false; - if (mIsAccessibleDrag) { + if (mOptions.isAccessibleDrag) { // For an accessible drag, we assume the view is being dragged from the center. mDragObject.xOffset = b.getWidth() / 2; mDragObject.yOffset = b.getHeight() / 2; @@ -266,11 +245,13 @@ public class DragController implements DragDriver.EventListener, TouchController mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop); mDragObject.stateAnnouncer = DragViewStateAnnouncer.createFor(dragView); - mDragDriver = DragDriver.create(this, dragInfo, dragView); + mDragDriver = DragDriver.create(mLauncher, this, mDragObject, mOptions); } mDragObject.dragSource = source; mDragObject.dragInfo = dragInfo; + mDragObject.originalDragInfo = new ItemInfo(); + mDragObject.originalDragInfo.copyFrom(dragInfo); if (dragOffset != null) { dragView.setDragVisualizeOffset(new Point(dragOffset)); @@ -282,9 +263,15 @@ public class DragController implements DragDriver.EventListener, TouchController mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); dragView.show(mMotionDownX, mMotionDownY); mDistanceSinceScroll = 0; + + for (DragListener listener : new ArrayList<>(mListeners)) { + listener.onDragStart(mDragObject, mOptions); + } + mLastTouch[0] = mMotionDownX; mLastTouch[1] = mMotionDownY; handleMoveEvent(mMotionDownX, mMotionDownY); + mLauncher.getUserEventDispatcher().resetActionDurationMillis(); return dragView; } @@ -307,7 +294,11 @@ public class DragController implements DragDriver.EventListener, TouchController } public boolean isDragging() { - return mDragDriver != null || mIsAccessibleDrag; + return mDragDriver != null || (mOptions != null && mOptions.isAccessibleDrag); + } + + public boolean isExternalDrag() { + return (mOptions != null && mOptions.systemDndStartPoint != null); } /** @@ -342,7 +333,7 @@ public class DragController implements DragDriver.EventListener, TouchController private void endDrag() { if (isDragging()) { mDragDriver = null; - mIsAccessibleDrag = false; + mOptions = null; clearScrollRunnable(); boolean isDeferred = false; if (mDragObject.dragView != null) { @@ -421,10 +412,6 @@ public class DragController implements DragDriver.EventListener, TouchController @Override public void onDriverDragEnd(float x, float y, DropTarget dropTargetOverride) { - final int[] dragLayerPos = getClampedDragLayerPos(x, y); - final int dragLayerX = dragLayerPos[0]; - final int dragLayerY = dragLayerPos[1]; - DropTarget dropTarget; PointF vec = null; @@ -453,14 +440,7 @@ public class DragController implements DragDriver.EventListener, TouchController * Call this from a drag source view. */ public boolean onInterceptTouchEvent(MotionEvent ev) { - @SuppressWarnings("all") // suppress dead code warning - final boolean debug = false; - if (debug) { - Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " Dragging=" - + (mDragDriver != null)); - } - - if (mIsAccessibleDrag) { + if (mOptions != null && mOptions.isAccessibleDrag) { return false; } @@ -507,7 +487,7 @@ public class DragController implements DragDriver.EventListener, TouchController */ public void setMoveTarget(View view) { mMoveTarget = view; - } + } public boolean dispatchUnhandledMove(View focused, int direction) { return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction); @@ -603,7 +583,7 @@ public class DragController implements DragDriver.EventListener, TouchController * Call this from a drag source view. */ public boolean onTouchEvent(MotionEvent ev) { - if (mDragDriver == null || mIsAccessibleDrag) { + if (mDragDriver == null || mOptions == null || mOptions.isAccessibleDrag) { return false; } @@ -734,6 +714,7 @@ public class DragController implements DragDriver.EventListener, TouchController final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null; mDragObject.dragSource.onDropCompleted( dropTargetAsView, mDragObject, flingVel != null, accepted); + mLauncher.getUserEventDispatcher().logDragNDrop(mDragObject, dropTargetAsView); } private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) { |