Bug 958109 - Wrap prompt inputs so that we can add padding around them. r=margaret
authorWes Johnston <wjohnston@mozilla.com>
Tue, 18 Feb 2014 13:20:00 -0800
changeset 169648 6c387fa25e618d5fdbb6b95bb9bf8349166bf617
parent 169647 f43ffc6a3076fa8e8b9bc55e23e474752024818d
child 169649 dcdf818049ee0e449702fe4e09caac326fb46cad
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmargaret
bugs958109
milestone30.0a1
Bug 958109 - Wrap prompt inputs so that we can add padding around them. r=margaret
mobile/android/base/prompts/Prompt.java
--- a/mobile/android/base/prompts/Prompt.java
+++ b/mobile/android/base/prompts/Prompt.java
@@ -98,17 +98,17 @@ public class Prompt implements OnClickLi
             mInitialized = true;
         }
     }
 
     private View applyInputStyle(View view, PromptInput input) {
         // Don't add padding to color picker views
         if (input.canApplyInputStyle()) {
             view.setPadding(mInputPaddingSize, 0, mInputPaddingSize, 0);
-	}
+        }
         return view;
     }
 
     public void show(JSONObject message) {
         processMessage(message);
     }
 
     public void show(String title, String text, PromptListItem[] listItems, boolean multipleSelection) {
@@ -309,16 +309,30 @@ public class Prompt implements OnClickLi
      *        The items to add.
      */
     private void addMenuList(AlertDialog.Builder builder, PromptListItem[] listItems) {
         PromptListAdapter adapter = new PromptListAdapter(mContext, android.R.layout.simple_list_item_1, listItems);
         builder.setAdapter(adapter, this);
         mSelected = null;
     }
 
+
+    /* Wraps an input in a linearlayout. We do this so that we can set padding that appears outside the background
+     * drawable for the view.
+     */
+    private View wrapInput(final PromptInput input) {
+        final LinearLayout linearLayout = new LinearLayout(mContext);
+        linearLayout.setOrientation(LinearLayout.VERTICAL);
+        applyInputStyle(linearLayout, input);
+
+        linearLayout.addView(input.getView(mContext));
+
+        return linearLayout;
+    }
+
     /* Add the requested input elements to the dialog.
      *
      * @param builder
      *        the alert builder currently building this dialog.
      * @return 
      *         return true if the inputs were added successfully. This may fail
      *         if the requested input is compatible with this Android verison
      */
@@ -328,28 +342,28 @@ public class Prompt implements OnClickLi
             return true;
         }
 
         try {
             View root = null;
             boolean scrollable = false; // If any of the innuts are scrollable, we won't wrap this in a ScrollView
 
             if (length == 1) {
-                root = mInputs[0].getView(mContext);
-                applyInputStyle(root, mInputs[0]);
+                root = wrapInput(mInputs[0]);
                 scrollable |= mInputs[0].getScrollable();
             } else if (length > 1) {
                 LinearLayout linearLayout = new LinearLayout(mContext);
                 linearLayout.setOrientation(LinearLayout.VERTICAL);
+
                 for (int i = 0; i < length; i++) {
-                    View content = mInputs[i].getView(mContext);
-                    applyInputStyle(content, mInputs[i]);
+                    View content = wrapInput(mInputs[i]);
                     linearLayout.addView(content);
                     scrollable |= mInputs[i].getScrollable();
                 }
+
                 root = linearLayout;
             }
 
             if (scrollable) {
                 builder.setView(root);
             } else {
                 ScrollView view = new ScrollView(mContext);
                 view.addView(root);