Avoid crash when widget previews have no intrinsic size

Intrinsic size for widget preview drawable checked.
Needed since some drawables, like color drawables,
do not have any intrinsic size.

Bug: 78452220
Test: manual, see Bug info.
Change-Id: I815353773e38b1fce2fe19962f07c1727e1b0768
This commit is contained in:
Roger Olsson
2018-04-12 10:08:01 +02:00
committed by Sunny Goyal
parent 87249707a5
commit 4ac406db22

View File

@@ -338,7 +338,8 @@ public class WidgetPreviewLoader {
int previewWidth;
int previewHeight;
if (widgetPreviewExists) {
if (widgetPreviewExists && drawable.getIntrinsicWidth() > 0
&& drawable.getIntrinsicHeight() > 0) {
previewWidth = drawable.getIntrinsicWidth();
previewHeight = drawable.getIntrinsicHeight();
} else {
@@ -358,8 +359,8 @@ public class WidgetPreviewLoader {
scale = maxPreviewWidth / (float) (previewWidth);
}
if (scale != 1f) {
previewWidth = (int) (scale * previewWidth);
previewHeight = (int) (scale * previewHeight);
previewWidth = Math.max((int)(scale * previewWidth), 1);
previewHeight = Math.max((int)(scale * previewHeight), 1);
}
// If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size