Java 类android.text.InputFilter 实例源码

项目:CXJPadProject    文件:NormalUtil.java   
public static void keepEditTwoPoint(EditText editText) {
    editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
    editText.setFilters(new InputFilter[]{new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (source.equals(".") && dest.toString().length() == 0) {
                return "0.";
            }
            if (dest.toString().contains(".")) {
                int index = dest.toString().indexOf(".");
                int mlength = dest.toString().substring(index).length();
                if (mlength == 3) {
                    return "";
                }
            }
            return null;
        }
    }});
}
项目:adyen-android    文件:ExpiryDateEditText.java   
private void init() {
    ArrayList<InputFilter> dateFilters = new ArrayList<>();
    dateFilters.add(new InputFilter.LengthFilter(EDIT_TEXT_MAX_LENGTH));
    this.setFilters(dateFilters.toArray(new InputFilter[dateFilters.size()]));
    this.addTextChangedListener(new ExpiryDateFormatWatcher());

    setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                ExpiryDateEditText.this.setTextColor(ContextCompat.getColor(getContext(), R.color.black_text));
            } else {
                if (!isInputDateValid(ExpiryDateEditText.this.getText().toString())) {
                    ExpiryDateEditText.this.setTextColor(ContextCompat.getColor(getContext(),
                            R.color.red_invalid_input_highlight));
                }
            }
        }
    });
}
项目:africastalking-android    文件:CardNumberTextWatcher.java   
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;
}
项目:androidtools    文件:StringUtils.java   
/**
 * Input frame character length limit
 *
 * @param mEdit     EditText
 * @param maxLength maxLength
 */
public void setEditable(EditText mEdit, int maxLength) {
    if (mEdit.getText().length() < maxLength) {
        mEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength) {
        }});
        mEdit.setCursorVisible(true);
        mEdit.setFocusableInTouchMode(true);
        mEdit.requestFocus();
    } else {
        mEdit.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
            }
        }});
        mEdit.setCursorVisible(false);
        mEdit.setFocusableInTouchMode(false);
        mEdit.clearFocus();
    }
}
项目:AssistantBySDK    文件:CommonEditDialog.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i("CommonEditDialog", "onCreate>>limits=" + inputLimits);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.common_edit_dialog);
    findViewById(R.id.ced_confirm).setOnClickListener(this);
    findViewById(R.id.ced_title).setOnClickListener(this);
    ((TextView) findViewById(R.id.ced_confirm)).setText(confirm);
    ((TextView) findViewById(R.id.ced_title)).setText(title);
    textInputLayout = (TextInputLayout) findViewById(R.id.edit_content);
    textInputLayout.getEditText().setText(content);
    textInputLayout.getEditText().setHint(contentHint);
    int textLength = textInputLayout.getEditText().length();
    textInputLayout.getEditText().setSelection(textLength);//设置光标位置
    textInputLayout.getEditText().addTextChangedListener(tw);
    textInputLayout.getEditText().setFilters(new InputFilter[]{new InputFilter.LengthFilter(inputLimits)});
    if (oneButtonOnly) {
        findViewById(R.id.ced_cancel).setVisibility(View.GONE);
    } else {
        ((TextView) findViewById(R.id.ced_cancel)).setText(cancel);
        findViewById(R.id.ced_cancel).setOnClickListener(this);
    }
}
项目:airgram    文件:PasscodeActivity.java   
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());
}
项目:MyLife    文件:TextViewUtils.java   
public static void setMaxLength(TextView textView, int length) {
    InputFilter[] inputFilters = textView.getFilters();
    ArrayList<InputFilter> inputFilterArray = new ArrayList<InputFilter>();

    if (inputFilters != null) {
        for (int i = 0; i < inputFilters.length; i++) {
            InputFilter inputFilter = inputFilters[i];

            if (!(inputFilter instanceof LengthFilter))
                inputFilterArray.add(inputFilter);
        }

    }
    inputFilterArray.add(new LengthFilter(length));
    textView.setFilters(inputFilterArray.toArray(new InputFilter[0]));
}
项目:Luhn    文件:CardNumberTextWatcher.java   
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;
}
项目:PlusGram    文件:PasscodeActivity.java   
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());
}
项目:ViewCacheManager    文件:MainActivity.java   
private View getItemView() {
    LinearLayout mItemLayout = new LinearLayout(this);
    mItemLayout.setGravity(Gravity.CENTER);
    mItemLayout.setOrientation(LinearLayout.VERTICAL);


    ImageView mImageView = new ImageView(this);
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(ui_dip2px(50), ui_dip2px(50));
    mImageView.setLayoutParams(mParams);
    mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);


    TextView mTextView = new TextView(this);
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
    mTextView.setTextColor(Color.BLUE);

    mItemLayout.addView(mImageView);
    mItemLayout.addView(mTextView);


    return mItemLayout;
}
项目:decoy    文件:LoginActivity.java   
/**
 * 登录面板
 */
