Java Code Examples for android.text.InputFilter

The following examples show how to use android.text.InputFilter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: AndroidBasicProject   Source File: EditTextUtil.java    License: MIT License 6 votes vote down vote up
/**
 * 限制内容长度
 */
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);
}
 
Example 2
Source Project: financisto   Source File: NumberPicker.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source Project: reel-search-android   Source File: SuggestionsActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_suggestions);
    mDictionaryManager = new DictionaryManager(this);
    mAdapter = new SuggestionsAdapter(this);
    mBinding.lstSuggestions.setAdapter(mAdapter);
    mBinding.btnSelect.setOnClickListener(v -> {
        final int selectedPosition = mBinding.reelSearch.getLayoutManager().getSelection();

        Snackbar.make(mBinding.btnSelect,
                "Selected position " + selectedPosition + " item " + mAdapter.getItem(selectedPosition),
                Snackbar.LENGTH_SHORT).show();
    });
    mBinding.txtQuery.setFilters(new InputFilter[]{
            (source, start, end, dest, dstart, dend) -> source.toString().toLowerCase().trim()
    });
    mBinding.reelSearch.setOnSelectionChangedListener((prevSelection, newSelection) -> {
        Log.e("Selection", "Changed to " + newSelection + " from " + prevSelection);
    });
}
 
Example 4
Source Project: AndroidWallet   Source File: NumberUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置输入小数位限制
 *
 * @param editText
 * @param length
 */
public static void setInputDotLength(EditText editText, final int length) {
    editText.setFilters(new InputFilter[]{new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end,
                                   Spanned dest, int dstart, int dend) {
            Log.i("", "source=" + source + ",start=" + start + ",end=" + end
                    + ",dest=" + dest.toString() + ",dstart=" + dstart
                    + ",dend=" + dend);
            if (dest.length() == 0 && source.equals(".")) {
                return "0.";
            }
            String dValue = dest.toString();
            String[] splitArray = dValue.split("\\.");
            if (splitArray.length > 1) {
                String dotValue = splitArray[1];
                if (dotValue.length() == length) {
                    return "";
                }
            }
            return null;
        }
    }
    });
}
 
Example 5
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});
}
 
Example 6
Source Project: memoir   Source File: ColorPickerDialog.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 7
public void setFieldText(CharSequence text) {
    if (messageEditText == null) {
        return;
    }
    messageEditText.setText(text);
    messageEditText.setSelection(messageEditText.getText().length());
    if (delegate != null) {
        delegate.onTextChanged(messageEditText.getText());
    }
    int old = captionMaxLength;
    captionMaxLength = MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength;
    if (old != captionMaxLength) {
        InputFilter[] inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(captionMaxLength);
        messageEditText.setFilters(inputFilters);
    }
}
 
Example 8
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    checkBtnIncludeStatus(isInclude);
    setDataToView();
    initSendSumField();
    initFeeField();
    updateArrivalField();
    updateWarnings();
    updateArrivalField();
}
 
Example 9
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    tokenCode = getIntent().getStringExtra(Extras.TOKEN_CODE_EXTRA);
    tvTokenHint.setText(tokenCode);
    getTokenBalanceBalance();
    getEthereumBalance();
    setDataToView();
    initSendSumField();
    getGasPrice();
    initFeeField();
}
 
Example 10
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    checkBtnIncludeStatus(isInclude);
    setDataToView();
    initSendSumField();
    initFeeField();
    updateArrivalField();
    updateWarnings();
    updateArrivalField();
}
 
Example 11
@Override
    protected void init(Bundle savedInstanceState) {
        GuardaApp.getAppComponent().inject(this);
        setToolBarTitle(getString(R.string.title_withdraw3));
        etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
        etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
        walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
        amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
        checkBtnIncludeStatus(isInclude);
        setDataToView();
        initSendSumField();
        initFeeField();
        btnInclude.setVisibility(View.GONE);
        btnExclude.setVisibility(View.GONE);
        etFeeAmount.setEnabled(false);
        feeContainer.setVisibility(View.GONE);
//        updateArrivalField();
//        updateWarnings();
//        updateArrivalField();
    }
 
