Bug 839771 - Use a compound drawable to add padding to select elements. r=sriram
authorWes Johnston <wjohnston@mozilla.com>
Thu, 21 Feb 2013 08:41:41 -0800
changeset 122554 e91be95894d1fe079d1cb7ca3b8f5ba5296bbf78
parent 122553 601c2d37c2bc9d7943807e9a3a94b665eb1ef7d0
child 122555 9ed862817d8d9e0e5aeba22a00d8020ba61fa041
push id23368
push userwjohnston@mozilla.com
push dateThu, 21 Feb 2013 16:42:05 +0000
treeherdermozilla-inbound@9ed862817d8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs839771
milestone22.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 839771 - Use a compound drawable to add padding to select elements. r=sriram
mobile/android/base/Makefile.in
mobile/android/base/PromptService.java
mobile/android/base/resources/drawable-hdpi/blank.png
mobile/android/base/resources/drawable-mdpi/blank.png
mobile/android/base/resources/drawable-xhdpi/blank.png
mobile/android/chrome/content/SelectHelper.js
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -506,16 +506,17 @@ RES_ANIM = \
   res/anim/awesomebar_fade_out.xml \
   res/anim/awesomebar_hold_still.xml \
   res/anim/grow_fade_in.xml \
   res/anim/grow_fade_in_center.xml \
   res/anim/shrink_fade_out.xml \
   $(NULL)
 
 RES_DRAWABLE_MDPI = \
+  res/drawable-mdpi/blank.png \
   res/drawable-mdpi/favicon.png \
   res/drawable-mdpi/folder.png \
   res/drawable-mdpi/abouthome_icon.png \
   res/drawable-mdpi/abouthome_logo_dark.png \
   res/drawable-mdpi/abouthome_logo_light.png \
   res/drawable-mdpi/abouthome_promo_box_bg.9.png \
   res/drawable-mdpi/abouthome_promo_box_pressed_bg.9.png \
   res/drawable-mdpi/abouthome_promo_logo_apps.png \
@@ -617,16 +618,17 @@ RES_DRAWABLE_MDPI = \
   $(addprefix res/drawable-mdpi/,$(notdir $(SYNC_RES_DRAWABLE_MDPI))) \
   $(NULL)
 
 RES_DRAWABLE_LDPI = \
   $(addprefix res/drawable-ldpi/,$(notdir $(SYNC_RES_DRAWABLE_LDPI))) \
   $(NULL)
 
 RES_DRAWABLE_HDPI = \
+  res/drawable-hdpi/blank.png \
   res/drawable-hdpi/favicon.png \
   res/drawable-hdpi/folder.png \
   res/drawable-hdpi/home_bg.png \
   res/drawable-hdpi/home_star.png \
   res/drawable-hdpi/abouthome_icon.png \
   res/drawable-hdpi/abouthome_logo_dark.png \
   res/drawable-hdpi/abouthome_logo_light.png \
   res/drawable-hdpi/abouthome_promo_box_bg.9.png \
@@ -707,16 +709,17 @@ RES_DRAWABLE_HDPI = \
   res/drawable-hdpi/validation_bg.9.png \
   res/drawable-hdpi/handle_end.png \
   res/drawable-hdpi/handle_middle.png \
   res/drawable-hdpi/handle_start.png \
   $(addprefix res/drawable-hdpi/,$(notdir $(SYNC_RES_DRAWABLE_HDPI))) \
   $(NULL)
 
 RES_DRAWABLE_XHDPI = \
+  res/drawable-xhdpi/blank.png \
   res/drawable-xhdpi/favicon.png \
   res/drawable-xhdpi/folder.png \
   res/drawable-xhdpi/abouthome_icon.png \
   res/drawable-xhdpi/abouthome_logo_dark.png \
   res/drawable-xhdpi/abouthome_logo_light.png \
   res/drawable-xhdpi/abouthome_promo_box_bg.9.png \
   res/drawable-xhdpi/abouthome_promo_box_pressed_bg.9.png \
   res/drawable-xhdpi/abouthome_promo_logo_apps.png \
