Java 类android.text.TextWatcher 实例源码

项目:letv    文件:BasicActivity.java   
protected void beautyEditText(final EditText mEditText, String hintStr, TextWatcher mTextWatcher) {
    mEditText.setHint(hintStr);
    mEditText.setHintTextColor(Color.parseColor("#1e0d0d0d"));
    mEditText.setTextColor(Color.parseColor("#0d0d0d"));
    SDKUtils.setBackground(mEditText, this.crMgmt.getDrawable("uac_input", true));
    mEditText.setTextSize(16.0f);
    if (mTextWatcher != null) {
        mEditText.addTextChangedListener(mTextWatcher);
    }
    mEditText.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mEditText.setSelection(mEditText.length());
            mEditText.requestFocus();
            mEditText.setFocusable(true);
        }
    });
}
项目:WeiboPhotoLinktoPeople    文件:MainActivity.java   
private void initListener() {
    findViewById(R.id.constraint_layout).setOnClickListener(this);
    fab.setOnClickListener(this);

    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            needClearInput = false;
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            textInputLayout.setErrorEnabled(false);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            editTextString = editText.getText().toString();
            if (editTextString.equals(""))
                setFabImage(false);
        }
    });
}
项目:ClickDrawableTextView    文件:ClickDrawableEditText.java   
@Override
public void removeTextChangedListener(TextWatcher watcher) {
    super.removeTextChangedListener(watcher);
    if (mCsDrawableViewManager != null){
        mCsDrawableViewManager.removeTextWatcher();
    }
}
项目:BlueTape    文件:TextChangedBindingFunctionTest.java   
@Test
public void doNotAddTextWatcher_IfAlreadyAdded() throws Exception {
    // Given
    given(view.getTag(anyInt()))
            .willReturn(mock(TextWatcher.class));

    BindingFunction function = TextChangedBindingFunction.create(listener);

    // When
    function.bind(view);

    // Then
    verify(view, never()).addTextChangedListener(any());
}
项目:BlueTape    文件:TextChangedBindingFunctionTest.java   
@Test
public void removeTextWatcher() throws Exception {
    // Given
    TextWatcher watcher = mock(TextWatcher.class);

    given(view.getTag(anyInt()))
            .willReturn(watcher);

    BindingFunction function = TextChangedBindingFunction.create(null);

    // When
    function.bind(view);

    // Then
    verify(view).removeTextChangedListener(watcher);
    verify(view).setTag(R.id.onTextChangedListener, null);
}
项目:SmsScheduler    文件:AddSmsActivity.java   
private void buildForm() {
    EditText formMessage = findViewById(R.id.form_input_message);
    AutoCompleteTextView formContact = findViewById(R.id.form_input_contact);
    TextWatcher watcherEmptiness = new EmptinessTextWatcher(this, formContact, formMessage);
    formContact.addTextChangedListener(watcherEmptiness);
    formMessage.addTextChangedListener(watcherEmptiness);

    new BuilderMessage().setView(formMessage).setSms(sms).build();
    new BuilderContact().setView(formContact).setSms(sms).setActivity(this).build();

    new BuilderSimCard().setActivity(this).setView(findViewById(R.id.form_sim_card)).setSms(sms).build();
    new BuilderRecurringMode()
        .setRecurringDayView((Spinner) findViewById(R.id.form_recurring_day))
        .setRecurringMonthView((Spinner) findViewById(R.id.form_recurring_month))
        .setDateView((DatePicker) findViewById(R.id.form_date))
        .setActivity(this)
        .setView(findViewById(R.id.form_recurring_mode))
        .setSms(sms)
        .build()
    ;

    new BuilderTime().setActivity(this).setView(findViewById(R.id.form_time)).setSms(sms).build();
    new BuilderDate().setActivity(this).setView(findViewById(R.id.form_date)).setSms(sms).build();

    new BuilderCancel().setView(findViewById(R.id.button_cancel)).setSms(sms).build();
}
项目:fonotes    文件:FLUIAndroidUtil.java   
private static TextWatcher createSelectStringDialogFilterTextWatcher(final Activity activity
        , final List<Pair<Bitmap, String>> values
        , final double maxImageWidthInCM
        , final double maxImageHeightInCM
        , EditText filterText
        , final boolean matchCase
        , final boolean containsMode
        , final boolean multiSelect
        , final ListView list
        , final SortedSet<String> allSelectedItems
        , final ReturnableObject<FLUIAndroidIconLabelAndCheckListAdapter>
                                                                             currentCheckListAdapter) {
    return createSelectStringDialogFilterTextWatcher(activity
            , values
            , maxImageWidthInCM
            , maxImageHeightInCM
            , DEFAULT_TEXT_SIZE_IN_DIP
            , SizeUnit.DIP
            , filterText
            , matchCase
            , containsMode
            , multiSelect
            , list
            , allSelectedItems
            , currentCheckListAdapter);
}
项目:AndroidDataBinding    文件:LoginViewModelTest.java   
@Test
public void testInputPassword() {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append("abcd");
    TextWatcher textWatcher = new CustomTextWatcher() {
        @Override
        public void afterTextChanged(Editable editable) {
            super.afterTextChanged(editable);
            loginRequest.setPassword(editable.toString());
        }
    };
    textWatcher.afterTextChanged(builder);
    assertFalse(loginRequest.isPasswordEmpty());
    assertFalse(loginRequest.isValidPassword());
    builder.clear();
    builder.append("abcd123");
    textWatcher.afterTextChanged(builder);
    assertTrue(loginRequest.isValidPassword());
}
项目:IndustryCalculatorForEVE    文件:BigDecimalEditText.java   
@Override
public void onFocusChange(View v, boolean has_focus)
{
  EditText ed = (EditText)v;
  TextWatcher w = (TextWatcher)ed.getTag();
  ed.removeTextChangedListener(w);
  if(has_focus)
  {
    ed.setSelection(ed.getText().length());
    if(focus_listener != null)
    {
      focus_listener.FocusReceived(tag);
    }
  }
  ed.addTextChangedListener(w);
}
项目:IndustryCalculatorForEVE    文件:BigDecimalEditText.java   
public void setValue(BigDecimal value)
{
  TextWatcher w = (TextWatcher)editor.getTag();
  editor.removeTextChangedListener(w);
  if(value.compareTo(min) < 0)
  {
    value = min;
  }
  if(value.compareTo(max) > 0)
  {
    value = max;
  }
  DecimalFormat formatter = new DecimalFormat("###.##");
  editor.setText(formatter.format(value));
  editor.addTextChangedListener(w);   
}
项目:IndustryCalculatorForEVE    文件:IntegerEditText.java   
@Override
public void onFocusChange(View v, boolean has_focus)
{
  EditText ed = (EditText)v;
  TextWatcher w = (TextWatcher)ed.getTag();
  ed.removeTextChangedListener(w);
  if(has_focus)
  {
    ed.setSelection(ed.getText().length());
  } else
  {
    int i = getValue(ed.getText().toString());
    ed.setText(String.valueOf(i));
  }
  ed.addTextChangedListener(w);
}
项目:IndustryCalculatorForEVE    文件:DoubleEditText.java   
@Override
public void onFocusChange(View v, boolean has_focus)
{
  EditText ed = (EditText)v;
  TextWatcher w = (TextWatcher)ed.getTag();
  ed.removeTextChangedListener(w);
  if(has_focus)
  {
    ed.setSelection(ed.getText().length());
    if(focus_listener != null)
    {
      focus_listener.FocusReceived(tag);
    }
  }/* else
  {
    double i = get(ed.getText().toString());
    ed.setText(String.valueOf(i));
  }*/
  ed.addTextChangedListener(w);
}
项目:credit_card_lib    文件:CreditCardBaseTextWatcher.java   
protected boolean checkIsCorrectTextWatcher(Editable editable, TextWatcher textWatcher) {
    CARD_TYPE currentCardType = getCurrentCardType();
    CARD_TYPE newCardType = getNewCardType(editable.toString());

    if(newCardType == currentCardType) {
        return true;
    }

    if(newCardType == CARD_TYPE.OTHERS) {
        mEditText.removeTextChangedListener(textWatcher);
        mEditText.addTextChangedListener(new OtherCardTextWatcher(mEditText));
        mEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(OTHERS_MAX_LENGTH)});
        setCursorPosition();
    } else if(newCardType == CARD_TYPE.AMERICAN_EXPRESS) {
        mEditText.removeTextChangedListener(textWatcher);
        mEditText.addTextChangedListener(new AmericanExpressTextWatcher(mEditText));
        mEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(AMERICAN_EXPRESS_MAX_LENGTH)});
        setCursorPosition();
    }
    return false;
}
项目:biermacht    文件:AlertBuilder.java   
public <T> AlertDialog.Builder searchableListAlert(final TextView text, final TextView title, final ArrayAdapter<T> adapter,
                                                   final ArrayList<T> list, final OnItemClickListener listener, TextWatcher textWatcher) {
  LayoutInflater factory = LayoutInflater.from(context);
  final LinearLayout alertView = (LinearLayout) factory.inflate(R.layout.alert_view_searchable_list, null);
  final EditText editText = (EditText) alertView.findViewById(R.id.edit_text);
  final ListView listView = (ListView) alertView.findViewById(R.id.list);
  listView.setOnItemClickListener(listener);
  listView.setAdapter(adapter);

  // Search text watcher.
  editText.addTextChangedListener(textWatcher);
  textWatcher.onTextChanged("", 0, 0, 0);

  return new AlertDialog.Builder(context)
          .setTitle(title.getText().toString())
          .setView(alertView)
          .setNegativeButton(R.string.cancel, null);
}
项目:android-SimpleNetCat    文件:MainFragment.java   
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
{
    View view = inflater.inflate( R.layout.fragment_main, container, false );
    ButterKnife.inject( this, view );
    TextWatcher watcher = new TextWatcherAdapter()
    {
        public void afterTextChanged( final Editable editable )
        {
            updateUIWithValidation();
        }
    };
    connectToText.setAdapter( connectToArrayAdapter );
    connectToText.addTextChangedListener( watcher );
    listenOnText.addTextChangedListener( watcher );
    return view;
}
项目:YiBo    文件:AddAccountActivity.java   
private void bindEvent() {
    Button btnBack = (Button) this.findViewById(R.id.btnBack);
    btnBack.setOnClickListener(new GoBackClickListener(R.anim.slide_in_right));

    spServiceProvider.setAdapter(new ServiceProviderSpinnerAdapter(this));
    OnItemSelectedListener spItemListener = new AddAccountSpItemSelectedListener(this);
    spServiceProvider.setOnItemSelectedListener(spItemListener);


    spConfigApp.setAdapter(new ConfigAppSpinnerAdapter(this));
    OnItemSelectedListener configAppItemSelectedListener = null;
    configAppItemSelectedListener = new AddAccountConfigAppItemSelectedListener(this);
    spConfigApp.setOnItemSelectedListener(configAppItemSelectedListener);

    TextWatcher editTextWatcher = new AddAccountTextWatcher(this);
    etUsername.addTextChangedListener(editTextWatcher);
    etPassword.addTextChangedListener(editTextWatcher);
    etRestProxy.addTextChangedListener(editTextWatcher);
    etSearchProxy.addTextChangedListener(editTextWatcher);

    AddAccountAuthorizeClickListener authorizeClickListener = null;
    authorizeClickListener = new AddAccountAuthorizeClickListener(this);
    btnAuthorize.setOnClickListener(authorizeClickListener);

}
项目:selendroid    文件:HomeScreenActivity.java   
private void initExceptionTestField() {
  EditText exceptionTestField =
      (EditText) findViewById(io.selendroid.testapp.R.id.exceptionTestField);
  exceptionTestField.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {}

    @Override
    public void afterTextChanged(Editable editable) {
      throw new RuntimeException("Unhandled Exception Test!");
    }
  });
}
项目:mongol-library    文件:MongolEditText.java   
/**
 * Adds a TextWatcher to the list of those whose methods are called
 * whenever this MongolEditText's text changes.
 */