private void setupLoginPanel() {
    loginAccountEdit = findView(R.id.edit_login_account);
    loginPasswordEdit = findView(R.id.edit_login_password);

    loginAccountEdit.setIconResource(R.drawable.user_account_icon);
    loginPasswordEdit.setIconResource(R.drawable.user_pwd_lock_icon);

    loginAccountEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(32)});
    loginPasswordEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(32)});
    loginAccountEdit.addTextChangedListener(textWatcher);
    loginPasswordEdit.addTextChangedListener(textWatcher);
    loginPasswordEdit.setOnKeyListener(this);

    String account = Preferences.getUserAccount();
    loginAccountEdit.setText(account);
}
项目:decoy    文件:UserProfileEditItemActivity.java   
private void findEditText() {
    editText = findView(R.id.edittext);
    if (key == UserConstant.KEY_NICKNAME) {
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});
    } else if (key == UserConstant.KEY_PHONE) {
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(13)});
    } else if (key == UserConstant.KEY_EMAIL || key == UserConstant.KEY_SIGNATURE) {
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(30)});
    } else if (key == UserConstant.KEY_ALIAS) {
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(16)});
    }
    if (key == UserConstant.KEY_ALIAS) {
        Friend friend = FriendDataCache.getInstance().getFriendByAccount(data);
        if (friend != null && !TextUtils.isEmpty(friend.getAlias())) {
            editText.setText(friend.getAlias());
        } else {
            editText.setHint("请输入备注名...");
        }
    } else {
        editText.setText(data);
    }
    editText.setDeleteImage(R.drawable.nim_grey_delete_icon);
}
项目:A.scribe    文件:NoteFragment.java   
private void initializeViews(Note note) {
    String title = note.getTitle();
    String text = note.getText();
    titleEditText.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
    titleEditText.setRawInputType(InputType.TYPE_CLASS_TEXT);
    if (title == null && text == null) {
        getActivity().getWindow()
                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
                        | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        Util.showKeyboardFrom(getContext(), textEditText);
    } else {
        titleEditText.setText(title);
        textEditText.setText(text);
    }
    setColor(note.getColor());
    updateDateEditedTextView();
}
项目:RNLearn_Project1    文件:ReactTextInputManager.java   
@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);
}
项目:financisto1-holo    文件:NumberPicker.java   
public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    setOrientation(VERTICAL);
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.number_picker, this, true);
    mHandler = new Handler();
    InputFilter inputFilter = new NumberPickerInputFilter();
    mNumberInputFilter = new NumberRangeKeyListener();
    mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
    mIncrementButton.setOnClickListener(this);
    mIncrementButton.setOnLongClickListener(this);
    mIncrementButton.setNumberPicker(this);
    mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
    mDecrementButton.setOnClickListener(this);
    mDecrementButton.setOnLongClickListener(this);
    mDecrementButton.setNumberPicker(this);

    mText = (EditText) findViewById(R.id.timepicker_input);
    mText.setOnFocusChangeListener(this);
    mText.setFilters(new InputFilter[] {inputFilter});
    mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);

    if (!isEnabled()) {
        setEnabled(false);
    }
}
项目:RLibrary    文件:ExEditText.java   
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);
    }
}
项目:RLibrary    文件:RTextView.java   
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);
}
项目:WiFiKeyShare    文件:WifiNetworkActivity.java   
private static void setPasswordRestrictions(EditText editText) {
    // Source: http://stackoverflow.com/a/4401227
    InputFilter filter = new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end,
                                   Spanned dest, int dstart, int dend) {
            // TODO: check that the filter follows WEP/WPA recommendations
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))) {
                    return "";
                }
            }
            return null;
        }
    };
    editText.setFilters(new InputFilter[]{filter});
}
项目:Doctor    文件:ColorPickerDialog.java   
@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;
}
项目:TenguChat    文件:EditMessage.java   
@Override
public boolean onTextContextMenuItem(int id) {
    if (id == android.R.id.paste) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return super.onTextContextMenuItem(android.R.id.pasteAsPlainText);
        } else {
            Editable editable = getEditableText();
            InputFilter[] filters = editable.getFilters();
            InputFilter[] tempFilters = new InputFilter[filters != null ? filters.length + 1 : 1];
            if (filters != null) {
                System.arraycopy(filters, 0, tempFilters, 1, filters.length);
            }
            tempFilters[0] = SPAN_FILTER;
            editable.setFilters(tempFilters);
            try {
                return super.onTextContextMenuItem(id);
            } finally {
                editable.setFilters(filters);
            }
        }
    } else {
        return super.onTextContextMenuItem(id);
    }
}
项目:smartcoins-wallet    文件:AccountActivity.java   
private void validationAccountName() {
    InputFilter filter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

            for (int i = start; i < end; i++) {
                if ((dstart == 0) && (!Character.isLetter(source.charAt(0)))) {
                    return "";
                } else if (!Character.isLetterOrDigit(source.charAt(i)) && (source.charAt(i) != '-')) {
                    return "";
                }
            }

            return null;
        }
    };
    etAccountName.setFilters(new InputFilter[]{filter});

}
项目:UNCmorfi    文件:BalanceFragment.java   
private void initNewUserView() {
    mEditText = mRootView.findViewById(R.id.new_user_input);
    ImageButton scanner = mRootView.findViewById(R.id.new_user_scanner);

    mEditText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
    mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                hideKeyboard();
                mBackend.newUser(textView.getText().toString().replace(" ", ","));
            }
            return false;
        }
    });
    scanner.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callScanner();
        }
    });
}
项目:AutoFormatEditText    文件:AutoFormatEditText.java   
private void setInputFilter(AttributeSet attrs) {
    int maxLength = MAX_LENGTH;
    if (attrs != null) {
        int[] maxLengthAttrs = {android.R.attr.maxLength};
        TypedArray typedArrays = getContext()
            .obtainStyledAttributes(attrs, maxLengthAttrs);
        try {
            maxLength = typedArrays.getInteger(0, MAX_LENGTH);
        } finally {
            typedArrays.recycle();
        }
    }

    // limit maximum length for input number
    InputFilter[] inputFilterArray = new InputFilter[1];
    inputFilterArray[0] = new InputFilter.LengthFilter(maxLength);
    setFilters(inputFilterArray);
}
项目:AndroidSamples    文件:PayPwdInputView.java   
/**
 * 构造方法
 *
 * @param context
 * @param attrs
 */
