当前位置: 首页>>代码示例>>Java>>正文


Java InputFilter类代码示例

本文整理汇总了Java中android.text.InputFilter的典型用法代码示例。如果您正苦于以下问题:Java InputFilter类的具体用法?Java InputFilter怎么用?Java InputFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InputFilter类属于android.text包,在下文中一共展示了InputFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: keepEditTwoPoint

import android.text.InputFilter; //导入依赖的package包/类
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;
        }
    }});
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:20,代码来源:NormalUtil.java

示例2: setEditable

import android.text.InputFilter; //导入依赖的package包/类
/**
 * 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();
    }
}
 
开发者ID:Jusenr,项目名称:androidtools,代码行数:26,代码来源:StringUtils.java

示例3: init

import android.text.InputFilter; //导入依赖的package包/类
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));
                }
            }
        }
    });
}
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:21,代码来源:ExpiryDateEditText.java

示例4: 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;
}
 
开发者ID:aksalj,项目名称:africastalking-android,代码行数:18,代码来源:CardNumberTextWatcher.java

示例5: onCreate

import android.text.InputFilter; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:24,代码来源:CommonEditDialog.java

示例6: 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());
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:22,代码来源:PasscodeActivity.java

示例7: setMaxLength

import android.text.InputFilter; //导入依赖的package包/类
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]));
}
 
开发者ID:Break369,项目名称:MyLife,代码行数:17,代码来源:TextViewUtils.java

示例8: getItemView

import android.text.InputFilter; //导入依赖的package包/类
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;
}
 
开发者ID:hnsugar,项目名称:ViewCacheManager,代码行数:24,代码来源:MainActivity.java

示例9: setupLoginPanel

import android.text.InputFilter; //导入依赖的package包/类
/**
 * 登录面板
 */
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);
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:20,代码来源:LoginActivity.java

示例10: findEditText

import android.text.InputFilter; //导入依赖的package包/类
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);
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:24,代码来源:UserProfileEditItemActivity.java

示例11: initializeViews

import android.text.InputFilter; //导入依赖的package包/类
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();
}
 
开发者ID:Laaidback,项目名称:A.scribe,代码行数:18,代码来源:NoteFragment.java

示例12: 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);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:41,代码来源:ReactTextInputManager.java

示例13: NumberPicker

import android.text.InputFilter; //导入依赖的package包/类
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);
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:27,代码来源:NumberPicker.java

示例14: 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);
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:ExEditText.java

示例15: 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);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:22,代码来源:RTextView.java


注:本文中的android.text.InputFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。