From 370164c4f77972675f4582618088e1a6fef9518f Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Wed, 8 Apr 2020 18:00:30 -0700 Subject: [PATCH] Fix drag and drop regression when dragging a scaled widget Missed this case in ag/10736229; the symptom was that if you picked up a widget when it was scaled due to split-screen, the widget would disappear Test: manual Change-Id: I26810fcf820f7053b6445989dce6598e1df55a8e --- src/com/android/launcher3/CellLayout.java | 9 +++++++-- .../android/launcher3/graphics/DragPreviewProvider.java | 4 +++- .../launcher3/widget/LauncherAppWidgetHostView.java | 9 ++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 4259196465..d7b5cf10ae 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -959,8 +959,13 @@ public class CellLayout extends ViewGroup { height = r.height(); } - if (v != null && v.getViewType() == DraggableView.DRAGGABLE_ICON) { - left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2; + // Center horizontaly + left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2; + + if (v != null && v.getViewType() == DraggableView.DRAGGABLE_WIDGET) { + // Center vertically + top += ((mCellHeight * spanY) - dragOutline.getHeight()) / 2; + } else if (v != null && v.getViewType() == DraggableView.DRAGGABLE_ICON) { int cHeight = getShortcutsAndWidgets().getCellContentHeight(); int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f)); top += cellPaddingY; diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java index ed9dfbbd79..848c04a730 100644 --- a/src/com/android/launcher3/graphics/DragPreviewProvider.java +++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java @@ -92,6 +92,8 @@ public class DragPreviewProvider { public Bitmap createDragBitmap() { int width = 0; int height = 0; + // Assume scaleX == scaleY, which is always the case for workspace items. + float scale = mView.getScaleX(); if (mView instanceof DraggableView) { ((DraggableView) mView).getVisualDragBounds(mTempRect); width = mTempRect.width(); @@ -102,7 +104,7 @@ public class DragPreviewProvider { } return BitmapRenderer.createHardwareBitmap(width + blurSizeOutline, - height + blurSizeOutline, (c) -> drawDragView(c, 1)); + height + blurSizeOutline, (c) -> drawDragView(c, scale)); } public final void generateDragOutline(Bitmap preview) { diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java index 78acc344d9..6232a1d871 100644 --- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java @@ -365,10 +365,9 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView @Override public void getVisualDragBounds(Rect bounds) { - int x = (int) (1 - getScaleToFit()) * getMeasuredWidth() / 2; - int y = (int) (1 - getScaleToFit()) * getMeasuredWidth() / 2; - int width = (int) getScaleToFit() * getMeasuredWidth(); - int height = (int) getScaleToFit() * getMeasuredHeight(); - bounds.set(x, y , x + width, y + height); + int width = (int) (getMeasuredWidth() * mScaleToFit); + int height = (int) (getMeasuredHeight() * mScaleToFit); + + bounds.set(0, 0 , width, height); } }