-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1, 优化颜色设置方式, 由颜色值改为资源ID EdtLinkBtnUtil: 1, 新增, 根据EditText内容长度控制Button按钮Enable状态
- Loading branch information
Showing
2 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
library/src/main/java/com/lt/library/util/EdtLinkBtnUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.lt.library.util; | ||
|
||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.util.ArrayMap; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import java.util.Map; | ||
|
||
public class EdtLinkBtnUtil implements TextWatcher { | ||
private ArrayMap<EditText, Integer> mEditTextMap; | ||
private Button mButton; | ||
|
||
private EdtLinkBtnUtil() { | ||
mEditTextMap = new ArrayMap<>(); | ||
} | ||
|
||
@Override | ||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||
} | ||
|
||
@Override | ||
public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
} | ||
|
||
@Override | ||
public void afterTextChanged(Editable s) { | ||
boolean isEnable = false; | ||
for (Map.Entry<EditText, Integer> entry : mEditTextMap.entrySet()) { | ||
EditText edt = entry.getKey(); | ||
Integer btnEnableLength = entry.getValue(); | ||
if (edt.getText().length() < btnEnableLength) { | ||
isEnable = false; | ||
break; | ||
} else { | ||
isEnable = true; | ||
} | ||
} | ||
mButton.setEnabled(isEnable); | ||
} | ||
|
||
public void addEvent() { | ||
for (Map.Entry<EditText, Integer> entry : mEditTextMap.entrySet()) { | ||
EditText editText = entry.getKey(); | ||
editText.addTextChangedListener(this); | ||
} | ||
} | ||
|
||
public void delEvent() { | ||
for (Map.Entry<EditText, Integer> entry : mEditTextMap.entrySet()) { | ||
EditText editText = entry.getKey(); | ||
editText.removeTextChangedListener(this); | ||
} | ||
} | ||
|
||
public static class Builder { | ||
private EdtLinkBtnUtil mEdtLinkBtnUtil; | ||
|
||
public Builder() { | ||
mEdtLinkBtnUtil = new EdtLinkBtnUtil(); | ||
} | ||
|
||
public Builder addEditText(EditText editText, int btnEnableLength) { | ||
mEdtLinkBtnUtil.mEditTextMap.put(editText, btnEnableLength); | ||
return this; | ||
} | ||
|
||
public Builder setButton(Button button) { | ||
mEdtLinkBtnUtil.mButton = button; | ||
mEdtLinkBtnUtil.mButton.setEnabled(false); | ||
return this; | ||
} | ||
|
||
public EdtLinkBtnUtil build() { | ||
return mEdtLinkBtnUtil; | ||
} | ||
} | ||
} |