Handing pin item drag when workspce is not loaded
While the launcher is loading, the drag view is displayed with a gray tint.
The drag is started, as soon as the workspace is unlocked
Bug: 33584624
Change-Id: I4013ea8b987ec305e73742b194f9e96af761cc35
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index 80c2860..5a5e7d0 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -221,7 +221,7 @@
if (!mIsInPreDrag) {
callOnDragStart();
} else if (mOptions.preDragCondition != null) {
- mOptions.preDragCondition.onPreDragStart();
+ mOptions.preDragCondition.onPreDragStart(mDragObject);
}
mLastTouch[0] = mMotionDownX;
@@ -236,7 +236,7 @@
listener.onDragStart(mDragObject, mOptions);
}
if (mOptions.preDragCondition != null) {
- mOptions.preDragCondition.onPreDragEnd(true /* dragStarted*/);
+ mOptions.preDragCondition.onPreDragEnd(mDragObject, true /* dragStarted*/);
}
mIsInPreDrag = false;
}
@@ -335,7 +335,7 @@
private void callOnDragEnd() {
if (mIsInPreDrag && mOptions.preDragCondition != null) {
- mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/);
+ mOptions.preDragCondition.onPreDragEnd(mDragObject, false /* dragStarted*/);
}
mIsInPreDrag = false;
mOptions = null;
diff --git a/src/com/android/launcher3/dragndrop/DragOptions.java b/src/com/android/launcher3/dragndrop/DragOptions.java
index 906855a..230fa2d 100644
--- a/src/com/android/launcher3/dragndrop/DragOptions.java
+++ b/src/com/android/launcher3/dragndrop/DragOptions.java
@@ -20,6 +20,8 @@
import android.support.annotation.CallSuper;
import android.view.View;
+import com.android.launcher3.DropTarget;
+
/**
* Set of options to control the drag and drop behavior.
*/
@@ -52,7 +54,7 @@
* The pre-drag has started, but onDragStart() is
* deferred until shouldStartDrag() returns true.
*/
- void onPreDragStart();
+ void onPreDragStart(DropTarget.DragObject dragObject);
/**
* The pre-drag has ended. This gets called at the same time as onDragStart()
@@ -60,6 +62,6 @@
* @param dragStarted Whether the pre-drag ended because the actual drag started.
* This will be true if the condition was met, otherwise false.
*/
- void onPreDragEnd(boolean dragStarted);
+ void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted);
}
}
diff --git a/src/com/android/launcher3/dragndrop/PinItemDragListener.java b/src/com/android/launcher3/dragndrop/PinItemDragListener.java
index 1a99cc8..4fc08bd 100644
--- a/src/com/android/launcher3/dragndrop/PinItemDragListener.java
+++ b/src/com/android/launcher3/dragndrop/PinItemDragListener.java
@@ -40,6 +40,7 @@
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.PendingAddItemInfo;
+import com.android.launcher3.R;
import com.android.launcher3.compat.PinItemRequestCompat;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.graphics.LauncherIcons;
@@ -55,7 +56,8 @@
* {@link DragSource} for handling drop from from a different window. This object is initialized
* in the source window and is passed on to the Launcher activity as an Intent extra.
*/
-public class PinItemDragListener implements Parcelable, View.OnDragListener, DragSource {
+public class PinItemDragListener
+ implements Parcelable, View.OnDragListener, DragSource, DragOptions.PreDragCondition {
private static final String TAG = "PinItemDragListener";
@@ -134,11 +136,6 @@
return false;
}
- if (mLauncher.isWorkspaceLocked()) {
- // TODO: implement wait
- return false;
- }
-
final PendingAddItemInfo item;
final Bitmap preview;
@@ -188,6 +185,7 @@
Point downPos = new Point((int) event.getX(), (int) event.getY());
DragOptions options = new DragOptions();
options.systemDndStartPoint = downPos;
+ options.preDragCondition = this;
int x = downPos.x + dragShift.x;
int y = downPos.y + dragShift.y;
@@ -198,6 +196,30 @@
}
@Override
+ public boolean shouldStartDrag(double distanceDragged) {
+ // Stay in pre-drag mode, if workspace is locked.
+ return !mLauncher.isWorkspaceLocked();
+ }
+
+ @Override
+ public void onPreDragStart(DropTarget.DragObject dragObject) {
+ // The predrag starts when the workspace is not yet loaded. In some cases we set
+ // the dragLayer alpha to 0 to have a nice fade-in animation. But that will prevent the
+ // dragView from being visible. Instead just skip the fade-in animation here.
+ mLauncher.getDragLayer().setAlpha(1);
+
+ dragObject.dragView.setColor(
+ mLauncher.getResources().getColor(R.color.delete_target_hover_tint));
+ }
+
+ @Override
+ public void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted) {
+ if (dragStarted) {
+ dragObject.dragView.setColor(0);
+ }
+ }
+
+ @Override
public boolean supportsAppInfoDropTarget() {
return false;
}
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index 95d51dc..0fc6c16 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -474,12 +474,12 @@
}
@Override
- public void onPreDragStart() {
+ public void onPreDragStart(DropTarget.DragObject dragObject) {
mOriginalIcon.setVisibility(INVISIBLE);
}
@Override
- public void onPreDragEnd(boolean dragStarted) {
+ public void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted) {
if (!dragStarted) {
mOriginalIcon.setVisibility(VISIBLE);
mLauncher.getUserEventDispatcher().logDeepShortcutsOpen(mOriginalIcon);