summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/PendingAppWidgetHostView.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-02-23 16:43:23 -0800
committerSunny Goyal <sunnygoyal@google.com>2016-02-23 16:43:23 -0800
commit5845bea514409ada1d5022c8a25fe175f6cac975 (patch)
tree45fd4850ac37c8729ac8c3d246b683487a6d6dfb /src/com/android/launcher3/PendingAppWidgetHostView.java
parentd31dcbcc7c7901959c65c4e635e59274a1d4c334 (diff)
downloadandroid_packages_apps_Trebuchet-5845bea514409ada1d5022c8a25fe175f6cac975.tar.gz
android_packages_apps_Trebuchet-5845bea514409ada1d5022c8a25fe175f6cac975.tar.bz2
android_packages_apps_Trebuchet-5845bea514409ada1d5022c8a25fe175f6cac975.zip
Preventing crash when there is not enough width to show the pending text
Bug: 26901856 Change-Id: I03c9631ce224cce76b2c896a5e6ce6b0ee741782
Diffstat (limited to 'src/com/android/launcher3/PendingAppWidgetHostView.java')
-rw-r--r--src/com/android/launcher3/PendingAppWidgetHostView.java44
1 files changed, 24 insertions, 20 deletions
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);