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:com.jaymullen.TrailJournal.wizard.ui.MilesFragment.java

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

    mMilesView.addTextChangedListener(new TextWatcher() {
        @Override// ww  w.  j  av a 2 s.c o 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(MilesPage.MILES_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.common.DialogPassword.java

public void showField() {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
    final String currentPassword = settings.getString(DialogPasswordSettings.KEY_PASSWORD, "");
    if (currentPassword.isEmpty()) {
        binding.passwordVerificationField.setVisibility(View.VISIBLE);
    } else {/*from w w w.j a  v a  2s  .c o  m*/
        binding.passwordVerificationField.setVisibility(View.GONE);
    }

    binding.passwordField.addTextChangedListener(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) {
            binding.buttons.dialogYes.setEnabled(s.length() > 0);
        }
    });

    binding.buttons.dialogNo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();
        }
    });

    binding.buttons.dialogYes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            confirm();
        }
    });
}

From source file:com.iutiao.sdk.dialogs.LoginDialog.java

public void updateUI() {
    //        Validate.notNull(signinBtn, "signinBtn");
    signinBtn.setEnabled(false);/*from   w w w . j a  v  a 2s. c o m*/
    usernameEt.setText(Utility.getMyPhoneNumber());
    usernameEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                passwordEt.requestFocus();
            }
            return true;
        }
    });

    passwordEt.addTextChangedListener(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) {
            if (passwordEt.getText().toString().length() >= 6) {
                signinBtn.setEnabled(true);
            } else if (signinBtn.isEnabled()) {
                signinBtn.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    signinBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String username = getInputUsername();
            if (Validate.isEmailValid(username) || Validate.isPhoneValid(username, "CN")) {
                performSignin();
            } else {
                Log.i("REG", "username " + username + " isEmailValid " + Validate.isEmailValid(username)
                        + " isPhoneValid " + Validate.isPhoneValid(username, "CN"));
                usernameEt.setError(getActivity().getString(R.string.com_iutiao_error_invalid_email_or_phone));
            }
        }
    });

    quickRegisterTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fragment.showQuickRegisterDialog();
        }
    });

    forgotPassTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fragment.showResetPasswordDialog();
        }
    });

}

From source file:com.home.young.filepicker.NewItemFragment.java

@NonNull
@Override// ww w  . j  av a  2s .c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(R.layout.nnf_dialog_folder_name).setTitle(R.string.nnf_new_folder)
            .setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, null);

    final AlertDialog dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog1) {
            final AlertDialog dialog = (AlertDialog) dialog1;
            final EditText editText = (EditText) dialog.findViewById(R.id.edit_text);

            if (editText == null) {
                throw new NullPointerException("Could not find an edit text in the dialog");
            }

            Button cancel = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
            cancel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    dialog.cancel();
                }
            });

            final Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            // Start disabled
            ok.setEnabled(false);
            ok.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    String itemName = editText.getText().toString();
                    if (validateName(itemName)) {
                        if (listener != null) {
                            listener.onNewFolder(itemName);
                        }
                        dialog.dismiss();
                    }
                }
            });

            editText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(final CharSequence s, final int start, final int count,
                        final int after) {
                }

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

                @Override
                public void afterTextChanged(final Editable s) {
                    ok.setEnabled(validateName(s.toString()));
                }
            });
        }
    });

    return dialog;
}

From source file:com.marakana.android.yamba.StatusFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle state) {
    super.onCreateView(inflater, parent, state);
    Log.d(TAG, "in onCreateView: " + state);

    View v = inflater.inflate(R.layout.fragment_status, parent, false);

    count = (TextView) v.findViewById(R.id.status_count);

    status = (EditText) v.findViewById(R.id.status_text);
    status.addTextChangedListener(new TextWatcher() {
        @Override//ww  w.  ja  v  a2  s.c  om
        public void afterTextChanged(Editable s) {
        }

        @Override
        public void beforeTextChanged(CharSequence cs, int s, int c, int a) {
        }

        @Override
        public void onTextChanged(CharSequence cs, int s, int b, int c) {
            setCount();
        }
    });

    ((Button) v.findViewById(R.id.status_submit)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v1) {
            submit();
        }
    });

    return v;
}

From source file:mp.paschalis.SendMessageActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send_message);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    app = (App) getApplication();// w w  w.  j  a v  a  2  s  . co m

    editTextMessage = (EditText) findViewById(R.id.editTextMessage);

    buttonSendMessage = (Button) findViewById(R.id.buttonSendMessage);
    progressBarSendMessage = (ProgressBar) findViewById(R.id.progressBarSendMessage);

    // Get arguments, to determine who opened this activity
    final Bundle extras = getIntent().getExtras();

    try {
        destUser = extras.getString(App.ExtrasForSendMessage_DestinationUser);
    } catch (Exception e) {
        this.finish();
    }

    editTextMessage.addTextChangedListener(new TextWatcher() {

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

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (editTextMessage.getText().length() >= 3)
                buttonSendMessage.setEnabled(true);
            else
                buttonSendMessage.setEnabled(false);
        }
    });

    buttonSendMessage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new AsyncTaskSendMessage().execute(destUser);

        }
    });

}

