Example usage for android.text TextWatcher TextWatcher

List of usage examples for android.text TextWatcher TextWatcher

Introduction

In this page you can find the example usage for android.text TextWatcher TextWatcher.

Prototype

TextWatcher

Source Link

Usage

From source file:co.juliansuarez.libwizardpager.wizard.ui.CustomerInfoFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mNameView.addTextChangedListener(new TextWatcher() {
        @Override/*from   w w  w.  j  a va  2 s  .co m*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.NAME_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mEmailView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.EMAIL_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:com.example.phkim.mycleanmvp.main.SearchFragment.java

private void addTextWatcher(EditText et) {
    et.addTextChangedListener(new TextWatcher() {
        @Override// w  w w. j  a va2  s . com
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mPresenter.inputTextSearch(s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

From source file:com.example.android.downloadablefonts.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initializeSeekBars();/*from ww w  .  ja  v  a2s  . c o  m*/
    mFamilyNameSet = new ArraySet<>();
    mFamilyNameSet.addAll(Arrays.asList(getResources().getStringArray(R.array.family_names)));

    mDownloadableFontTextView = findViewById(R.id.textview);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.family_names));
    final TextInputLayout familyNameInput = findViewById(R.id.auto_complete_family_name_input);
    final AutoCompleteTextView autoCompleteFamilyName = findViewById(R.id.auto_complete_family_name);
    autoCompleteFamilyName.setAdapter(adapter);
    autoCompleteFamilyName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
            // No op
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int count, int after) {
            if (isValidFamilyName(charSequence.toString())) {
                familyNameInput.setErrorEnabled(false);
                familyNameInput.setError("");
            } else {
                familyNameInput.setErrorEnabled(true);
                familyNameInput.setError(getString(R.string.invalid_family_name));
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            // No op
        }
    });

    mRequestDownloadButton = findViewById(R.id.button_request);
    mRequestDownloadButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String familyName = autoCompleteFamilyName.getText().toString();
            if (!isValidFamilyName(familyName)) {
                familyNameInput.setErrorEnabled(true);
                familyNameInput.setError(getString(R.string.invalid_family_name));
                Toast.makeText(MainActivity.this, R.string.invalid_input, Toast.LENGTH_SHORT).show();
                return;
            }
            requestDownload(familyName);
            mRequestDownloadButton.setEnabled(false);
        }
    });
    mBestEffort = findViewById(R.id.checkbox_best_effort);
}

From source file:com.example.android.common.logger.LogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View result = inflateViews();

    mLogView.addTextChangedListener(new TextWatcher() {
        @Override/*ww  w.j  a  v a 2 s .c om*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
        }
    });
    return result;
}

From source file:com.example.flashcards.wizardpager.wizard.ui.HandInputFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mFirstView.addTextChangedListener(new TextWatcher() {
        @Override/*from w  ww.j a  v  a2 s.  co  m*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(HandInputWordPage.FIRST, (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mSecondView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(HandInputWordPage.SECOND,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:com.gelakinetic.mtgfam.helpers.AutocompleteCursorAdapter.java

/**
 * Standard constructor.//from w w  w  .j a v  a2  s . c om
 *
 * @param context  The context where the ListView associated with this SimpleListItemFactory is running
 * @param from     A list of column names representing the data to bind to the UI. Can be null if the cursor is not
 *                 available yet.
 * @param to       The views that should display column in the "from" parameter. These should all be TextViews. The
 *                 first N views in this list are given the values of the first N columns in the from parameter.
 *                 Can be null if the cursor is not available yet.
 * @param textView The text view which we are watching for changes
 */
public AutocompleteCursorAdapter(FamiliarFragment context, String[] from, int[] to,
        AutoCompleteTextView textView, boolean showArrowhead) {
    super(context.getActivity(), showArrowhead ? R.layout.list_item_1_arrowhead : R.layout.list_item_1, null,
            from, to, 0);
    mFragment = context;
    mFragment.getLoaderManager().initLoader(0, null, this);
    textView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            /* Don't care */
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            /* Don't care */
        }

        @Override
        public void afterTextChanged(Editable editable) {
            /* Preform a query */
            mAutocompleteFilter[0] = String.valueOf(editable);
            mFragment.getLoaderManager().restartLoader(0, null, AutocompleteCursorAdapter.this);
        }
    });
}