public PayPwdInputView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;

    // 获取attr
    getAtt(attrs);
    // 初始化画笔
    initPaint();

    // 设置EditText背景为透明
    this.setBackgroundColor(Color.TRANSPARENT);
    // 设置不显示光标
    this.setCursorVisible(false);
    // 设置EditText的最大长度
    this.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxCount)});

}
项目:RxTools    文件:RxTool.java   
public static void setEdDecimal(EditText editText, int count) {
    if (count < 1) {
        count = 1;
    }

    editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);

    //设置字符过滤
    final int finalCount = count;
    editText.setFilters(new InputFilter[]{new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (source.equals(".") && dest.toString().length() == 0) {
                return "0.";
            }
            if (dest.toString().contains(".")) {
                int index = dest.toString().indexOf(".");
                int mlength = dest.toString().substring(index).length();
                if (mlength == finalCount) {
                    return "";
                }
            }
            return null;
        }
    }});
}
项目:Eulen    文件:EulenOTP.java   
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;
}
项目:MaterialEditText    文件:MaterialEditText.java   
/**
 * @return max length of editText
 */
private int getEditTextMaxLength() {
    int length = 0;
    try {
        InputFilter[] filters = mEditText.getFilters();
        for (InputFilter filter : filters) {
            Class<?> clazz = filter.getClass();
            if (clazz.getName().equals("android.text.InputFilter$LengthFilter")) {
                Field[] fields = clazz.getDeclaredFields();
                for (Field field : fields) {
                    if (field.getName().equals("mMax")) {
                        field.setAccessible(true);
                        length = (int) field.get(filter);
                    }
                }
            }
        }
    } catch (Exception ignoreException) {
    }
    return length;
}
项目:msb-android    文件:EditInfo.java   
@Override
public void process() {
    mIntent = getIntent();

    mEditName = mIntent.getStringExtra(EXTRA_NAME);
    mAllowEmpty = mIntent.getBooleanExtra(EXTRA_ALLOW_EMPTY, true);

    int maxLength = mIntent.getIntExtra(EXTRA_MAX_LENGTH, 0);
    if (maxLength > 0) {
        mEditText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});
    }

    mEditText.setText(mIntent.getStringExtra(EXTRA_VALUE));
    mEditText.setSelectAllOnFocus(true);
    mHintText.setText(mIntent.getStringExtra(EXTRA_HINT));

    setTitleBarStyle();
}
项目:bluesnap-android-int    文件:BluesnapFragment.java   
private void changeZipTextAndStateLengthAccordingToCountry() {
    // check if usa if so change zip text to postal code otherwise billing zip
    if (Arrays.asList(Constants.COUNTRIES_WITHOUT_ZIP).contains(getCountryText())) {
        zipFieldLayout.setVisibility(View.INVISIBLE);
        zipEditText.setText("");
    } else {
        zipFieldLayout.setVisibility(View.VISIBLE);
        zipTextView.setText(
                AndroidUtil.STATE_NEEDED_COUNTRIES[0].equals(getCountryText())
                        ? R.string.postal_code_hint
                        : R.string.billing_zip
        );
    }

    int maxLength = 50;
    if (AndroidUtil.checkCountryForState(getCountryText()))
        maxLength = 2;
    billingStateEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)});
    billingAddressLabelTextView.setTextColor(Color.BLACK);

}
项目:bluesnap-android-int    文件:ShippingFragment.java   
private void changeZipTextAndStateLengthAccordingToCountry() {
    // check if usa if so change zip text to postal code otherwise billing zip
    if (Arrays.asList(Constants.COUNTRIES_WITHOUT_ZIP).contains(getCountryText())) {
        shippingZipLinearLayout.setVisibility(View.INVISIBLE);
        shippingZipEditText.setText("");
    } else {
        shippingZipLinearLayout.setVisibility(View.VISIBLE);
        shippingZipLabelTextView.setText(
                AndroidUtil.STATE_NEEDED_COUNTRIES[0].equals(getCountryText())
                        ? R.string.postal_code_hint
                        : R.string.zip
        );
    }

    int maxLength = 50;
    if (AndroidUtil.checkCountryForState(getCountryText()))
        maxLength = 2;
    shippingStateEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)});
}
项目:mask-edittext    文件:MaskEditText.java   
private void applyMask(Editable text) {
    if (TextUtils.isEmpty(text) || !hasMask()) {
        return;
    }

    //remove input filters to ignore input type
    InputFilter[] filters = text.getFilters();
    text.setFilters(new InputFilter[0]);

    int maskLen = mask.length();
    int textLen = text.length();

    int i = 0;
    int notSymbolIndex = 0;
    StringBuilder sb = new StringBuilder();
    while (i < maskLen && notSymbolIndex < textLen) {
        if (mask.charAt(i) == text.charAt(notSymbolIndex) || mask.charAt(i) == REPLACE_CHAR) {
            sb.append(text.charAt(notSymbolIndex));
            notSymbolIndex++;
        } else {
            sb.append(mask.charAt(i));
        }
        i++;
    }

    text.clear();
    text.append(sb.toString());

    //reset filters
    text.setFilters(filters);
}
项目:EasyEmoji    文件:EmojiUtil.java   
@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;
}
项目:Pinview    文件:Pinview.java   
/**
 * 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);
}
项目:android_ui    文件:EditLayout.java   
/**
 * Setups the current EditText with configuration options provided by {@link #mEditConfig} if
 * available.
 */