Example 12
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    tokenCode = getIntent().getStringExtra(Extras.TOKEN_CODE_EXTRA);
    tvTokenHint.setText(tokenCode);
    getTokenBalanceBalance();
    getEthereumBalance();
    setDataToView();
    initSendSumField();
    getGasPrice();
    initFeeField();
}
 
Example 13
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    checkBtnIncludeStatus(isInclude);
    setDataToView();
    initSendSumField();
    initFeeField();
    updateArrivalField();
    updateWarnings();
    updateArrivalField();
}
 
Example 14
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    checkBtnIncludeStatus(isInclude);
    setDataToView();
    initSendSumField();
    initFeeField();
    updateArrivalField();
    updateWarnings();
    updateArrivalField();
}
 
Example 15
Source Project: Luhn   Source File: CardNumberTextWatcher.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example 16
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    tokenCode = getIntent().getStringExtra(Extras.TOKEN_CODE_EXTRA);
    tvTokenHint.setText(tokenCode);
    getTokenBalanceBalance();
    getEthereumBalance();
    setDataToView();
    initSendSumField();
    getGasPrice();
    initFeeField();
}
 
Example 17
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    switchContainer.requestFocus();
    getBalance();
    checkBtnIncludeStatus(isInclude);
    setDataToView();
    initSendSumField();
    getGasPrice();
    initCustomFields();
    initFeeField();
}
 
Example 18
@Override
protected void init(Bundle savedInstanceState) {
    GuardaApp.getAppComponent().inject(this);
    setToolBarTitle(getString(R.string.title_withdraw3));
    etSumSend.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    etFeeAmount.setFilters(new InputFilter[]{new DigitsInputFilter(8, 8, Float.POSITIVE_INFINITY)});
    walletNumber = getIntent().getStringExtra(Extras.WALLET_NUMBER);
    amountToSend = getIntent().getStringExtra(Extras.AMOUNT_TO_SEND);
    checkBtnIncludeStatus(isInclude);
    setDataToView();
    initSendSumField();
    initFeeField();
    updateArrivalField();
    updateWarnings();
    updateArrivalField();
}
 
Example 19
Source Project: hash-checker   Source File: HashCalculatorFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void validateTextCase() {
    boolean useUpperCase = SettingsHelper.useUpperCase(context);
    InputFilter[] fieldFilters = useUpperCase
            ? new InputFilter[]{new InputFilter.AllCaps()}
            : new InputFilter[]{};
    etCustomHash.setFilters(fieldFilters);
    etGeneratedHash.setFilters(fieldFilters);

    if (useUpperCase) {
        TextTools.convertToUpperCase(etCustomHash);
        TextTools.convertToUpperCase(etGeneratedHash);
    } else {
        TextTools.convertToLowerCase(etCustomHash);
        TextTools.convertToLowerCase(etGeneratedHash);
    }

    etCustomHash.setSelection(
            etCustomHash.getText().length()
    );
    etGeneratedHash.setSelection(
            etGeneratedHash.getText().length()
    );
}
 
Example 20
Source Project: AndroidProject   Source File: RegexEditText.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 添加筛选规则
 */
public void addFilters(InputFilter filter) {
    if (filter == null) {
        return;
    }

    final InputFilter[] newFilters;
    final InputFilter[] oldFilters = getFilters();
    if (oldFilters != null && oldFilters.length > 0) {
        newFilters = new InputFilter[oldFilters.length + 1];
        // 复制旧数组的元素到新数组中
        System.arraycopy(oldFilters, 0, newFilters, 0, oldFilters.length);
        newFilters[oldFilters.length] = filter;
    } else {
        newFilters = new InputFilter[1];
        newFilters[0] = filter;
    }
    super.setFilters(newFilters);
}
 
