Bug 735636 - Factor out icon update into separate method (r=wesj)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 30 Mar 2012 17:31:31 +0100
changeset 90690 c2ababf0ea20bd9d0c81b19172b98c66a2cca079
parent 90689 c883b789280f63dba67e4a7783a5158db01cf94f
child 90691 a6515bb070f4656db2f2d4533d7fd9a3560d9954
push id1069
push usermfinkle@mozilla.com
push dateWed, 04 Apr 2012 14:22:33 +0000
treeherdermozilla-aurora@883536e3b5da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs735636
milestone13.0a2
Bug 735636 - Factor out icon update into separate method (r=wesj)
mobile/android/base/PromptService.java
--- a/mobile/android/base/PromptService.java
+++ b/mobile/android/base/PromptService.java
@@ -493,16 +493,40 @@ public class PromptService implements On
             return (item.isGroup ? VIEW_TYPE_GROUP : VIEW_TYPE_ITEM);
         }
 
         @Override
         public int getViewTypeCount() {
             return VIEW_TYPE_COUNT;
         }
 
+        private void maybeUpdateIcon(PromptListItem item, TextView t) {
+            if (item.icon == null)
+                return;
+
+            Resources res = GeckoApp.mAppContext.getResources();
+
+            // Set padding inside the item.
+            t.setPadding(item.inGroup ? mLeftRightTextWithIconPadding + mGroupPaddingSize :
+                                        mLeftRightTextWithIconPadding,
+                         mTopBottomTextWithIconPadding,
+                         mLeftRightTextWithIconPadding,
+                         mTopBottomTextWithIconPadding);
+
+            // Set the padding between the icon and the text.
+            t.setCompoundDrawablePadding(mIconTextPadding);
+
+            // 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.icon).getBitmap();
+            Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
+
+            t.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
+        }
+
         public View getView(int position, View convertView, ViewGroup parent) {
             PromptListItem item = getItem(position);
             ViewHolder viewHolder = null;
 
             if (convertView == null) {
                 int resourceId = mResourceId;
                 if (item.isGroup) {
                     resourceId = R.layout.list_item_header;
@@ -538,39 +562,18 @@ public class PromptService implements On
                         ct.setPadding((item.inGroup ? mGroupPaddingSize : viewHolder.paddingLeft),
                                       viewHolder.paddingTop,
                                       viewHolder.paddingRight,
                                       viewHolder.paddingBottom);
                     }
                 } catch (Exception ex) { }
             }
 
-            if (viewHolder.textView != null) {
-                final TextView t1 = viewHolder.textView;
-                t1.setText(item.label);
-
-                if (item.icon != null) {
-                    Resources res = GeckoApp.mAppContext.getResources();
-
-                    // Set padding inside the item.
-                    t1.setPadding(item. inGroup ? mLeftRightTextWithIconPadding + mGroupPaddingSize : mLeftRightTextWithIconPadding,
-                                  mTopBottomTextWithIconPadding,
-                                  mLeftRightTextWithIconPadding, mTopBottomTextWithIconPadding);
-
-                    // Set the padding between the icon and the text.
-                    t1.setCompoundDrawablePadding(mIconTextPadding);
-
-                    // 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.icon).getBitmap();
-                    Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
-
-                    t1.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
-                }
-            }
+            viewHolder.textView.setText(item.label);
+            maybeUpdateIcon(item, viewHolder.textView);
 
             return convertView;
         }
 
         private class ViewHolder {
             public TextView textView;
             public int paddingLeft;
             public int paddingRight;