當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。