private void updateEditTextConfiguration() {
    if (mEditConfig == null || mEditText == null) {
        return;
    }
    if (mEditConfig.text != null) {
        mEditText.setText(mEditConfig.text);
        super.setLabel(mEditConfig.hint);
    }
    if (mEditConfig.hint != null) {
        mEditText.setHint(mEditConfig.hint);
    }
    if (mEditConfig.inputType != 0) {
        // We try to preserve here the type face that is set to the edit text because calling
        // EditText.setInputType(int) method resets it back to MONOSPACE.
        final Typeface typeface = mEditText.getTypeface();
        mEditText.setInputType(mEditConfig.inputType);
        mEditText.setTypeface(typeface);
    }
    if (mEditConfig.maxLength != 0) {
        mEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mEditConfig.maxLength)});
    }
    if (mEditConfig.lines != 0) {
        mEditText.setLines(mEditConfig.lines);
    }
    if (mEditConfig.minLines != 0) {
        mEditText.setMinLines(mEditConfig.minLines);
    }
    if (mEditConfig.maxLines != 0) {
        mEditText.setMaxLines(mEditConfig.maxLines);
    }
}
项目:android_ui    文件:EditLayout.java   
/**
 * Sets the maximum length (in characters) to be used as constraint filter for the current EditText.
 * Setting this property will constraint a user in typing more characters into EditText than the
 * specified value.
 * <p>
 * <b>Note</b>, that if <b>none zero</b>, this value will also change the current value of length
 * constraint requested by {@link #setLengthConstraint(int)} used to indicate current state of
 * the editable text's length vs. the constraint one.
 *
 * @param maxLength The desired maximum length. Passing {@code 0} will clear the current filter.
 * @see android.R.attr#maxLength android:maxLength
 * @see #getMaxLength()
 */