Example 21
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_url_enter);

    final EditText qrResult=(EditText) findViewById(R.id.gnResult);
    Button generate=(Button) findViewById(R.id.generate);

    int maxLength = 150;
    qrResult.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});

    generate.setOnClickListener(new View.OnClickListener() {
        String result;
        @Override
        public void onClick(View v) {
            result = qrResult.getText().toString();
            Intent i = new Intent(UrlEnterActivity.this, QrGeneratorDisplayActivity.class);
            i.putExtra("gn", result);
            i.putExtra("type", Contents.Type.WEB_URL);
            startActivity(i);
        }
    });


}
 
Example 22
Source Project: TLint   Source File: MaterialNumberPicker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Init number picker by disabling focusability of edit text embedded inside the number picker
 * We also override the edit text filter private attribute by using reflection as the formatter
 * is
 * still buggy while attempting to display the default value
 * This is still an open Google @see <a href="https://code.google.com/p/android/issues/detail?id=35482#c9">issue</a>
 * from 2012
 */
private void initView() {
    setMinValue(MIN_VALUE);
    setMaxValue(MAX_VALUE);
    setValue(DEFAULT_VALUE);
    setBackgroundColor(BACKGROUND_COLOR);
    setSeparatorColor(SEPARATOR_COLOR);
    setTextColor(TEXT_COLOR);
    setTextSize(TEXT_SIZE);
    setWrapSelectorWheel(false);
    setFocusability(false);

    try {
        Field f = NumberPicker.class.getDeclaredField("mInputText");
        f.setAccessible(true);
        EditText inputText = (EditText) f.get(this);
        inputText.setFilters(new InputFilter[0]);
    } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
}
 
Example 23
Source Project: twittererer   Source File: TimelineActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void showNewTweetDialog() {
    final EditText tweetText = new EditText(this);
    tweetText.setId(R.id.tweet_text);
    tweetText.setSingleLine();
    tweetText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    tweetText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(140)});
    tweetText.setImeOptions(EditorInfo.IME_ACTION_DONE);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.label_what_is_happening);
    builder.setPositiveButton(R.string.action_tweet, (dialog, which) -> presenter.tweet(tweetText.getText().toString()));

    AlertDialog alert = builder.create();
    alert.setView(tweetText, 64, 0, 64, 0);
    alert.show();

    tweetText.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            alert.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick();
            return true;
        }
        return false;
    });
}
 
Example 24
public TextInputProxyEditTextbox(Context context, int allowedLength, boolean limitInput) {
    super(context);
    this.allowedLength = allowedLength;
    this.limitInput = limitInput;

    if (limitInput) {
        InputFilter[] fillters = new InputFilter[2];
        fillters[0] = new InputFilter.LengthFilter(this.allowedLength);
        fillters[1] = new InputFilter() {

            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                if (source.equals("") || source.toString().matches("^[a-zA-Z0-9_ -^~\'.,;!#&()=`{}]*"))
                    return source;
                return "";
            }
        };
        setFilters(fillters);
    } else
        setFilters(new InputFilter[]{new InputFilter.LengthFilter(this.allowedLength)});
}
 
Example 25
Source Project: FormatEditText   Source File: FormattedEditText.java    License: MIT License 6 votes vote down vote up
@Override
@CallSuper
public void setFilters(InputFilter[] filters) {
    if (filters == null) {
        throw new IllegalArgumentException("filters can not be null");
    }
    boolean havingFilter = false;
    for (int i = 0; i < filters.length; i++) {
        if (filters[i] instanceof InputFilter.LengthFilter) {
            mLengthFilterDelegate = new LengthFilterDelegate(filters[i]);
            filters[i] = mLengthFilterDelegate;
        } else if (filters[i] instanceof PlaceholderFilter) {
            havingFilter = true;
        }
    }
    if (!havingFilter) {
        InputFilter[] replaceFilters = new InputFilter[filters.length + 1];
        replaceFilters[0] = new PlaceholderFilter();
        System.arraycopy(filters, 0, replaceFilters, 1, filters.length);
        super.setFilters(replaceFilters);
        return;
    }
    super.setFilters(filters);
}
 