--- a/mobile/android/base/PromptService.java
+++ b/mobile/android/base/PromptService.java
@@ -584,16 +584,18 @@ public class PromptService implements On
 
     public class PromptListAdapter extends ArrayAdapter<PromptListItem> {
         private static final int VIEW_TYPE_ITEM = 0;
         private static final int VIEW_TYPE_GROUP = 1;
         private static final int VIEW_TYPE_COUNT = 2;
 
         public ListView listView;
         private int mResourceId = -1;
+        private Drawable mBlankDrawable = null;
+        private Drawable mMoreDrawable = null;
 
         PromptListAdapter(Context context, int textViewResourceId, PromptListItem[] objects) {
             super(context, textViewResourceId, objects);
             mResourceId = textViewResourceId;
         }
 
         @Override
         public int getItemViewType(int position) {
@@ -601,55 +603,61 @@ public class PromptService implements On
             return (item.isGroup ? VIEW_TYPE_GROUP : VIEW_TYPE_ITEM);
         }
 
         @Override
         public int getViewTypeCount() {
             return VIEW_TYPE_COUNT;
         }
 
+        private Drawable getMoreDrawable(Resources res) {
+            if (mMoreDrawable == null) {
+                mMoreDrawable = res.getDrawable(android.R.drawable.ic_menu_more);
+            }
+            return mMoreDrawable;
+        }
+
+        private Drawable getBlankDrawable(Resources res) {
+            if (mBlankDrawable == null) {
+                mBlankDrawable = res.getDrawable(R.drawable.blank);
+            }
+            return mBlankDrawable;
+        }
+
         private void maybeUpdateIcon(PromptListItem item, TextView t) {
-            if (item.icon == null && !item.isParent) {
+            if (item.icon == null && !item.inGroup && !item.isParent) {
                 t.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                 return;
             }
 
             Drawable d = null;
             Resources res = GeckoApp.mAppContext.getResources();
             // Set the padding between the icon and the text.
             t.setCompoundDrawablePadding(mIconTextPadding);
             if (item.icon != null) {
-                // Set padding inside the item.
-                t.setPadding(item.inGroup ? mLeftRightTextWithIconPadding + mGroupPaddingSize :
-                                            mLeftRightTextWithIconPadding,
-                             mTopBottomTextWithIconPadding,
-                             mLeftRightTextWithIconPadding,
-                             mTopBottomTextWithIconPadding);
                 // 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();
                 d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
+            } else if (item.inGroup) {
+                // We don't currently support "indenting" items with icons
+                d = getBlankDrawable(res);
             }
 
             Drawable moreDrawable = null;
             if (item.isParent) {
-                moreDrawable = res.getDrawable(android.R.drawable.ic_menu_more);
+                moreDrawable = getMoreDrawable(res);
             }
 
             if (d != null || moreDrawable != null) {
                 t.setCompoundDrawablesWithIntrinsicBounds(d, null, moreDrawable, null);
             }
         }
 
         private void maybeUpdateCheckedState(int position, PromptListItem item, ViewHolder viewHolder) {
-            viewHolder.textView.setPadding((item.inGroup ? mGroupPaddingSize : viewHolder.paddingLeft),
-                                            viewHolder.paddingTop,
-                                            viewHolder.paddingRight,
-                                            viewHolder.paddingBottom);
-
             viewHolder.textView.setEnabled(!item.disabled && !item.isGroup);
             viewHolder.textView.setClickable(item.isGroup || item.disabled);
 
             if (mSelected == null)
                 return;
 
             CheckedTextView ct;
             try {
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..11d5b6a914c627e60744ad6a06233698c899b9ff
GIT binary patch
literal 140
zc%17D@N?(olHy`uVBq!ia0vp^DnQK0!3HF^CGyCEIK@HkP7LeL$-D$|*pj^6T^Rm@
z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPggqCSfs2HiHXy*8_!kJY5_^IIbrr
aNTdLH6B!u8#XhS8Sqz@8elF{r5}E+;Ss!u$
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6773a96d287a9e7beac5a225d3b765d061c91d06
GIT binary patch
literal 140
zc%17D@N?(olHy`uVBq!ia0vp^5<twz!3HFctjk*s;uHtDJ29*~C-V}>VN3FMcVYMs
zf(!O8p9~b?EbxddW?<kJ24O~qS#v-Ju$OrHy0YJ85*Cx>v*Qk(3l!q<ba4#fxSpJ_
az!1nwWMG`8)BP35V(@hJb6Mw<&;$Tf%pgbr
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c6d417b25ac4462268ef8e7f7ae5ee0ca285a63c
GIT binary patch
literal 140
zc%17D@N?(olHy`uVBq!ia0vp^20+Zn!3HE}sOa{CIK@HkP7LeL$-D$|*pj^6T^Rm@
z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPggqCSfs2@u-Bqu|OdnPZ!4!j_b(@
a5|4nqgA9xpa+u<QECx?kKbLh*2~7YGMj#Ua
--- a/mobile/android/chrome/content/SelectHelper.js
+++ b/mobile/android/chrome/content/SelectHelper.js
@@ -8,17 +8,17 @@ var SelectHelper = {
 
   handleEvent: function(aEvent) {
     this.handleClick(aEvent.target);
   },
 
   handleClick: function(aTarget) {
     // if we're busy looking at a select we want to eat any clicks that
     // come to us, but not to process them
-    if (this._uiBusy || !this._isMenu(aTarget))
+    if (this._uiBusy || !this._isMenu(aTarget) || aTarget.disabled)
         return;
 
     this._uiBusy = true;
     this.show(aTarget);
     this._uiBusy = false;
   },
 
   show: function(aElement) {