From 1b8bbb6c40f02edcd741d8b969601cb354030833 Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Wed, 19 May 2021 22:45:16 +0100 Subject: [PATCH] Correct size of AppWidget for color extraction. Correct the size of the App Widget: first, compute the size when the widget is positioned (it wasn't done), then do not apply the transformation when computing the size of the widget when drawn. Note: Somehow, there is a shift by 1 on the position on the x axis, both in landscape and portrait. So I added a +1 to get the exact same values. If not, we have a risk of getting different colors. Fix: 188759989 Bug: 187907544 Test: Added logs and moved a widget by hand, check the actual coordinates with hsv. Change-Id: Ia3bd5b3e3ea9a3ef75f8cdf466a9800786646a94 --- src/com/android/launcher3/CellLayout.java | 7 +++++-- .../launcher3/widget/LauncherAppWidgetHostView.java | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 1df9df6763..bfa1769ea8 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -1080,9 +1080,10 @@ public class CellLayout extends ViewGroup { cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect); // Now get the rect in drag layer coordinates. - getBoundsForViewInDragLayer(launcher.getDragLayer(), workspace, mTempRect, false, + getBoundsForViewInDragLayer(launcher.getDragLayer(), this, mTempRect, true, mTmpFloatArray, mTempRectF); Utilities.setRect(mTempRectF, mTempRect); + ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, pageId); } } @@ -2594,7 +2595,9 @@ public class CellLayout extends ViewGroup { final int cellWidth = mCellWidth; final int cellHeight = mCellHeight; - final int hStartPadding = getPaddingLeft(); + // We observe a shift of 1 pixel on the x coordinate compared to the actual cell coordinates + final int hStartPadding = getPaddingLeft() + + (int) Math.ceil(getUnusedHorizontalSpace() / 2f); final int vStartPadding = getPaddingTop(); int x = hStartPadding + (cellX * mBorderSpacing) + (cellX * cellWidth); diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java index 5deecd4c8a..8685aae737 100644 --- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java @@ -319,11 +319,15 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView } mIsScrollable = checkScrollableRecursively(this); - if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo) { + mCurrentWidgetSize.left = left; + mCurrentWidgetSize.right = right; + mCurrentWidgetSize.top = top; + mCurrentWidgetSize.bottom = bottom; + LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) getTag(); - getBoundsForViewInDragLayer(mLauncher.getDragLayer(), this, mCurrentWidgetSize, true, - mTmpFloatArray, mTempRectF); + getBoundsForViewInDragLayer(mLauncher.getDragLayer(), (View) getParent(), + mCurrentWidgetSize, true, mTmpFloatArray, mTempRectF); setRect(mTempRectF, mCurrentWidgetSize); updateColorExtraction(mCurrentWidgetSize, mWorkspace.getPageIndexForScreenId(info.screenId));