Merge "Separate animations and add dragOffSet points in dragOptions" into udc-dev am: 125e121834
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/22862532 Change-Id: Id61315d5e0d15da6354927889fa97ea8eb957528 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -198,7 +198,7 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
|
||||
|
||||
@Override
|
||||
public boolean shouldStartDrag(double distanceDragged) {
|
||||
return mDragView != null && mDragView.isAnimationFinished();
|
||||
return mDragView != null && mDragView.isScaleAnimationFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,7 +231,6 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
|
||||
dragLayerY,
|
||||
(View target, DropTarget.DragObject d, boolean success) -> {} /* DragSource */,
|
||||
(ItemInfo) btv.getTag(),
|
||||
/* dragVisualizeOffset = */ null,
|
||||
dragRect,
|
||||
scale * iconScale,
|
||||
scale,
|
||||
@@ -241,7 +240,7 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
|
||||
@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;
|
||||
|
||||
|
||||
@@ -1661,17 +1661,14 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
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 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
dragLayerY,
|
||||
source,
|
||||
dragObject,
|
||||
dragVisualizeOffset,
|
||||
dragRect,
|
||||
scale * iconScale,
|
||||
scale,
|
||||
@@ -1714,7 +1719,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
dragLayerY,
|
||||
source,
|
||||
dragObject,
|
||||
dragVisualizeOffset,
|
||||
dragRect,
|
||||
scale * iconScale,
|
||||
scale,
|
||||
|
||||
@@ -143,14 +143,12 @@ public abstract class DragController<T extends ActivityContext>
|
||||
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 @@ public abstract class DragController<T extends ActivityContext>
|
||||
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 @@ public abstract class DragController<T extends ActivityContext>
|
||||
int dragLayerY,
|
||||
DragSource source,
|
||||
ItemInfo dragInfo,
|
||||
Point dragOffset,
|
||||
Rect dragRegion,
|
||||
float initialDragViewScale,
|
||||
float dragViewScaleOnDrop,
|
||||
|
||||
@@ -78,5 +78,12 @@ public class DragOptions {
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import android.graphics.Color;
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
}
|
||||
}
|
||||
});
|
||||
// Set up the shift animator.
|
||||
mShiftAnim = ValueAnimator.ofFloat(0f, 1f);
|
||||
|
||||
setDragRegion(new Rect(0, 0, width, height));
|
||||
|
||||
@@ -319,12 +322,12 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
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 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
applyTranslation();
|
||||
}
|
||||
});
|
||||
mShiftAnim.start();
|
||||
}
|
||||
|
||||
private void applyTranslation() {
|
||||
|
||||
@@ -21,7 +21,6 @@ import static com.android.launcher3.LauncherState.NORMAL;
|
||||
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 @@ public class LauncherDragController extends DragController<Launcher> {
|
||||
int dragLayerY,
|
||||
DragSource source,
|
||||
ItemInfo dragInfo,
|
||||
Point dragOffset,
|
||||
Rect dragRegion,
|
||||
float initialDragViewScale,
|
||||
float dragViewScaleOnDrop,
|
||||
@@ -129,9 +127,11 @@ public class LauncherDragController extends DragController<Launcher> {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.android.launcher3.secondarydisplay;
|
||||
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 @@ public class SecondaryDisplayLauncher extends BaseDraggingActivity
|
||||
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 @@ public class SecondaryDisplayLauncher extends BaseDraggingActivity
|
||||
dragLayerY,
|
||||
source,
|
||||
dragObject,
|
||||
dragVisualizeOffset,
|
||||
dragRect,
|
||||
scale * iconScale,
|
||||
scale,
|
||||
@@ -437,7 +443,6 @@ public class SecondaryDisplayLauncher extends BaseDraggingActivity
|
||||
dragLayerY,
|
||||
source,
|
||||
dragObject,
|
||||
dragVisualizeOffset,
|
||||
dragRect,
|
||||
scale * iconScale,
|
||||
scale,
|
||||
|
||||
@@ -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 @@ public class SecondaryDragController extends DragController<SecondaryDisplayLaun
|
||||
@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 @@ public class SecondaryDragController extends DragController<SecondaryDisplayLaun
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class SecondaryDragLayer extends BaseDragLayer<SecondaryDisplayLauncher>
|
||||
|
||||
@Override
|
||||
public boolean shouldStartDrag(double distanceDragged) {
|
||||
return mDragView != null && mDragView.isAnimationFinished();
|
||||
return mDragView != null && mDragView.isScaleAnimationFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -103,7 +103,6 @@ public class PendingItemDragHelper extends DragPreviewProvider {
|
||||
final int previewWidth;
|
||||
final int previewHeight;
|
||||
final float scale;
|
||||
final Point dragOffset;
|
||||
final Rect dragRegion;
|
||||
|
||||
mEstimatedCellSize = launcher.getWorkspace().estimateItemSize(mAddInfo);
|
||||
@@ -173,7 +172,6 @@ public class PendingItemDragHelper extends DragPreviewProvider {
|
||||
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 @@ public class PendingItemDragHelper extends DragPreviewProvider {
|
||||
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 @@ public class PendingItemDragHelper extends DragPreviewProvider {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user