From 00f89fbbf67d0f99e433b4cbd8c79947aebb83dd Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 22 Feb 2023 02:21:20 +0000 Subject: [PATCH] Fix taskbar drag view scale when returning to original icon - Use getSourceVisualDragBounds() if the target view is BubbleTextView; this accounts for padding as well as extra ring inset for PredictedAppIcon - Also ensure we always use the final drag view scale when switching to the system drag and drop, instead of using the current scale which might be in the process of animating Test: drag regular and predicted icons in taskbar, but drop it in a region that doesn't accept it (e.g. the taskbar itself), check that the return animation scales and offsets more correctly than before Bug: 269814838 Change-Id: Ie8398b2617340e1d2568773563aa0263a3366940 --- .../launcher3/taskbar/TaskbarDragController.java | 12 ++++++++++-- src/com/android/launcher3/dragndrop/DragView.java | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index 45df9d6de9..4e79011ca0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -340,7 +340,7 @@ public class TaskbarDragController extends DragController im if (DEBUG_DRAG_SHADOW_SURFACE) { canvas.drawColor(0xffff0000); } - float scale = mDragObject.dragView.getScaleX(); + float scale = mDragObject.dragView.getEndScale(); canvas.scale(scale, scale); mDragObject.dragView.draw(canvas); canvas.restore(); @@ -601,7 +601,15 @@ public class TaskbarDragController extends DragController im View target = findTaskbarTargetForIconView(originalView); int[] toPosition = target.getLocationOnScreen(); - float toScale = (float) target.getWidth() / mDragIconSize; + float iconSize = target.getWidth(); + if (target instanceof BubbleTextView) { + Rect bounds = new Rect(); + ((BubbleTextView) target).getSourceVisualDragBounds(bounds); + toPosition[0] += bounds.left; + toPosition[1] += bounds.top; + iconSize = bounds.width(); + } + float toScale = iconSize / mDragIconSize; float toAlpha = (target == originalView) ? 1f : 0f; MultiValueUpdateListener listener = new MultiValueUpdateListener() { final FloatProp mDx = new FloatProp(fromX, toPosition[0], 0, diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index e10fdf53d8..46c8e8114b 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -83,6 +83,7 @@ public abstract class DragView extends Fram protected final int mRegistrationX; protected final int mRegistrationY; private final float mInitialScale; + private final float mEndScale; protected final float mScaleOnDrop; protected final int[] mTempLoc = new int[2]; @@ -158,7 +159,7 @@ public abstract class DragView extends Fram setClipToPadding(false); } - final float scale = (width + finalScaleDps) / width; + mEndScale = (width + finalScaleDps) / width; // Set the initial scale to avoid any jumps setScaleX(initialScale); @@ -169,8 +170,8 @@ public abstract class DragView extends Fram mAnim.setDuration(VIEW_ZOOM_DURATION); mAnim.addUpdateListener(animation -> { final float value = (Float) animation.getAnimatedValue(); - setScaleX(initialScale + (value * (scale - initialScale))); - setScaleY(initialScale + (value * (scale - initialScale))); + setScaleX(Utilities.mapRange(value, initialScale, mEndScale)); + setScaleY(Utilities.mapRange(value, initialScale, mEndScale)); if (!isAttachedToWindow()) { animation.cancel(); } @@ -508,6 +509,10 @@ public abstract class DragView extends Fram return mInitialScale; } + public float getEndScale() { + return mEndScale; + } + @Override public boolean hasOverlappingRendering() { return false;