ソースを参照

Input filters builder support, resolves #1480

Aidan Follestad 7 年 前
コミット
5574b5999c

+ 8 - 2
core/src/main/java/com/afollestad/materialdialogs/DialogInit.java

@@ -366,7 +366,8 @@ class DialogInit {
           // Setting padding to an EditText causes visual errors, set it to the parent instead
           sv.setPadding(framePadding, paddingTop, framePadding, paddingBottom);
         } else {
-          // Setting padding to scroll view pushes the scroll bars out, don't do it if not necessary (like above)
+          // Setting padding to scroll view pushes the scroll bars out, don't do it if not necessary
+          // (like above)
           sv.setPadding(0, paddingTop, 0, paddingBottom);
           innerView.setPadding(framePadding, 0, framePadding, 0);
         }
@@ -530,7 +531,8 @@ class DialogInit {
       if (builder.inputType != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
           && (builder.inputType & InputType.TYPE_TEXT_VARIATION_PASSWORD)
               == InputType.TYPE_TEXT_VARIATION_PASSWORD) {
-        // If the flags contain TYPE_TEXT_VARIATION_PASSWORD, apply the password transformation method automatically
+        // If the flags contain TYPE_TEXT_VARIATION_PASSWORD, apply the password transformation
+        // method automatically
         dialog.input.setTransformationMethod(PasswordTransformationMethod.getInstance());
       }
     }
@@ -543,5 +545,9 @@ class DialogInit {
       dialog.inputMinMax.setVisibility(View.GONE);
       dialog.inputMinMax = null;
     }
+
+    if (builder.inputFilters != null) {
+      dialog.input.setFilters(builder.inputFilters);
+    }
   }
 }

+ 7 - 0
core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -26,6 +26,7 @@ import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.text.Editable;
 import android.text.Html;
+import android.text.InputFilter;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.Log;
@@ -1114,6 +1115,7 @@ public class MaterialDialog extends DialogBase
     protected CharSequence checkBoxPrompt;
     protected boolean checkBoxPromptInitiallyChecked;
     protected CheckBox.OnCheckedChangeListener checkBoxPromptListener;
+    protected InputFilter[] inputFilters;
 
     protected String progressNumberFormat;
     protected NumberFormat progressPercentFormat;
@@ -2119,6 +2121,11 @@ public class MaterialDialog extends DialogBase
       return inputRange(minLength, maxLength, DialogUtils.getColor(context, errorColor));
     }
 
+    public Builder inputFilters(@Nullable InputFilter... filters) {
+      this.inputFilters = filters;
+      return this;
+    }
+
     public Builder alwaysCallInputCallback() {
       this.alwaysCallInputCallback = true;
       return this;