Separate animations and add dragOffSet points in dragOptions
For 1, when animateShift() is called shiftAnimation() is the only thing needed.
2, by having point saved in preDragCondition, we can use that to update the drag layers and not have to
modify registrationX/Y later
Removed dragVisualizedOffset since it does not do anything.
There is an issue that also needs to be fixed if user decides to long click
on a search result and let go, the icon flashes at the touch point when you let go.. so we check when mContent can be shown in DragView
depending on if there is dragOffset.
If there is dragOffset, set mContent to invisible.
If there is no dragOffset, set mContent to visible because it doesn't matter as the original content is at the same spot.
bug: 245659929
test: manual: video: https://drive.google.com/file/d/1JQ0pud31HU0WlrqecX0v1cdPKQ37jQCf/view?usp=sharing
Change-Id: I4d2276b9c43e1e92c45d8538b8dde70baa84a5e8
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
index 72add4f..88fea31 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
@@ -198,7 +198,7 @@
@Override
public boolean shouldStartDrag(double distanceDragged) {
- return mDragView != null && mDragView.isAnimationFinished();
+ return mDragView != null && mDragView.isScaleAnimationFinished();
}
@Override
@@ -231,7 +231,6 @@
dragLayerY,
(View target, DropTarget.DragObject d, boolean success) -> {} /* DragSource */,
(ItemInfo) btv.getTag(),
- /* dragVisualizeOffset = */ null,
dragRect,
scale * iconScale,
scale,
@@ -241,7 +240,7 @@
@Override
protected DragView startDrag(@Nullable Drawable drawable, @Nullable View view,
DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source,
- ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale,
+ ItemInfo dragInfo, Rect dragRegion, float initialDragViewScale,
float dragViewScaleOnDrop, DragOptions options) {
mOptions = options;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 98016f6..2fa1a57 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1661,17 +1661,14 @@
scale = previewProvider.getScaleAndPosition(contentView, mTempXY);
}
- int halfPadding = previewProvider.previewPadding / 2;
int dragLayerX = mTempXY[0];
int dragLayerY = mTempXY[1];
- Point dragVisualizeOffset = null;
Rect dragRect = new Rect();
if (draggableView != null) {
draggableView.getSourceVisualDragBounds(dragRect);
dragLayerY += dragRect.top;
- dragVisualizeOffset = new Point(-halfPadding, halfPadding);
}
@@ -1689,6 +1686,15 @@
}
}
+ if (dragOptions.preDragCondition != null) {
+ int xDragOffSet = dragOptions.preDragCondition.getDragOffset().x;
+ int yDragOffSet = dragOptions.preDragCondition.getDragOffset().y;
+ if (xDragOffSet != 0 || yDragOffSet != 0) {
+ dragLayerX += xDragOffSet;
+ dragLayerY += yDragOffSet;
+ }
+ }
+
final DragView dv;
if (contentView instanceof View) {
if (contentView instanceof LauncherAppWidgetHostView) {
@@ -1701,7 +1707,6 @@
dragLayerY,
source,
dragObject,
- dragVisualizeOffset,
dragRect,
scale * iconScale,
scale,
@@ -1714,7 +1719,6 @@
dragLayerY,
source,
dragObject,
- dragVisualizeOffset,
dragRect,
scale * iconScale,
scale,
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index 328d769..9867268 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -143,14 +143,12 @@
int dragLayerY,
DragSource source,
ItemInfo dragInfo,
- Point dragOffset,
Rect dragRegion,
float initialDragViewScale,
float dragViewScaleOnDrop,
DragOptions options) {
- return startDrag(drawable, /* view= */ null, originalView, dragLayerX, dragLayerY,
- source, dragInfo, dragOffset, dragRegion, initialDragViewScale, dragViewScaleOnDrop,
- options);
+ return startDrag(drawable, /* view= */ null, originalView, dragLayerX, dragLayerY, source,
+ dragInfo, dragRegion, initialDragViewScale, dragViewScaleOnDrop, options);
}
/**
@@ -180,14 +178,12 @@
int dragLayerY,
DragSource source,
ItemInfo dragInfo,
- Point dragOffset,
Rect dragRegion,
float initialDragViewScale,
float dragViewScaleOnDrop,
DragOptions options) {
- return startDrag(/* drawable= */ null, view, originalView, dragLayerX, dragLayerY,
- source, dragInfo, dragOffset, dragRegion, initialDragViewScale, dragViewScaleOnDrop,
- options);
+ return startDrag(/* drawable= */ null, view, originalView, dragLayerX, dragLayerY, source,
+ dragInfo, dragRegion, initialDragViewScale, dragViewScaleOnDrop, options);
}
protected abstract DragView startDrag(
@@ -198,7 +194,6 @@
int dragLayerY,
DragSource source,
ItemInfo dragInfo,
- Point dragOffset,
Rect dragRegion,
float initialDragViewScale,
float dragViewScaleOnDrop,
diff --git a/src/com/android/launcher3/dragndrop/DragOptions.java b/src/com/android/launcher3/dragndrop/DragOptions.java
index 1ff4335..2af81db 100644
--- a/src/com/android/launcher3/dragndrop/DragOptions.java
+++ b/src/com/android/launcher3/dragndrop/DragOptions.java
@@ -78,5 +78,12 @@
* This will be true if the condition was met, otherwise false.
*/
void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted);
+
+ /**
+ * The offset points that should be overridden to update the dragLayer.
+ */
+ default Point getDragOffset() {
+ return new Point(0,0);
+ }
}
}
diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java
index 46c8e81..0d0717e 100644
--- a/src/com/android/launcher3/dragndrop/DragView.java
+++ b/src/com/android/launcher3/dragndrop/DragView.java
@@ -37,7 +37,6 @@
import android.graphics.ColorFilter;
import android.graphics.Path;
import android.graphics.Picture;
-import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
@@ -89,15 +88,17 @@
private final RunnableList mOnDragStartCallback = new RunnableList();
- private Point mDragVisualizeOffset = null;
+ private boolean mHasDragOffset;
private Rect mDragRegion = null;
protected final T mActivity;
private final BaseDragLayer<T> mDragLayer;
private boolean mHasDrawn = false;
- final ValueAnimator mAnim;
+ final ValueAnimator mScaleAnim;
+ final ValueAnimator mShiftAnim;
+
// Whether mAnim has started. Unlike mAnim.isStarted(), this is true even after mAnim ends.
- private boolean mAnimStarted;
+ private boolean mScaleAnimStarted;
private Runnable mOnAnimEndCallback = null;
private int mLastTouchX;
@@ -166,9 +167,9 @@
setScaleY(initialScale);
// Animate the view into the correct position
- mAnim = ValueAnimator.ofFloat(0f, 1f);
- mAnim.setDuration(VIEW_ZOOM_DURATION);
- mAnim.addUpdateListener(animation -> {
+ mScaleAnim = ValueAnimator.ofFloat(0f, 1f);
+ mScaleAnim.setDuration(VIEW_ZOOM_DURATION);
+ mScaleAnim.addUpdateListener(animation -> {
final float value = (Float) animation.getAnimatedValue();
setScaleX(Utilities.mapRange(value, initialScale, mEndScale));
setScaleY(Utilities.mapRange(value, initialScale, mEndScale));
@@ -176,10 +177,10 @@
animation.cancel();
}
});
- mAnim.addListener(new AnimatorListenerAdapter() {
+ mScaleAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
- mAnimStarted = true;
+ mScaleAnimStarted = true;
}
@Override
@@ -190,6 +191,8 @@
}
}
});
+ // Set up the shift animator.
+ mShiftAnim = ValueAnimator.ofFloat(0f, 1f);
setDragRegion(new Rect(0, 0, width, height));
@@ -319,12 +322,12 @@
return mDragRegion.height();
}
- public void setDragVisualizeOffset(Point p) {
- mDragVisualizeOffset = p;
+ public void setHasDragOffset(boolean hasDragOffset) {
+ mHasDragOffset = hasDragOffset;
}
- public Point getDragVisualizeOffset() {
- return mDragVisualizeOffset;
+ public boolean getHasDragOffset() {
+ return mHasDragOffset;
}
public void setDragRegion(Rect r) {
@@ -392,22 +395,29 @@
if (mContent != null) {
// At the drag start, the source view visibility is set to invisible.
- mContent.setVisibility(VISIBLE);
+ if (getHasDragOffset()) {
+ // If there is any dragOffset, this means the content will show away of the original
+ // icon location, otherwise it's fine since original content would just show at the
+ // same spot.
+ mContent.setVisibility(INVISIBLE);
+ } else {
+ mContent.setVisibility(VISIBLE);
+ }
}
move(touchX, touchY);
// Post the animation to skip other expensive work happening on the first frame
- post(mAnim::start);
+ post(mScaleAnim::start);
}
public void cancelAnimation() {
- if (mAnim != null && mAnim.isRunning()) {
- mAnim.cancel();
+ if (mScaleAnim != null && mScaleAnim.isRunning()) {
+ mScaleAnim.cancel();
}
}
- public boolean isAnimationFinished() {
- return mAnimStarted && !mAnim.isRunning();
+ public boolean isScaleAnimationFinished() {
+ return mScaleAnimStarted && !mScaleAnim.isRunning();
}
/**
@@ -434,13 +444,15 @@
int duration);
public void animateShift(final int shiftX, final int shiftY) {
- if (mAnim.isStarted()) {
- return;
- }
+ if (mShiftAnim.isStarted()) return;
+
+ // Set mContent visibility to visible to show icon regardless in case it is INVISIBLE.
+ if (mContent != null) mContent.setVisibility(VISIBLE);
+
mAnimatedShiftX = shiftX;
mAnimatedShiftY = shiftY;
applyTranslation();
- mAnim.addUpdateListener(new AnimatorUpdateListener() {
+ mShiftAnim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float fraction = 1 - animation.getAnimatedFraction();
@@ -449,6 +461,7 @@
applyTranslation();
}
});
+ mShiftAnim.start();
}
private void applyTranslation() {
diff --git a/src/com/android/launcher3/dragndrop/LauncherDragController.java b/src/com/android/launcher3/dragndrop/LauncherDragController.java
index 0e8b0a5..aaa5b1a 100644
--- a/src/com/android/launcher3/dragndrop/LauncherDragController.java
+++ b/src/com/android/launcher3/dragndrop/LauncherDragController.java
@@ -21,7 +21,6 @@
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import android.content.res.Resources;
-import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.HapticFeedbackConstants;
@@ -60,7 +59,6 @@
int dragLayerY,
DragSource source,
ItemInfo dragInfo,
- Point dragOffset,
Rect dragRegion,
float initialDragViewScale,
float dragViewScaleOnDrop,
@@ -129,9 +127,11 @@
mDragObject.dragInfo = dragInfo;
mDragObject.originalDragInfo = mDragObject.dragInfo.makeShallowCopy();
- if (dragOffset != null) {
- dragView.setDragVisualizeOffset(new Point(dragOffset));
+ if (mOptions.preDragCondition != null) {
+ dragView.setHasDragOffset(mOptions.preDragCondition.getDragOffset().x != 0 ||
+ mOptions.preDragCondition.getDragOffset().y != 0);
}
+
if (dragRegion != null) {
dragView.setDragRegion(new Rect(dragRegion));
}
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java
index 56dffa9..fcc62a7 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java
@@ -18,7 +18,6 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Intent;
-import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -405,17 +404,25 @@
drawable = null;
scale = previewProvider.getScaleAndPosition(contentView, mTempXY);
}
- int halfPadding = previewProvider.previewPadding / 2;
+
int dragLayerX = mTempXY[0];
int dragLayerY = mTempXY[1];
- Point dragVisualizeOffset = null;
Rect dragRect = new Rect();
if (draggableView != null) {
draggableView.getSourceVisualDragBounds(dragRect);
dragLayerY += dragRect.top;
- dragVisualizeOffset = new Point(-halfPadding, halfPadding);
}
+
+ if (options.preDragCondition != null) {
+ int xOffSet = options.preDragCondition.getDragOffset().x;
+ int yOffSet = options.preDragCondition.getDragOffset().y;
+ if (xOffSet != 0 && yOffSet != 0) {
+ dragLayerX += xOffSet;
+ dragLayerY += yOffSet;
+ }
+ }
+
if (contentView != null) {
mDragController.startDrag(
contentView,
@@ -424,7 +431,6 @@
dragLayerY,
source,
dragObject,
- dragVisualizeOffset,
dragRect,
scale * iconScale,
scale,
@@ -437,7 +443,6 @@
dragLayerY,
source,
dragObject,
- dragVisualizeOffset,
dragRect,
scale * iconScale,
scale,
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java
index b1a9b86..8d1d96b 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java
@@ -17,7 +17,6 @@
package com.android.launcher3.secondarydisplay;
import android.content.res.Resources;
-import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.HapticFeedbackConstants;
@@ -51,7 +50,7 @@
@Override
protected DragView startDrag(@Nullable Drawable drawable, @Nullable View view,
DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source,
- ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale,
+ ItemInfo dragInfo, Rect dragRegion, float initialDragViewScale,
float dragViewScaleOnDrop, DragOptions options) {
if (PROFILE_DRAWING_DURING_DRAG) {
android.os.Debug.startMethodTracing("Launcher");
@@ -117,9 +116,11 @@
mDragObject.dragInfo = dragInfo;
mDragObject.originalDragInfo = mDragObject.dragInfo.makeShallowCopy();
- if (dragOffset != null) {
- dragView.setDragVisualizeOffset(new Point(dragOffset));
+ if (mOptions.preDragCondition != null) {
+ dragView.setHasDragOffset(mOptions.preDragCondition.getDragOffset().x != 0 ||
+ mOptions.preDragCondition.getDragOffset().y != 0);
}
+
if (dragRegion != null) {
dragView.setDragRegion(new Rect(dragRegion));
}
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
index a917b68..87afcab 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
@@ -236,7 +236,7 @@
@Override
public boolean shouldStartDrag(double distanceDragged) {
- return mDragView != null && mDragView.isAnimationFinished();
+ return mDragView != null && mDragView.isScaleAnimationFinished();
}
@Override
diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java
index f269434..faad307 100644
--- a/src/com/android/launcher3/widget/PendingItemDragHelper.java
+++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java
@@ -103,7 +103,6 @@
final int previewWidth;
final int previewHeight;
final float scale;
- final Point dragOffset;
final Rect dragRegion;
mEstimatedCellSize = launcher.getWorkspace().estimateItemSize(mAddInfo);
@@ -173,7 +172,6 @@
scale = previewBounds.width() / (float) previewWidth;
launcher.getDragController().addDragListener(new WidgetHostViewLoader(launcher, mView));
- dragOffset = null;
dragRegion = null;
draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_WIDGET);
} else {
@@ -188,8 +186,6 @@
li.recycle();
scale = ((float) launcher.getDeviceProfile().iconSizePx) / previewWidth;
- dragOffset = new Point(previewPadding / 2, previewPadding / 2);
-
// Create a preview same as the workspace cell size and draw the icon at the
// appropriate position.
DeviceProfile dp = launcher.getDeviceProfile();
@@ -217,11 +213,10 @@
// Start the drag
if (mAppWidgetHostViewPreview != null) {
launcher.getDragController().startDrag(mAppWidgetHostViewPreview, draggableView,
- dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale,
- options);
+ dragLayerX, dragLayerY, source, mAddInfo, dragRegion, scale, scale, options);
} else {
launcher.getDragController().startDrag(preview, draggableView, dragLayerX, dragLayerY,
- source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
+ source, mAddInfo, dragRegion, scale, scale, options);
}
}