public void setMaxLength(int maxLength) {
    if (mEditConfig.maxLength != maxLength) {
        mEditConfig.maxLength = Math.max(0, maxLength);
        if (mEditConfig.maxLength > 0) {
            mEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mEditConfig.maxLength)});
        } else {
            mEditText.setFilters(new InputFilter[0]);
        }
        if (!(mEditText instanceof EditTextWidget) || !UiConfig.MATERIALIZED) {
            this.handleLengthConstraintUpdate(mEditConfig.maxLength = maxLength);
        }
    }
}
项目:bridgefy-android-samples    文件:TimelineActivity.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timeline);
        ButterKnife.bind(this);

        // recover our username and set the maximum tweet size
        username = getIntent().getStringExtra(INTENT_USERNAME);
        txtMessage.setFilters(new InputFilter[] { new InputFilter.LengthFilter(138 - username.length()) });

        // Configure the Toolbar
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        gatewaySwitch.setChecked(true);

        // configure the recyclerview
        RecyclerView tweetsRecyclerView = findViewById(R.id.tweet_list);
        LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
        mLinearLayoutManager.setReverseLayout(true);
        tweetsRecyclerView.setLayoutManager(mLinearLayoutManager);
        tweetsRecyclerView.setAdapter(tweetsAdapter);

        // Set the Bridgefy MessageListener
        Log.d(TAG, "Setting new State and Message Listeners");
        Bridgefy.setMessageListener(tweetManager = new TweetManager(username, this));

        // register the connected receiver