From source file:com.krossovochkin.kwitter.fragments.SendTweetFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final EditText tweetEditText = (EditText) getView().findViewById(R.id.tweet_edit_text);
    final FloatingActionButton sendTweetButton = (FloatingActionButton) getView()
            .findViewById(R.id.send_tweet_button);
    final TextView symbolCounterTextView = (TextView) getView().findViewById(R.id.char_counter_text_view);

    tweetEditText.addTextChangedListener(new TextWatcher() {
        @Override/* w  ww  . j ava 2s. c  om*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (tweetEditText.getText() != null) {
                int charsLeft = getResources().getInteger(R.integer.max_tweet_char_length)
                        - tweetEditText.getText().length();
                symbolCounterTextView.setText(String.valueOf(charsLeft));

                if (charsLeft < 0) {
                    sendTweetButton.setEnabled(false);
                } else {
                    sendTweetButton.setEnabled(true);
                }
            }
        }
    });

    if (isReply()) {
        Status status = (Status) getArguments().getSerializable(Constants.STATUS_KEY);
        StringBuilder mentions = new StringBuilder();

        mentions.append("@");
        mentions.append(status.getUser().getScreenName());
        mentions.append(" ");

        for (UserMentionEntity mentionEntity : status.getUserMentionEntities()) {
            mentions.append("@");
            mentions.append(mentionEntity.getScreenName());
            mentions.append(" ");
        }
        tweetEditText.setText(mentions.toString());
    }

    sendTweetButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (twitterActionListener != null) {
                if (tweetEditText.getText() != null) {

                    if (isReply()) {
                        Status status = (Status) getArguments().getSerializable(Constants.STATUS_KEY);
                        twitterActionListener.sendReplyRequest(status, tweetEditText.getText().toString());
                    } else {
                        twitterActionListener.sendTweetRequest(tweetEditText.getText().toString());
                    }

                    getFragmentManager().popBackStack();
                } else {
                    Log.e(TAG, "tweetEditText has no text");
                }
            } else {
                Log.e(TAG, "twitterActionListener from SendTweetFragment is null, did the fragment"
                        + "is attached to activity?");
            }
        }
    });

    KeyboardHelper.showSoftKeyboard(getActivity(), tweetEditText);
}

From source file:fi.tuukka.weather.view.FragmentStations.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.asemat, container, false);
    rg = (RadioGroup) view.findViewById(R.id.radioGroup1);
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override//from   w  w  w  .  j  a  v  a 2  s .  co  m
        public void onCheckedChanged(RadioGroup rg, int id) {
            if (listenCheck) {
                for (int i = 0; i < rg.getChildCount(); i++) {
                    RadioButton btn = (RadioButton) rg.getChildAt(i);
                    if (btn.getId() == id) {
                        String text = (String) btn.getText();
                        Station station = new Station(text, null);
                        changeStation(station);
                        refreshStations();
                        return;
                    }
                }
            }
        }
    });
    EditText searchBox = (EditText) view.findViewById(R.id.stationSearchBox);
    searchBox.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String string = s.toString();
            if (query == null || !query.equals(string)) {
                query = s.toString();
                stationStrings = null; // mark as not finished
                ((ActivityMain) getActivity()).queryStations();
            }
        }
    });
    Activity activity = getActivity();
    header = (TextView) view.findViewById(R.id.stationsHeader);
    int fontsize = Utils.getScaledFont(activity);
    int pad = Utils.dpToPx(5, activity);
    header.setTextAppearance(activity, R.style.TextStyle);
    header.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontsize);
    header.setPadding(0, pad, 0, pad);
    header.setText("Syt kunta/kunnanosa:");
    super.onCreateView(inflater, container, savedInstanceState);
    return view;
}

From source file:dtu.ds.warnme.app.dialog.LoginDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_login, null);
    builder.setView(view);//  w  w  w .j  a v a  2s.  c om
    builder.setTitle(R.string.login);
    builder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing do to here...
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing do to here...
        }
    });

    progressView = view.findViewById(R.id.dialog_login_progress);
    formView = view.findViewById(R.id.dialog_login_form);

    usernameEditText = (EditText) view.findViewById(R.id.dialog_login_edit_text_username);
    usernameEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            usernameEditText.setError(null);
        }
    });

    passwordEditText = (EditText) view.findViewById(R.id.dialog_login_edit_text_password);
    passwordEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            passwordEditText.setError(null);
        }
    });

    dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final String username = usernameEditText.getText().toString();
                    String password = passwordEditText.getText().toString();

                    boolean formOk = true;

                    if (StringUtils.isBlank(username)) {
                        usernameEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }
                    if (StringUtils.isBlank(password)) {
                        passwordEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }

                    if (!formOk) {
                        Log.d(TAG, "Form contains errors.");
                        return;
                    }

                    final String hashedPassword = SecurityUtils.hashSHA512Base64(password);

                    tempRestClient = new RestClient(Prefs.getHost(), Prefs.getPort(), Prefs.getWsContextPath(),
                            username, hashedPassword, Prefs.getRealm());
                    tempRestClient.getProfile(dialog.getContext(),
                            new GsonHttpResponseHandler<User>(new TypeToken<User>() {
                            }.getType()) {

                                @Override
                                public void onFailure(int statusCode, Header[] headers, String responseBody,
                                        Throwable error) {
                                    Log.e(TAG, "Login failed. [statusCode = " + statusCode + ", error=" + error
                                            + "]");

                                    if (statusCode == 0) {
                                        Toast.makeText(dialog.getOwnerActivity(), R.string.check_connection,
                                                Toast.LENGTH_LONG).show();
                                        return;
                                    }

                                    usernameEditText.setError(
                                            getResources().getText(R.string.bad_username_or_password));
                                    passwordEditText.setError(
                                            getResources().getText(R.string.bad_username_or_password));
                                    listener.onLoginFailure();
                                }

                                @Override
                                public void onFinish() {
                                    positiveButton.setEnabled(true);
                                    UiUtilities.fadeInFadeOut(formView, progressView);
                                }

                                @Override
                                public void onStart() {
                                    positiveButton.setEnabled(false);
                                    UiUtilities.fadeInFadeOut(progressView, formView);
                                }

                                @Override
                                public void onSuccess(int statusCode, Header[] headers, User user) {
                                    Log.i(TAG, "Login succeeded. [statusCode = " + statusCode + "]");
                                    UserProfileHolder.setUserProfile(user);
                                    Prefs.setUsername(username);
                                    Prefs.setPasswordHash(hashedPassword);
                                    dialog.dismiss();

                                    listener.onLoginSuccess();
                                }

                            });

                }
            });

            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (tempRestClient != null) {
                        tempRestClient.cancelRequests(dialog.getOwnerActivity(), true);
                    }
                    dialog.dismiss();
                }
            });
        }
    });

    return dialog;
}

From source file:com.grarak.kerneladiutor.fragments.tools.BuildpropFragment.java

@Override
protected void init() {
    super.init();

    addViewPagerFragment(mSearchFragment = SearchFragment.newInstance(mKeyText, mValueText, new TextWatcher() {
        @Override/*from   ww w .j  a v  a 2s  .c om*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            mKeyText = s.toString();
            reload(false);
        }
    }, new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            mValueText = s.toString();
            reload(false);
        }
    }));

    if (mAddDialog != null) {
        mAddDialog.show();
    }
    if (mItemOptionsDialog != null) {
        mItemOptionsDialog.show();
    }
    if (mDeleteDialog != null) {
        mDeleteDialog.show();
    }
    if (mKey != null) {
        modify(mKey, mValue);
    }
}