Bug 735636 - Factor out checked state update into separate method (r=wesj)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 30 Mar 2012 17:31:31 +0100
changeset 90735 130e702908ca5f21364fd080edaf156d10e71e06
parent 90734 bb20be085b35a2cc1087d49aa763aa0d9c0bb570
child 90736 61964245b303642e64d2e301ce67f87a61ac2d91
push id22382
push userbmo@edmorley.co.uk
push dateSat, 31 Mar 2012 21:44:34 +0000
treeherdermozilla-central@bbe5086163c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs735636
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 735636 - Factor out checked state update into separate method (r=wesj)
mobile/android/base/PromptService.java
--- a/mobile/android/base/PromptService.java
+++ b/mobile/android/base/PromptService.java
@@ -517,62 +517,69 @@ public class PromptService implements On
             // 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);
         }
 
+        private void maybeUpdateCheckedState(int position, PromptListItem item, ViewHolder viewHolder) {
+            if (item.isGroup)
+                return;
+
+            CheckedTextView ct;
+            try {
+                ct = (CheckedTextView) viewHolder.textView;
+            } catch (Exception e) {
+                return;
+            }
+
+            ct.setEnabled(!item.disabled);
+            ct.setClickable(item.disabled);
+
+            // Apparently just using ct.setChecked(true) doesn't work, so this
+            // is stolen from the android source code as a way to set the checked
+            // state of these items
+            if (listView != null)
+                listView.setItemChecked(position, mSelected[position]);
+
+            ct.setPadding((item.inGroup ? mGroupPaddingSize : viewHolder.paddingLeft),
+                          viewHolder.paddingTop,
+                          viewHolder.paddingRight,
+                          viewHolder.paddingBottom);
+        }
+
         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;
                 }
 
                 convertView = mInflater.inflate(resourceId, null);
 
                 viewHolder = new ViewHolder();
                 viewHolder.textView = (TextView) convertView.findViewById(android.R.id.text1);
+
                 viewHolder.paddingLeft = viewHolder.textView.getPaddingLeft();
                 viewHolder.paddingRight = viewHolder.textView.getPaddingRight();
                 viewHolder.paddingTop = viewHolder.textView.getPaddingTop();
                 viewHolder.paddingBottom = viewHolder.textView.getPaddingBottom();
 
                 convertView.setTag(viewHolder);
             } else {
                 viewHolder = (ViewHolder) convertView.getTag();
             }
 
-            if (!item.isGroup){
-                try {
-                    CheckedTextView ct = (CheckedTextView) viewHolder.textView;
-                    if (ct != null){
-                        ct.setEnabled(!item.disabled);
-                        ct.setClickable(item.disabled);
-
-                        // Apparently just using ct.setChecked(true) doesn't work, so this
-                        // is stolen from the android source code as a way to set the checked
-                        // state of these items
-                        if (listView != null)
-                            listView.setItemChecked(position, mSelected[position]);
-
-                        ct.setPadding((item.inGroup ? mGroupPaddingSize : viewHolder.paddingLeft),
-                                      viewHolder.paddingTop,
-                                      viewHolder.paddingRight,
-                                      viewHolder.paddingBottom);
-                    }
-                } catch (Exception ex) { }
-            }
-
             viewHolder.textView.setText(item.label);
+            maybeUpdateCheckedState(position, item, viewHolder);
             maybeUpdateIcon(item, viewHolder.textView);
 
             return convertView;
         }
 
         private class ViewHolder {
             public TextView textView;
             public int paddingLeft;