public void addTextChangedListener(TextWatcher watcher) {
    if (mListeners == null) {
        mListeners = new ArrayList<>();
    }

    mListeners.add(watcher);
}
项目:mongol-library    文件:MongolEditText.java   
/**
 * Removes the specified TextWatcher from the list of those whose
 * methods are called
 * whenever this TextView's text changes.
 */
public void removeTextChangedListener(TextWatcher watcher) {
    if (mListeners != null) {
        int i = mListeners.indexOf(watcher);

        if (i >= 0) {
            mListeners.remove(i);
        }
    }
}
项目:AndroidBackendlessChat    文件:ChatSDKProfileFragment.java   
@Override
public void onResume() {
    super.onResume();

    // Setting a listener to text change, The listener will take cate of indexing the data.
    SaveIndexDetailsTextWatcher emailTextWatcher = new SaveIndexDetailsTextWatcher(BDefines.Keys.BEmail);
    SaveIndexDetailsTextWatcher nameTextWatcher= new SaveIndexDetailsTextWatcher(BDefines.Keys.BName);
    etMail.addTextChangedListener(emailTextWatcher);
    etName.addTextChangedListener(nameTextWatcher);


    // The number would only be index if phone index is enabled in BDefines.
    TextWatcher phoneTextWatcher = new SaveIndexDetailsTextWatcher(BDefines.Keys.BPhone);
    etPhone.addTextChangedListener(phoneTextWatcher);
}
项目:floating_calc    文件:FormattedNumberEditText.java   
@Override
public void addTextChangedListener(TextWatcher watcher) {
    // Some flavors of Android call addTextChangedListener in the constructor, so add a
    // null check to mTextWatchers
    if (watcher.equals(mTextWatcher) || mTextWatchers == null) {
        super.addTextChangedListener(watcher);
    } else {
        mTextWatchers.add(watcher);
    }
}
项目:MTweaks-KernelAdiutorMOD    文件:BuildpropFragment.java   
public static SearchFragment newInstance(String keyText, String valueText, TextWatcher keyWatcher,
                                         TextWatcher valueWatcher) {
    SearchFragment fragment = new SearchFragment();
    fragment.mKeyText = keyText;
    fragment.mValueText = valueText;
    fragment.mKeyWatcher = keyWatcher;
    fragment.mValueWatcher = valueWatcher;
    return fragment;
}
项目:chat-sdk-android-push-firebase    文件:ChatSDKProfileFragment.java   
@Override
public void onResume() {
    super.onResume();

    // Setting a listener to text change, The listener will take cate of indexing the data.
    SaveIndexDetailsTextWatcher emailTextWatcher = new SaveIndexDetailsTextWatcher(BDefines.Keys.BEmail);
    SaveIndexDetailsTextWatcher nameTextWatcher= new SaveIndexDetailsTextWatcher(BDefines.Keys.BName);
    etMail.addTextChangedListener(emailTextWatcher);
    etName.addTextChangedListener(nameTextWatcher);


    // The number would only be index if phone index is enabled in BDefines.
    TextWatcher phoneTextWatcher = new SaveIndexDetailsTextWatcher(BDefines.Keys.BPhone);
    etPhone.addTextChangedListener(phoneTextWatcher);
}
项目:buildAPKsApps    文件:AlarmOptions.java   
private void setEdit(View v, String s, int hint_res, TextWatcher w) {
  EditText t = (EditText)v.findViewById(R.id.setting_edit);
  t.setVisibility(View.VISIBLE);
  t.addTextChangedListener(w);
  t.setText(s);
  t.setSelection(s.length());
  t.setHint(hint_res);
}
项目:KernelAdiutor-Mod    文件:BuildpropFragment.java   
public static SearchFragment newInstance(String keyText, String valueText, TextWatcher keyWatcher,
                                         TextWatcher valueWatcher) {
    SearchFragment fragment = new SearchFragment();
    fragment.mKeyText = keyText;
    fragment.mValueText = valueText;
    fragment.mKeyWatcher = keyWatcher;
    fragment.mValueWatcher = valueWatcher;
    return fragment;
}
项目:ClickDrawableTextView    文件:ClickDrawableAutoCompleteTextView.java   
@Override
public void addTextChangedListener(TextWatcher watcher) {
    super.addTextChangedListener(watcher);
    if (mCsDrawableViewManager != null){
        mCsDrawableViewManager.addTextWatcher(watcher);
    }
}
项目:ClickDrawableTextView    文件:ClickDrawableAutoCompleteTextView.java   
@Override
public void removeTextChangedListener(TextWatcher watcher) {
    super.removeTextChangedListener(watcher);
    if (mCsDrawableViewManager != null){
        mCsDrawableViewManager.removeTextWatcher();
    }
}
项目:ClickDrawableTextView    文件:ClickDrawableTextView.java   
@Override
public void addTextChangedListener(TextWatcher watcher) {
    super.addTextChangedListener(watcher);
    if (mCsDrawableViewManager != null){
        mCsDrawableViewManager.addTextWatcher(watcher);
    }
}
项目:ClickDrawableTextView    文件:ClickDrawableTextView.java   
@Override
public void removeTextChangedListener(TextWatcher watcher) {
    super.removeTextChangedListener(watcher);
    if (mCsDrawableViewManager != null){
        mCsDrawableViewManager.removeTextWatcher();
    }
}
项目:ClickDrawableTextView    文件:ClickDrawableEditText.java   
@Override
public void addTextChangedListener(TextWatcher watcher) {
    super.addTextChangedListener(watcher);
    if (mCsDrawableViewManager != null){
        mCsDrawableViewManager.addTextWatcher(watcher);
    }
}
项目:GravityBox    文件:ModMms.java   
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
    try {
        if (!prepareUnicodeFilter()) return;

        if (DEBUG) log("ComposeMessageActivity created. Hooking to TextEditorWatcher");

        final TextWatcher textEditorWatcher = (TextWatcher) XposedHelpers.getObjectField(
                param.thisObject, "mTextEditorWatcher");
        if (textEditorWatcher != null) {
            XposedHelpers.findAndHookMethod(textEditorWatcher.getClass(), "onTextChanged", 
                    CharSequence.class, int.class, int.class, int.class, new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param2) throws Throwable {
                    if (param2.thisObject != textEditorWatcher) return;

                    CharSequence s = (CharSequence) param2.args[0];
                    if (DEBUG) log("TextEditorWatcher.onTextChanged: original ='" + s + "'");
                    s = mUnicodeFilter.filter(s);
                    if (DEBUG) log("TextEditorWatcher.onTextChanged: stripped ='" + s + "'");
                    param2.args[0] = s;
                }
            });
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
项目:BlueTape    文件:TextWatcherAdapterTest.java   
@Test
public void notifyListener() throws Exception {
    // Given
    TextWatcher watcher = TextWatcherAdapter.whenTextChanged(listener);

    given(editable.toString())
            .willReturn("value");

    // When
    watcher.afterTextChanged(editable);

    // Then
    verify(listener).onTextChanged("value");
}
项目:BlueTape    文件:TextChangedBindingFunctionTest.java   
@Test
public void addTextWatcher() throws Exception {
    // Given
    BindingFunction function = TextChangedBindingFunction.create(listener);

    // When
    function.bind(view);

    // Then
    verify(view).addTextChangedListener(isA(TextWatcher.class));
    verify(view).setTag(eq(R.id.onTextChangedListener), isA(TextWatcher.class));
}
项目:FormatEditText    文件:FormattedEditText.java   
@Override
public void addTextChangedListener(TextWatcher watcher) {
    if (mWatchers == null) {
        mWatchers = new ArrayList<>();
    }
    mWatchers.add(watcher);
}
项目:FormatEditText    文件:FormattedEditText.java   
@Override
public void removeTextChangedListener(TextWatcher watcher) {
    if (mWatchers != null) {
        int i = mWatchers.indexOf(watcher);
        if (i >= 0) {
            mWatchers.remove(i);
        }
    }
}
项目:FormatEditText    文件:FormattedEditText.java   
private void sendBeforeTextChanged(CharSequence text, int start, int before, int after) {
    if (mWatchers != null) {
        final ArrayList<TextWatcher> list = mWatchers;
        final int size = list.size();
        for (int i = 0; i < size; i++) {
            list.get(i).beforeTextChanged(text, start, before, after);
        }
    }
}
项目:FormatEditText    文件:FormattedEditText.java   
private void sendOnTextChanged(CharSequence s, int start, int before, int count) {
    if (mWatchers != null) {
        final ArrayList<TextWatcher> list = mWatchers;
        final int size = list.size();
        for (int i = 0; i < size; i++) {
            list.get(i).onTextChanged(s, start, before, count);
        }
    }
}
项目:FormatEditText    文件:FormattedEditText.java   
private void sendAfterTextChanged(Editable s) {
    if (mWatchers != null) {
        final ArrayList<TextWatcher> list = mWatchers;
        final int size = list.size();
        for (int i = 0; i < size; i++) {
            list.get(i).afterTextChanged(s);
        }
    }
}
项目:RNLearn_Project1    文件:ReactEditText.java   
@Override
public void addTextChangedListener(TextWatcher watcher) {
  if (mListeners == null) {
    mListeners = new ArrayList<>();
    super.addTextChangedListener(getTextWatcherDelegator());
  }

  mListeners.add(watcher);
}