//        LocalBroadcastManager.getInstance(this).registerReceiver(wifiReceiver, wifiReceiver.getIntentFilter());
        getApplicationContext().registerReceiver(wifiReceiver,
                new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
项目:stynico    文件:ChatActivity.java   
public  InputFilter getInputFilterProhibitEmoji()
 {
     InputFilter filter = new InputFilter() {
         @Override
         public CharSequence filter(CharSequence source, int start, int end,
                                    Spanned dest, int dstart, int dend)
{
             StringBuffer buffer = new StringBuffer();
             for (int i = start; i < end; i++)
    {
                 char codePoint = source.charAt(i);
                 if (!getIsEmoji(codePoint))
        {
                     buffer.append(codePoint);
                 }
        else
        {
            //  ToastUtil.show("群组昵称不能含有第三方表情");
                     i++;
                     continue;
                 }
             }
             if (source instanceof Spanned)
    {
                 SpannableString sp = new SpannableString(buffer);
                 TextUtils.copySpansFrom((Spanned) source, start, end, null,
                                sp, 0);
                 return sp;
             }
    else
    {
                 return buffer;
             }
         }
     };
     return filter;
 }
项目:adyen-android    文件:CreditCardEditText.java   
private void init() {
    ArrayList<InputFilter> cardNoFilters = new ArrayList<>();
    cardNoFilters.add(new InputFilter.LengthFilter(CC_MAX_LENGTH));
    cardNoFilters.add(new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            for (char c : source.toString().toCharArray()) {
                if (!Character.isDigit(c) && !Character.isWhitespace(c)) {
                     return "";
                }
            }
            return source;
        }
    });
    this.setFilters(cardNoFilters.toArray(new InputFilter[cardNoFilters.size()]));
    this.addTextChangedListener(new CreditCardInputFormatWatcher());

    setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                CreditCardEditText.this.setTextColor(ContextCompat.getColor(getContext(), R.color.black_text));
            } else {
                if (!isValidNr(CreditCardEditText.this.getCCNumber())) {
                    CreditCardEditText.this.setTextColor(ContextCompat.getColor(getContext(),
                            R.color.red_invalid_input_highlight));
                }
            }
        }
    });
}
项目:adyen-android    文件:CVCEditText.java   
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));
    }
}
项目:CipherSharedPrefs    文件:MainActivity.java   
@Override
public void onInitialized(MainPresenter presenter, MainViewState viewState) {
    if (!presenter.isInitialized()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.enter_key);
        builder.setMessage(R.string.key_requirments_message);

        EditText editText = new EditText(this);
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(16)});
        builder.setView(editText);

        builder.setPositiveButton(R.string.apply, null);

        AlertDialog dialog = builder.create();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
            if (editText.getText().length() == 16) {
                String key = editText.getText().toString();
                presenter.initializeWithKey(key);
                presenter.getValues();
                dialog.dismiss();
            } else {
                Toast.makeText(this, R.string.bad_key, Toast.LENGTH_LONG).show();
            }
        });

        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) editText.getLayoutParams();
        int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16f, getResources().getDisplayMetrics());
        layoutParams.setMargins(margin, margin, margin, margin);
        editText.requestLayout();
    } else {
        if (!viewState.isPrefsLoaded() && !presenter.isTaskRunning(MainPresenter.TASK_GET_RUNNING)) {
            presenter.getValues();
        }
    }
}