From 6d8deb32f6a2c15127af363288f188ddde6e5638 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Fri, 24 Sep 2021 17:32:51 +0100 Subject: [PATCH] Fix getWidgetItemSizePx estimation The size returned by getWidgetItemSizePx is used by the widget picker for the NavigableAppWidgetHostView. We should NOT deduct the padding applied to NavigableAppWidgetHostView to this size. If a launcher grid insets NavigableAppWidgetHostView, then we must add the inset to the NavigableAppWidgetHostView width / height. Test: Compare the size of widgets in preview and home screen using layout inspector. See screenshots in the bug Fix: 200983939 Change-Id: I35022861b65f2624f69940cf3856d9c47f8dbbd9 --- .../launcher3/widget/util/WidgetSizes.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/widget/util/WidgetSizes.java b/src/com/android/launcher3/widget/util/WidgetSizes.java index 451ed6efcc..b211f4c22b 100644 --- a/src/com/android/launcher3/widget/util/WidgetSizes.java +++ b/src/com/android/launcher3/widget/util/WidgetSizes.java @@ -17,7 +17,6 @@ package com.android.launcher3.widget.util; import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget; - import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; import android.content.ComponentName; @@ -87,7 +86,13 @@ public final class WidgetSizes { } /** - * Returns the size of a WidgetItem. + * Returns the size of a {@link WidgetItem}. + * + *

This size is used by the widget picker. It should NEVER be shared with app widgets. + * + *

For sizes shared with app widgets, please refer to + * {@link #getWidgetPaddedSizes(Context, ComponentName, int, int)} & + * {@link #getWidgetPaddedSizePx(Context, ComponentName, DeviceProfile, int, int)}. */ public static Size getWidgetItemSizePx(Context context, DeviceProfile profile, WidgetItem widgetItem) { @@ -96,8 +101,15 @@ public final class WidgetSizes { .getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding); return new Size(dimension, dimension); } - return getWidgetPaddedSizePx(context, widgetItem.componentName, profile, widgetItem.spanX, - widgetItem.spanY); + Size widgetItemSize = getWidgetSizePx(profile, widgetItem.spanX, + widgetItem.spanY, /* recycledCellSize= */ null); + if (profile.shouldInsetWidgets()) { + Rect inset = new Rect(); + AppWidgetHostView.getDefaultPaddingForWidget(context, widgetItem.componentName, inset); + return new Size(widgetItemSize.getWidth() + inset.left + inset.right, + widgetItemSize.getHeight() + inset.top + inset.bottom); + } + return widgetItemSize; } private static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY,