Bug 1378617 - Fix ClassCastException if the icon is not a BitmapDrawable. r?sebastian
MozReview-Commit-ID: IU9hOPEA7eb
--- 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);