From caf2e5f350ef99dcb31dc1dd71d8a4a4f9ce954d Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Tue, 10 Aug 2021 00:04:49 +0100 Subject: [PATCH] Use target size to scale down a widget preview image WidgetCells are being recycled in WidgetFullSheet. getWidth/getHeight could be a recycled dimension. There is also no guarantee that measure has taken placed before the scale down logic. Let's use the targeted width for the scale down logic instead. Test: Manual Fix: 195417705 Change-Id: Idfb3cc485604d19658e210709bebde6f163003cf --- src/com/android/launcher3/widget/WidgetCell.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index 167eb0983e..a8ed1549d6 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -325,10 +325,10 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { return; } if (drawable != null) { + // Scale down the preview size if it's wider than the cell. float scale = 1f; - if (getWidth() > 0 && getHeight() > 0) { - // Scale down the preview size if it's wider than the cell. - float maxWidth = getWidth(); + if (mTargetPreviewWidth > 0) { + float maxWidth = mTargetPreviewWidth; float previewWidth = drawable.getIntrinsicWidth() * mPreviewContainerScale; scale = Math.min(maxWidth / previewWidth, 1); }