Example 26
Source Project: bcm-android   Source File: EmojiEditText.java    License: GNU General Public License v3.0 5 votes vote down vote up
private InputFilter[] appendEmojiFilter(@Nullable InputFilter[] originalFilters) {
    InputFilter[] result;

    if (originalFilters != null) {
        result = new InputFilter[originalFilters.length + 1];
        System.arraycopy(originalFilters, 0, result, 1, originalFilters.length);
    } else {
        result = new InputFilter[1];
    }

    result[0] = new EmojiFilter(this);

    return result;
}
 
Example 27
Source Project: star-dns-changer   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
private void initViews() {
    toolbar.setTitle("");
    setSupportActionBar(toolbar);
    logo.bringToFront();
    logo.requestLayout();
    logo.invalidate();

    InputFilter[] filters = new InputFilter[1];
    filters[0] = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start,
                                   int end, Spanned dest, int dstart, int dend) {
            if (end > start) {
                String destTxt = dest.toString();
                String resultingTxt = destTxt.substring(0, dstart) +
                        source.subSequence(start, end) +
                        destTxt.substring(dend);
                if (!resultingTxt.matches("^\\d{1,3}(\\." +
                        "(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) {
                    return "";
                } else {
                    String[] splits = resultingTxt.split("\\.");
                    for (int i = 0; i < splits.length; i++) {
                        if (Integer.valueOf(splits[i]) > 255) {
                            return "";
                        }
                    }
                }
            }
            return null;
        }
    };
    firstDnsEdit.setFilters(filters);
    secondDnsEdit.setFilters(filters);
    ViewCompat.setTranslationZ(logo, 8);
}
 
Example 28
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mms_enter);


    final EditText qrMms=(EditText) findViewById(R.id.editTel);
    final EditText qrText=(EditText) findViewById(R.id.editText1);
    Button generate=(Button) findViewById(R.id.generate);

    int maxLength = 15;
    qrMms.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});

    int maxLength2 = 300;
    qrText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength2)});


    generate.setOnClickListener(new View.OnClickListener() {
        String result;
        @Override
        public void onClick(View v) {

            result = qrMms.getText().toString()+":"+qrText.getText().toString();
            Intent i = new Intent(MmsEnterActivity.this, QrGeneratorDisplayActivity.class);
            i.putExtra("gn", result);
            i.putExtra("type", Contents.Type.MMS);
            startActivity(i);
        }
    });
}
 
Example 29
Source Project: DevUtils   Source File: EditTextUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置长度限制
 * @param editText  {@link EditText}
 * @param maxLength 长度限制
 * @param <T>       泛型
 * @return {@link EditText}
 */
public static <T extends EditText> T setMaxLength(final T editText, final int maxLength) {
    if (editText != null && maxLength > 0) {
        // 设置最大长度限制
        InputFilter[] filters = {new InputFilter.LengthFilter(maxLength)};
        editText.setFilters(filters);
    }
    return editText;
}
 
Example 30
Source Project: px-android   Source File: PayerInformationActivity.java    License: MIT License 5 votes vote down vote up
private void setIdentificationLastNameEditTextListeners() {
    mIdentificationLastNameEditText.setFilters(new InputFilter[] { new InputFilter.AllCaps() });

    mIdentificationLastNameEditText.setOnEditorActionListener((v, actionId, event) -> onNextKey(actionId, event));

    mIdentificationLastNameEditText.setOnTouchListener((v, event) -> {
        onTouchEditText(mIdentificationLastNameEditText, event);
        return true;
    });

    mIdentificationLastNameEditText.addTextChangedListener(
        new TicketIdentificationNameTextWatcher(new TicketIdentificationNameEditTextCallback() {
            @Override
            public void checkOpenKeyboard() {
                openKeyboard(mIdentificationLastNameEditText);
            }

            @Override
            public void saveIdentificationName(final CharSequence string) {
                presenter.saveIdentificationLastName(string.toString());

                mIdentificationTicketView.setIdentificationLastName(string.toString());
                mIdentificationTicketView.draw();
            }

            @Override
            public void changeErrorView() {
                checkChangeErrorView();
            }

            @Override
            public void toggleLineColorOnError(final boolean toggle) {
                mIdentificationLastNameEditText.toggleLineColorOnError(toggle);
            }
        }));
}