Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lblbc001 committed Jan 31, 2019
1 parent 1863927 commit e09fefb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 10 additions & 6 deletions clearedittextlib/src/main/java/com/cxyzy/cet/ClearEditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class ClearEditText extends AppCompatEditText implements OnFocusChangeLis
private boolean hasFocus;
private int start, count, before;
private int showType;
private String allowableCharacters;
private String textFormat;
private InputTextFormatter inputTextFormatter;

Expand All @@ -56,7 +55,6 @@ public ClearEditText(Context context, AttributeSet attrs, int defStyle) {
private void init(final Context context, @Nullable AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ClearEditText);
showType = typedArray.getInt(R.styleable.ClearEditText_showType, TYPE_COMMON);
allowableCharacters = typedArray.getString(R.styleable.ClearEditText_allowableCharacters);
textFormat = typedArray.getString(R.styleable.ClearEditText_textFormat);

inputTextFormatter = InputTextFormatterFactory.getFormatter(showType);
Expand All @@ -75,29 +73,35 @@ private void init(final Context context, @Nullable AttributeSet attrs) {
//设置输入框里面内容发生改变的监听
addTextChangedListener(this);

setAllowableCharacters();
setTextFormat();
setInputFilter();

}

if (TextUtils.isEmpty(allowableCharacters)) {
allowableCharacters = inputTextFormatter.getAllowableCharacters();
}
private void setAllowableCharacters() {
String allowableCharacters = inputTextFormatter.getAllowableCharacters();
if (!TextUtils.isEmpty(allowableCharacters)) {
if (!allowableCharacters.contains(" ")) {
allowableCharacters = allowableCharacters + " ";
}
setKeyListener(DigitsKeyListener.getInstance(allowableCharacters));
}
}

private void setTextFormat() {
if (!TextUtils.isEmpty(textFormat)) {
inputTextFormatter.setTextFormat(textFormat);
}
}

private void setInputFilter() {
if (getFilters() == null || getFilters().length == 0) {
InputFilter[] filters = inputTextFormatter.getInputFilter();
if (filters != null && filters.length != 0) {
setFilters(filters);
}
}

}

/**
Expand Down
1 change: 0 additions & 1 deletion clearedittextlib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<enum name="IDCardNo" value="3" />
</attr>
<attr name="textFormat" format="string"/>
<attr name="allowableCharacters" format="string"/>

</declare-styleable>

Expand Down

0 comments on commit e09fefb

Please sign in to comment.