From 5845bea514409ada1d5022c8a25fe175f6cac975 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 23 Feb 2016 16:43:23 -0800 Subject: Preventing crash when there is not enough width to show the pending text Bug: 26901856 Change-Id: I03c9631ce224cce76b2c896a5e6ce6b0ee741782 --- .../launcher3/PendingAppWidgetHostView.java | 44 ++++++++++++---------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'src/com/android/launcher3/PendingAppWidgetHostView.java') diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java index 85d8658a6..1c0290417 100644 --- a/src/com/android/launcher3/PendingAppWidgetHostView.java +++ b/src/com/android/launcher3/PendingAppWidgetHostView.java @@ -231,26 +231,30 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen int actualIconSize = (int) Math.min(iconSize, grid.iconSizePx); - // Recreate the setup text. - mSetupTextLayout = new StaticLayout( - getResources().getText(R.string.gadget_setup_text), mPaint, availableWidth, - Layout.Alignment.ALIGN_CENTER, 1, 0, true); - int textHeight = mSetupTextLayout.getHeight(); - - // Extra icon size due to the setting icon - float minHeightWithText = textHeight + actualIconSize * settingIconScaleFactor - + grid.iconDrawablePaddingPx; - - int iconTop; - if (minHeightWithText < availableHeight) { - // We can draw the text as well - iconTop = (getHeight() - textHeight - - grid.iconDrawablePaddingPx - actualIconSize) / 2; - - } else { - // The text will not fit. Only draw the icons. - iconTop = (getHeight() - actualIconSize) / 2; - mSetupTextLayout = null; + // Icon top when we do not draw the text + int iconTop = (getHeight() - actualIconSize) / 2; + mSetupTextLayout = null; + + if (availableWidth > 0) { + // Recreate the setup text. + mSetupTextLayout = new StaticLayout( + getResources().getText(R.string.gadget_setup_text), mPaint, availableWidth, + Layout.Alignment.ALIGN_CENTER, 1, 0, true); + int textHeight = mSetupTextLayout.getHeight(); + + // Extra icon size due to the setting icon + float minHeightWithText = textHeight + actualIconSize * settingIconScaleFactor + + grid.iconDrawablePaddingPx; + + if (minHeightWithText < availableHeight) { + // We can draw the text as well + iconTop = (getHeight() - textHeight - + grid.iconDrawablePaddingPx - actualIconSize) / 2; + + } else { + // We can't draw the text. Let the iconTop be same as before. + mSetupTextLayout = null; + } } mRect.set(0, 0, actualIconSize, actualIconSize); -- cgit v1.2.3