Browse Source

- InputInfo新增方法:`getInputFilters()`、`setInputFilters(InputFilter[] inputFilters)`、`addInputFilter(InputFilter inputFilter)` 和 `removeInputFilter(InputFilter inputFilter)`

0.0.49.beta1
- 修复 BlurRelativeLayout 和 BlurLinearLayout 在 iOS 主题下使用 DialogFragment 模式时存在的渲染宽度和高度 <=0 导致的异常(issues:324);
- 修复 IOS 主题下可能存在的 `RSInvalidStateException: Calling RS with no Context active` 异常问题(issues:327);
- 修复可能存在的高频启关对话框过程中,因UI未完成构建被关闭引发的空指针异常(issues:331);
Kongzue 1 năm trước cách đây
mục cha
commit
2d41dfc42e

+ 3 - 0
DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java

@@ -652,6 +652,9 @@ public class MessageDialog extends BaseDialog {
                 if (inputInfo.getTextInfo() != null) {
                     useTextInfo(txtInput, inputInfo.getTextInfo());
                 }
+                if (inputInfo.getInputFilters() != null && inputInfo.getInputFilters().length > 0) {
+                    txtInput.setFilters(inputInfo.getInputFilters());
+                }
             }
 
             int visibleButtonCount = 0;

+ 54 - 17
DialogX/src/main/java/com/kongzue/dialogx/util/InputInfo.java

@@ -1,7 +1,11 @@
 package com.kongzue.dialogx.util;
 
+import android.text.InputFilter;
+
 import androidx.annotation.ColorInt;
 
+import java.util.Arrays;
+
 /**
  * Author: @Kongzue
  * Github: https://github.com/kongzue/
@@ -10,82 +14,115 @@ import androidx.annotation.ColorInt;
  * CreateTime: 2018/11/8 21:41
  */
 public class InputInfo {
-    
+
     private int MAX_LENGTH = -1;    //最大长度,-1不生效
     private int inputType;          //类型详见 android.text.InputType
     private TextInfo textInfo;      //默认字体样式
     private boolean multipleLines;  //支持多行
     private boolean selectAllText;  //默认选中所有文字(便于修改)
-    
+
     private Integer cursorColor;    //输入框光标颜色
     private Integer bottomLineColor;//输入框横线颜色
-    
+
+    private InputFilter[] inputFilters; //输入过滤器
+
     public int getMAX_LENGTH() {
         return MAX_LENGTH;
     }
-    
+
     public InputInfo setMAX_LENGTH(int MAX_LENGTH) {
         this.MAX_LENGTH = MAX_LENGTH;
         return this;
     }
-    
+
     public int getInputType() {
         return inputType;
     }
-    
+
     public InputInfo setInputType(int inputType) {
         this.inputType = inputType;
         return this;
     }
-    
+
     public TextInfo getTextInfo() {
         return textInfo;
     }
-    
+
     public InputInfo setTextInfo(TextInfo textInfo) {
         this.textInfo = textInfo;
         return this;
     }
-    
+
     public boolean isMultipleLines() {
         return multipleLines;
     }
-    
+
     public InputInfo setMultipleLines(boolean multipleLines) {
         this.multipleLines = multipleLines;
         return this;
     }
-    
+
     public boolean isSelectAllText() {
         return selectAllText;
     }
-    
+
     public InputInfo setSelectAllText(boolean selectAllText) {
         this.selectAllText = selectAllText;
         return this;
     }
-    
+
     public Integer getCursorColor() {
         return cursorColor;
     }
-    
+
     public InputInfo setCursorColor(@ColorInt int cursorColor) {
         this.cursorColor = cursorColor;
         return this;
     }
-    
+
     public InputInfo setThemeColor(@ColorInt int themeColor) {
         this.cursorColor = themeColor;
         this.bottomLineColor = themeColor;
         return this;
     }
-    
+
     public Integer getBottomLineColor() {
         return bottomLineColor;
     }
-    
+
     public InputInfo setBottomLineColor(int bottomLineColor) {
         this.bottomLineColor = bottomLineColor;
         return this;
     }
+
+    public InputFilter[] getInputFilters() {
+        return inputFilters;
+    }
+
+    public InputInfo setInputFilters(InputFilter[] inputFilters) {
+        this.inputFilters = inputFilters;
+        return this;
+    }
+
+    public InputInfo addInputFilter(InputFilter inputFilter) {
+        if (this.inputFilters == null) {
+            this.inputFilters = new InputFilter[]{inputFilter};
+        } else {
+            this.inputFilters = Arrays.copyOf(this.inputFilters, this.inputFilters.length + 1);
+            this.inputFilters[this.inputFilters.length - 1] = inputFilter;
+        }
+        return this;
+    }
+
+    public InputInfo removeInputFilter(InputFilter inputFilter) {
+        if (this.inputFilters!= null) {
+            for (int i = 0; i < this.inputFilters.length; i++) {
+                if (this.inputFilters[i] == inputFilter) {
+                    this.inputFilters = Arrays.copyOf(this.inputFilters, this.inputFilters.length - 1);
+                    return this;
+                }
+            }
+        }
+        return this;
+    }
 }