本文整理汇总了Java中android.text.InputFilter.LengthFilter方法的典型用法代码示例。如果您正苦于以下问题:Java InputFilter.LengthFilter方法的具体用法?Java InputFilter.LengthFilter怎么用?Java InputFilter.LengthFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.InputFilter
的用法示例。
在下文中一共展示了InputFilter.LengthFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCardIcon
import android.text.InputFilter; //导入方法依赖的package包/类
private Card setCardIcon(String source) {
Card card = new CardValidator(source).guessCard();
InputFilter[] FilterArray = new InputFilter[1];
if (card != null) {
int maxLength = Integer.parseInt(String.valueOf(card.getMaxLength()));
FilterArray[0] = new InputFilter.LengthFilter(getSpacedPanLength(maxLength));
mCardTextInputLayout.getEditText().setCompoundDrawablesRelativeWithIntrinsicBounds(ContextCompat.getDrawable(mCardTextInputLayout.getContext(), card.getDrawable()), null, null, null);
} else {
FilterArray[0] = new InputFilter.LengthFilter(getSpacedPanLength(19));
mCardTextInputLayout.getEditText().setCompoundDrawablesRelativeWithIntrinsicBounds(ContextCompat.getDrawable(mCardTextInputLayout.getContext(), R.drawable.payment_method_generic_card), null, null, null);
}
mCardTextInputLayout.getEditText().setFilters(FilterArray);
return card;
}
示例2: updateDropDownTextView
import android.text.InputFilter; //导入方法依赖的package包/类
private void updateDropDownTextView() {
if (dropDown != null) {
if (currentPasswordType == 0) {
dropDown.setText(LocaleController.getString("PasscodePIN", R.string.PasscodePIN));
} else if (currentPasswordType == 1) {
dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword));
}
}
if (type == 1 && currentPasswordType == 0 || type == 2 && UserConfig.passcodeType == 0) {
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(4);
passwordEditText.setFilters(filterArray);
passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890"));
} else if (type == 1 && currentPasswordType == 1 || type == 2 && UserConfig.passcodeType == 1) {
passwordEditText.setFilters(new InputFilter[0]);
passwordEditText.setKeyListener(null);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
示例3: setMaxLength
import android.text.InputFilter; //导入方法依赖的package包/类
@ReactProp(name = "maxLength")
public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {
InputFilter [] currentFilters = view.getFilters();
InputFilter[] newFilters = EMPTY_FILTERS;
if (maxLength == null) {
if (currentFilters.length > 0) {
LinkedList<InputFilter> list = new LinkedList<>();
for (int i = 0; i < currentFilters.length; i++) {
if (!(currentFilters[i] instanceof InputFilter.LengthFilter)) {
list.add(currentFilters[i]);
}
}
if (!list.isEmpty()) {
newFilters = (InputFilter[]) list.toArray(new InputFilter[list.size()]);
}
}
} else {
if (currentFilters.length > 0) {
newFilters = currentFilters;
boolean replaced = false;
for (int i = 0; i < currentFilters.length; i++) {
if (currentFilters[i] instanceof InputFilter.LengthFilter) {
currentFilters[i] = new InputFilter.LengthFilter(maxLength);
replaced = true;
}
}
if (!replaced) {
newFilters = new InputFilter[currentFilters.length + 1];
System.arraycopy(currentFilters, 0, newFilters, 0, currentFilters.length);
currentFilters[currentFilters.length] = new InputFilter.LengthFilter(maxLength);
}
} else {
newFilters = new InputFilter[1];
newFilters[0] = new InputFilter.LengthFilter(maxLength);
}
}
view.setFilters(newFilters);
}
示例4: setMaxLength
import android.text.InputFilter; //导入方法依赖的package包/类
public void setMaxLength(int length) {
InputFilter[] filters = getFilters();
boolean have = false;
InputFilter.LengthFilter lengthFilter = new InputFilter.LengthFilter(length);
for (int i = 0; i < filters.length; i++) {
InputFilter filter = filters[i];
if (filter instanceof InputFilter.LengthFilter) {
have = true;
filters[i] = lengthFilter;
setFilters(filters);
break;
}
}
if (!have) {
addFilter(lengthFilter);
}
}
示例5: setMaxLength
import android.text.InputFilter; //导入方法依赖的package包/类
public void setMaxLength(int length, boolean addMoreStringLength) {
InputFilter[] filters = getFilters();
boolean have = false;
InputFilter.LengthFilter lengthFilter = new InputFilter.LengthFilter(length + (addMoreStringLength ? getMoreString().length() : 0));
for (int i = 0; i < filters.length; i++) {
InputFilter filter = filters[i];
if (filter instanceof InputFilter.LengthFilter) {
have = true;
filters[i] = lengthFilter;
setFilters(filters);
break;
}
}
if (!have) {
addFilter(lengthFilter);
}
setMaxLines(1);
//setSingleLine();
setEllipsize(TextUtils.TruncateAt.END);
}
示例6: createExact
import android.text.InputFilter; //导入方法依赖的package包/类
@SuppressLint("InflateParams")
private View createExact() {
View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_color_exact, null);
mExactViewA = (EditText) view.findViewById(R.id.exactA);
mExactViewR = (EditText) view.findViewById(R.id.exactR);
mExactViewG = (EditText) view.findViewById(R.id.exactG);
mExactViewB = (EditText) view.findViewById(R.id.exactB);
InputFilter[] filters = new InputFilter[]{new InputFilter.LengthFilter(2)};
mExactViewA.setFilters(filters);
mExactViewR.setFilters(filters);
mExactViewG.setFilters(filters);
mExactViewB.setFilters(filters);
mExactViewA.setVisibility(mUseOpacityBar ? View.VISIBLE : View.GONE);
setExactColor(mInitialColor);
mExactColorPicker = (ColorWheelView) view.findViewById(R.id.picker_exact);
mExactColorPicker.setOldCenterColor(mInitialColor);
mExactColorPicker.setNewCenterColor(mNewColor);
return view;
}
示例7: inputFilter
import android.text.InputFilter; //导入方法依赖的package包/类
InputFilter[] inputFilter(final Context context) {
InputFilter filters[] = new InputFilter[2];
filters[0] = new InputFilter.LengthFilter(context.getResources().getInteger(R.integer.config_message_size));
filters[1] = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for(int index = start; index < end; index++) {
if(!new String(charset).contains(String.valueOf(source.charAt(index)))) {
Toast toast = Toast.makeText(context, context.getString(R.string.invalid_char), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return "";
}
}
return null;
}
};
return filters;
}
示例8: lengthChineseFilter
import android.text.InputFilter; //导入方法依赖的package包/类
/**
* 限制中文字符的长度
*/
public static void lengthChineseFilter(final EditText editText, final int length) {
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(length) {
public CharSequence filter(@NonNull CharSequence source, int start, int end, @NonNull Spanned dest, int dstart, int dend) {
// 可以检查中文字符
boolean isChinese = CharacterCheck.checkNameChese(source.toString());
if (!isChinese || dest.toString().length() >= length) {
return "";
}
return source;
}
};
// Sets the list of input filters that will be used if the buffer is Editable. Has no effect otherwise.
editText.setFilters(filters);
}
示例9: getEditTextMaxLength
import android.text.InputFilter; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static int getEditTextMaxLength(EditText editText){
int length=0;
InputFilter[] inputFilters = editText.getFilters();
for(InputFilter filter:inputFilters){
if(filter instanceof InputFilter.LengthFilter){
length = ((InputFilter.LengthFilter) filter).getMax();
}
}
return length;
}
示例10: generateOneEditText
import android.text.InputFilter; //导入方法依赖的package包/类
/**
* Takes care of styling the editText passed in the param.
* tag is the index of the editText.
*
* @param styleEditText
* @param tag
*/
private void generateOneEditText(EditText styleEditText, String tag) {
params.setMargins(mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2);
filters[0] = new InputFilter.LengthFilter(1);
styleEditText.setFilters(filters);
styleEditText.setLayoutParams(params);
styleEditText.setGravity(Gravity.CENTER);
styleEditText.setCursorVisible(mCursorVisible);
if (!mCursorVisible) {
styleEditText.setClickable(false);
styleEditText.setHint(mHint);
styleEditText.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// When back space is pressed it goes to delete mode and when u click on an edit Text it should get out of the delete mode
mDelPressed = false;
return false;
}
});
}
styleEditText.setBackgroundResource(mPinBackground);
styleEditText.setPadding(0, 0, 0, 0);
styleEditText.setTag(tag);
styleEditText.setInputType(getKeyboardInputType());
styleEditText.addTextChangedListener(this);
styleEditText.setOnFocusChangeListener(this);
styleEditText.setOnKeyListener(this);
}
示例11: setMaxLength
import android.text.InputFilter; //导入方法依赖的package包/类
public void setMaxLength(final int newMaxLength) {
this.maxLength = newMaxLength;
InputFilter[] inputFilters = getFilters();
for (int i = 0; i < inputFilters.length; i++) {
if (inputFilters[i] instanceof InputFilter.LengthFilter) {
inputFilters[i] = new InputFilter.LengthFilter(maxLength);
break;
}
}
this.setFilters(inputFilters);
if (this.getText().toString().length() > maxLength) {
this.setText(this.getText().toString().substring(0, maxLength));
}
}
示例12: onCreateView
import android.text.InputFilter; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_login, container, false);
_unbinder = ButterKnife.bind(this, view);
InputFilter filter = new InputFilter.LengthFilter(PINCODE_LENGTH);
_passwordInput.setFilters(new InputFilter[]{filter});
return view;
}
示例13: initFabText
import android.text.InputFilter; //导入方法依赖的package包/类
private void initFabText() {
if (fabText == null || fabText.length() == 0) {
return;
}
int maxLength = 25;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
setFilters(fArray);
setEllipsize(TextUtils.TruncateAt.END);
setTextColor(fabTextColor);
setText(fabText);
setAllCaps(fabTextAllCaps);
}
示例14: lengthFilter
import android.text.InputFilter; //导入方法依赖的package包/类
/**
* 限制内容长度
*/
public static void lengthFilter(final EditText editText, final int length) {
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(length) {
public CharSequence filter(@NonNull CharSequence source, int start, int end, @NonNull Spanned dest, int dstart, int dend) {
if (dest.toString().length() >= length) {
return "";
}
return source;
}
};
// Sets the list of input filters that will be used if the buffer is Editable. Has no effect otherwise.
editText.setFilters(filters);
}
示例15: setMaxLength
import android.text.InputFilter; //导入方法依赖的package包/类
@ReactProp(name = "maxLength")
public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {
InputFilter [] currentFilters = view.getFilters();
InputFilter[] newFilters = EMPTY_FILTERS;
if (maxLength == null) {
if (currentFilters.length > 0) {
LinkedList<InputFilter> list = new LinkedList<>();
for (int i = 0; i < currentFilters.length; i++) {
if (!(currentFilters[i] instanceof InputFilter.LengthFilter)) {
list.add(currentFilters[i]);
}
}
if (!list.isEmpty()) {
newFilters = (InputFilter[]) list.toArray();
}
}
} else {
if (currentFilters.length > 0) {
newFilters = currentFilters;
boolean replaced = false;
for (int i = 0; i < currentFilters.length; i++) {
if (currentFilters[i] instanceof InputFilter.LengthFilter) {
currentFilters[i] = new InputFilter.LengthFilter(maxLength);
replaced = true;
}
}
if (!replaced) {
newFilters = new InputFilter[currentFilters.length + 1];
System.arraycopy(currentFilters, 0, newFilters, 0, currentFilters.length);
currentFilters[currentFilters.length] = new InputFilter.LengthFilter(maxLength);
}
} else {
newFilters = new InputFilter[1];
newFilters[0] = new InputFilter.LengthFilter(maxLength);
}
}
view.setFilters(newFilters);
}