From source file:net.eledge.android.europeana.gui.dialog.NameInputDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view = inflater.inflate(R.layout.dialog_nameinput, null);
    TextView text = (TextView) view.findViewById(R.id.dialog_nameinput_textview);
    if (resText != -1) {
        text.setText(resText);//  w  w w .  j  ava 2 s  .  com
    } else {
        text.setVisibility(View.GONE);
    }
    mInput = (EditText) view.findViewById(R.id.dialog_nameinput_edittext);
    mInput.setHint(resInput);
    mInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            //ignore
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            mDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(StringUtils.isNotBlank(s.toString()));
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(view);
    if (resTitle != -1) {
        builder.setTitle(resTitle);
    }
    builder.setPositiveButton(resPositiveButton, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            String input = mInput.getText().toString();
            if (StringUtils.isNotBlank(input)) {
                mListener.positiveResponse(input);
                NameInputDialog.this.dismiss();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            mListener.negativeResponse();
            mDialog.dismiss();
        }
    });
    mDialog = builder.create();
    mDialog.setCanceledOnTouchOutside(false);
    mDialog.setCancelable(false);
    return mDialog;
}

From source file:com.jaymullen.TrailJournal.wizard.ui.BodyFragment.java

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

    mBodyView.addTextChangedListener(new TextWatcher() {
        @Override// w  w  w  . j  av  a2 s  .c  o 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(BodyPage.BODY_DATA_KEY, (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:com.mercandalli.android.apps.files.admin.UserAddFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.rootView = inflater.inflate(R.layout.fragment_admin_add_user, container, false);

    this.circle = (ImageButton) this.rootView.findViewById(R.id.circle);
    this.circle.setVisibility(View.GONE);

    this.username = (TextView) this.rootView.findViewById(R.id.username);
    this.password = (TextView) this.rootView.findViewById(R.id.password);

    this.newUser = new UserModel();

    this.username.addTextChangedListener(new TextWatcher() {
        @Override/*ww  w  . j a  v  a2  s  .c  o m*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!StringUtils.isNullOrEmpty(s.toString())
                    && !StringUtils.isNullOrEmpty(password.getText().toString())) {
                circle.setVisibility(View.VISIBLE);
            } else {
                circle.setVisibility(View.GONE);
            }
            newUser.username = s.toString();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    this.password.addTextChangedListener(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) {
            if (!StringUtils.isNullOrEmpty(s.toString())
                    && !StringUtils.isNullOrEmpty(username.getText().toString())) {
                circle.setVisibility(View.VISIBLE);
            } else {
                circle.setVisibility(View.GONE);
            }
            newUser.password = HashUtils.sha1(s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    this.circle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Register : POST /user
            List<StringPair> parameters = new ArrayList<>();
            parameters.add(new StringPair("username", "" + newUser.username));
            parameters.add(new StringPair("password", "" + newUser.password));

            if (NetUtils.isInternetConnection(getContext()) && !StringUtils.isNullOrEmpty(newUser.username)
                    && !StringUtils.isNullOrEmpty(newUser.password)) {
                requestLaunched = true;
                (new TaskPost(getActivity(), Constants.URL_DOMAIN + Config.ROUTE_USER,
                        new IPostExecuteListener() {
                            @Override
                            public void onPostExecute(JSONObject json, String body) {
                                try {
                                    if (json != null) {
                                        if (json.has("succeed") && json.getBoolean("succeed")) {
                                            Toast.makeText(getActivity(), "User added", Toast.LENGTH_SHORT)
                                                    .show();
                                        }
                                        if (json.has("user")) {
                                            JSONObject user = json.getJSONObject("user");
                                            if (user.has("id")) {
                                                Config.setUserId(getActivity(), user.getInt("id"));
                                            }
                                        }
                                    } else {
                                        Toast.makeText(getContext(), R.string.server_error, Toast.LENGTH_SHORT)
                                                .show();
                                    }
                                } catch (JSONException e) {
                                    Log.e(getClass().getName(), "Failed to convert Json", e);
                                }
                                requestLaunched = false;
                            }
                        }, parameters)).execute();
            } else {
                requestLaunched = false;
                Toast.makeText(getActivity(), "Request not sent", Toast.LENGTH_SHORT).show();
            }
        }
    });

    return this.rootView;
}

From source file:com.magizdev.babyoneday.profilewizard.NameFragment.java

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

    mNameView.addTextChangedListener(new TextWatcher() {
        @Override//from ww  w. jav a  2s.  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(Profile.NAME, (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

}