From 80b25cfd5d8b7292cf15f260812981eff3fa8aea Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 11 May 2021 11:55:20 -0700 Subject: [PATCH] Fix widget drop animation When removing content from the dragView, replace it with a snapshot so that the preview remains the same Test: Drag a widget and observe the drop animation is shown. Bug: 187423667 Change-Id: I1e726f50a2b3d0a5f1562297cccf47a435affd02 --- .../android/launcher3/dragndrop/DragView.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index 30ee9ecddd..1664980c35 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -33,11 +33,13 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; 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; import android.graphics.drawable.Drawable; +import android.graphics.drawable.PictureDrawable; import android.os.Build; import android.os.Handler; import android.os.Looper; @@ -457,7 +459,6 @@ public class DragView extends FrameLayout implements StateListener= 0) { - removeView(mContent); + Picture picture = new Picture(); + mContent.draw(picture.beginRecording(mWidth, mHeight)); + picture.endRecording(); + View view = new View(mLauncher); + view.setClipToOutline(mContent.getClipToOutline()); + view.setOutlineProvider(mContent.getOutlineProvider()); + view.setBackground(new PictureDrawable(picture)); + view.measure(makeMeasureSpec(mWidth, EXACTLY), makeMeasureSpec(mHeight, EXACTLY)); + view.layout(mContent.getLeft(), mContent.getTop(), + mContent.getRight(), mContent.getBottom()); + addViewInLayout(view, indexOfChild(mContent), mContent.getLayoutParams(), true); + + removeViewInLayout(mContent); + mContent.setVisibility(INVISIBLE); mContent.setLayoutParams(mContentViewLayoutParams); if (reattachToPreviousParent) { mContentViewParent.addView(mContent, mContentViewInParentViewIndex);