Bug 1378617 - Fix ClassCastException if the icon is not a BitmapDrawable. r?sebastian draft
authorNevin Chen <cnevinchen@gmail.com>
Tue, 11 Jul 2017 14:08:33 +0800
changeset 606617 a56e9b7e503def6c0d22aa6ac2c46c7c7178528e
parent 605863 a418121d46250f91728b86d9eea331029c264c30
child 636804 229bb65e227f26b9a7524fa6bf8faf862920f201
push id67740
push userbmo:cnevinchen@gmail.com
push dateTue, 11 Jul 2017 06:12:39 +0000
reviewerssebastian
bugs1378617
milestone56.0a1
Bug 1378617 - Fix ClassCastException if the icon is not a BitmapDrawable. r?sebastian MozReview-Commit-ID: IU9hOPEA7eb
mobile/android/base/java/org/mozilla/gecko/prompts/PromptListAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/prompts/PromptListAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/prompts/PromptListAdapter.java
@@ -7,16 +7,17 @@ import org.mozilla.gecko.menu.MenuItemSw
 import org.mozilla.gecko.widget.GeckoActionProvider;
 
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.VectorDrawable;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.view.ViewCompat;
 import android.support.v4.widget.TextViewCompat;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.CheckedTextView;
 import android.widget.TextView;
@@ -99,30 +100,40 @@ public class PromptListAdapter extends A
     }
 
     public void toggleSelected(int position) {
         PromptListItem item = getItem(position);
         item.setSelected(!item.getSelected());
     }
 
     private void maybeUpdateIcon(PromptListItem item, TextView t) {
-        if (item.getIcon() == null && !item.inGroup && !item.isParent) {
+        final Drawable icon = item.getIcon();
+        if (icon == null && !item.inGroup && !item.isParent) {
             TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(t, null, null, null, null);
             return;
         }
 
         Drawable d = null;
         Resources res = getContext().getResources();
         // Set the padding between the icon and the text.
         t.setCompoundDrawablePadding(mIconTextPadding);
-        if (item.getIcon() != null) {
+        if (icon != null) {
             // We want the icon to be of a specific size. Some do not
             // follow this rule so we have to resize them.
-            Bitmap bitmap = ((BitmapDrawable) item.getIcon()).getBitmap();
-            d = new BitmapDrawable(res, Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
+            if (icon instanceof BitmapDrawable) {
+                Bitmap bitmap = ((BitmapDrawable) icon).getBitmap();
+                d = new BitmapDrawable(res, Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
+            } else if (icon instanceof VectorDrawable) {
+                // If it's a VectorDrawable, we don't need to scale it.
+                d = icon;
+            } else {
+                // Other than that, we just use blank.
+                d = getBlankDrawable(res);
+            }
+
         } else if (item.inGroup) {
             // We don't currently support "indenting" items with icons
             d = getBlankDrawable(res);
         }
 
         Drawable moreDrawable = null;
         if (item.isParent) {
             moreDrawable = getMoreDrawable(res);