summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/dragndrop/DragController.java
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2016-09-28 12:49:25 -0700
committerTony Wickham <twickham@google.com>2016-10-04 12:26:35 -0700
commit10236d6ac7f5f787ca21736494ccb5eaf2bd7c27 (patch)
tree5caed1278efbd05aa9a99f5be8afd38e025569b3 /src/com/android/launcher3/dragndrop/DragController.java
parent59769e3331f36fd63134825b5155035e32413469 (diff)
downloadandroid_packages_apps_Trebuchet-10236d6ac7f5f787ca21736494ccb5eaf2bd7c27.tar.gz
android_packages_apps_Trebuchet-10236d6ac7f5f787ca21736494ccb5eaf2bd7c27.tar.bz2
android_packages_apps_Trebuchet-10236d6ac7f5f787ca21736494ccb5eaf2bd7c27.zip
Update pre-drag lifecycle for apps with shortcuts.
- First of all, deferred drag has been renamed to pre-drag to avoid confusion with the existing deferred end drag. - For normal drags, the cycle is still startDrag --> onDragStart --> onDrop --> onDropComplete --> onDragEnd. - Pre-drags have two additional callbacks: onPreDragStart and onPreDragEnd. onPreDragStart is called between startDrag and onDragStart, and onPreDragEnd is called at the same time as onDragStart or onDragEnd. - If the pre-drag has not transitioned to a full drag before onDragEnd, onDragStart and onDropComplete are skipped (onDrop is still called to allow the DragView to animate). Change-Id: Icd7a8f75d5fcc159f9a52758c22ab6eae3edb9e2
Diffstat (limited to 'src/com/android/launcher3/dragndrop/DragController.java')
-rw-r--r--src/com/android/launcher3/dragndrop/DragController.java77
1 files changed, 46 insertions, 31 deletions
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index c7b66e7bd..19a47e873 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -131,7 +131,7 @@ public class DragController implements DragDriver.EventListener, TouchController
protected final int mFlingToDeleteThresholdVelocity;
private VelocityTracker mVelocityTracker;
- private boolean mIsDragDeferred;
+ private boolean mIsInPreDrag;
/**
* Interface to receive notifications when a drag starts or stops
@@ -230,13 +230,14 @@ public class DragController implements DragDriver.EventListener, TouchController
mDragObject = new DropTarget.DragObject();
- mIsDragDeferred = !mOptions.deferDragCondition.shouldStartDeferredDrag(0);
+ mIsInPreDrag = mOptions.preDragCondition != null
+ && !mOptions.preDragCondition.shouldStartDrag(0);
final Resources res = mLauncher.getResources();
final float scaleDps = FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND
? res.getDimensionPixelSize(R.dimen.dragViewScale)
- : mIsDragDeferred
- ? res.getDimensionPixelSize(R.dimen.deferred_drag_view_scale)
+ : mIsInPreDrag
+ ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale)
: 0f;
final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
registrationY, initialDragViewScale, scaleDps);
@@ -271,10 +272,10 @@ public class DragController implements DragDriver.EventListener, TouchController
dragView.show(mMotionDownX, mMotionDownY);
mDistanceSinceScroll = 0;
- if (!mIsDragDeferred) {
- startDeferredDrag();
- } else {
- mOptions.deferDragCondition.onDeferredDragStart();
+ if (!mIsInPreDrag) {
+ callOnDragStart();
+ } else if (mOptions.preDragCondition != null) {
+ mOptions.preDragCondition.onPreDragStart();
}
mLastTouch[0] = mMotionDownX;
@@ -284,16 +285,18 @@ public class DragController implements DragDriver.EventListener, TouchController
return dragView;
}
- public boolean isDeferringDrag() {
- return mIsDragDeferred;
- }
-
- public void startDeferredDrag() {
+ private void callOnDragStart() {
for (DragListener listener : new ArrayList<>(mListeners)) {
listener.onDragStart(mDragObject, mOptions);
}
- mOptions.deferDragCondition.onDragStart();
- mIsDragDeferred = false;
+ if (mOptions.preDragCondition != null) {
+ mOptions.preDragCondition.onPreDragEnd(true /* dragStarted*/);
+ }
+ mIsInPreDrag = false;
+ }
+
+ public boolean isInPreDrag() {
+ return mIsInPreDrag;
}
/**
@@ -329,7 +332,9 @@ public class DragController implements DragDriver.EventListener, TouchController
mDragObject.deferDragViewCleanupPostAnimation = false;
mDragObject.cancelled = true;
mDragObject.dragComplete = true;
- mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
+ if (!mIsInPreDrag) {
+ mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
+ }
}
endDrag();
}
@@ -350,7 +355,6 @@ public class DragController implements DragDriver.EventListener, TouchController
private void endDrag() {
if (isDragging()) {
mDragDriver = null;
- mOptions = null;
clearScrollRunnable();
boolean isDeferred = false;
if (mDragObject.dragView != null) {
@@ -363,15 +367,24 @@ public class DragController implements DragDriver.EventListener, TouchController
// Only end the drag if we are not deferred
if (!isDeferred) {
- for (DragListener listener : new ArrayList<>(mListeners)) {
- listener.onDragEnd();
- }
+ callOnDragEnd();
}
}
releaseVelocityTracker();
}
+ private void callOnDragEnd() {
+ if (mIsInPreDrag && mOptions.preDragCondition != null) {
+ mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/);
+ }
+ mIsInPreDrag = false;
+ mOptions = null;
+ for (DragListener listener : new ArrayList<>(mListeners)) {
+ listener.onDragEnd();
+ }
+ }
+
/**
* This only gets called as a result of drag view cleanup being deferred in endDrag();
*/
@@ -380,9 +393,7 @@ public class DragController implements DragDriver.EventListener, TouchController
if (mDragObject.deferDragViewCleanupPostAnimation) {
// If we skipped calling onDragEnd() before, do it now
- for (DragListener listener : new ArrayList<>(mListeners)) {
- listener.onDragEnd();
- }
+ callOnDragEnd();
}
}
@@ -536,9 +547,9 @@ public class DragController implements DragDriver.EventListener, TouchController
mLastTouch[1] = y;
checkScrollState(x, y);
- if (mIsDragDeferred && mOptions.deferDragCondition.shouldStartDeferredDrag(
- Math.hypot(x - mMotionDownX, y - mMotionDownY))) {
- startDeferredDrag();
+ if (mIsInPreDrag && mOptions.preDragCondition != null
+ && mOptions.preDragCondition.shouldStartDrag(mDistanceSinceScroll)) {
+ callOnDragStart();
}
}
@@ -701,7 +712,7 @@ public class DragController implements DragDriver.EventListener, TouchController
(vec1.length() * vec2.length()));
}
- void drop(DropTarget dropTarget, float x, float y, PointF flingVel) {
+ private void drop(DropTarget dropTarget, float x, float y, PointF flingVel) {
final int[] coordinates = mCoordinatesTemp;
mDragObject.x = coordinates[0];
@@ -734,11 +745,15 @@ 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);
- if (mIsDragDeferred) {
- mOptions.deferDragCondition.onDropBeforeDeferredDrag();
+ if (!mIsInPreDrag) {
+ mDragObject.dragSource.onDropCompleted(
+ dropTargetAsView, mDragObject, flingVel != null, accepted);
+ } else {
+ // Only defer the drag view cleanup if the drag source handles the drop.
+ if (!(mDragObject.dragSource instanceof DropTarget)) {
+ mDragObject.deferDragViewCleanupPostAnimation = false;
+ }
}
}