OSDN Git Service

Preventing crash when there is not enough width to show the pending text
authorSunny Goyal <sunnygoyal@google.com>
Wed, 24 Feb 2016 00:43:23 +0000 (16:43 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Wed, 24 Feb 2016 00:43:23 +0000 (16:43 -0800)
Bug: 26901856
Change-Id: I03c9631ce224cce76b2c896a5e6ce6b0ee741782

src/com/android/launcher3/PendingAppWidgetHostView.java

index 85d8658..1c02904 100644 (file)
@@ -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);