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); } }); }
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); } }); }
@Override public void removeTextChangedListener(TextWatcher watcher) { super.removeTextChangedListener(watcher); if (mCsDrawableViewManager != null){ mCsDrawableViewManager.removeTextWatcher(); } }
@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()); }
@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); }
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(); }
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); }
@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()); }
@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); }
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); }
@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); }
@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); }
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; }
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); }
@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; }
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); }
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!"); } }); }
/** * 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); }
/** * 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); } } }
@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); }
@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); } }
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; }
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); }
@Override public void addTextChangedListener(TextWatcher watcher) { super.addTextChangedListener(watcher); if (mCsDrawableViewManager != null){ mCsDrawableViewManager.addTextWatcher(watcher); } }
@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); } }
@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"); }
@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)); }
@Override public void addTextChangedListener(TextWatcher watcher) { if (mWatchers == null) { mWatchers = new ArrayList<>(); } mWatchers.add(watcher); }
@Override public void removeTextChangedListener(TextWatcher watcher) { if (mWatchers != null) { int i = mWatchers.indexOf(watcher); if (i >= 0) { mWatchers.remove(i); } } }
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); } } }
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); } } }
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); } } }
@Override public void addTextChangedListener(TextWatcher watcher) { if (mListeners == null) { mListeners = new ArrayList<>(); super.addTextChangedListener(getTextWatcherDelegator()); } mListeners.add(watcher); }