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:mp.paschalis.RegisterActivity.java

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

    app = (App) getApplication();//from   ww  w  .  j av a2 s  .  com

    buttonRegister = (Button) findViewById(R.id.buttonRegister);

    registerAsyncTask = new RegisterAsyncTask();

    registerUsername = (EditText) findViewById(R.id.editTextRegisterUsername);
    registerPassword = (EditText) findViewById(R.id.editTextRegisterPassword);
    registerConfirmPassword = (EditText) findViewById(R.id.editTextRegisterConfirmPassword);
    registerName = (EditText) findViewById(R.id.editTextRegisterName);
    registerSurname = (EditText) findViewById(R.id.editTextRegisterSurname);
    registerEmail = (EditText) findViewById(R.id.editTextRegisterEmail);
    registerPhone = (EditText) findViewById(R.id.editTextRegisterPhone);
    checkBoxNotificationsApplication = (CheckBox) findViewById(R.id.checkBoxRegisterNotificationsApplication);
    checkBoxNotificationsEmail = (CheckBox) findViewById(R.id.checkBoxRegisterNotificationsEmail);
    // textViewConfirmPassword = (TextView)
    // findViewById(R.id.textViewRegisterConfirmPassword);

    // Watch Field Changes
    registerUsername.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) {
            enableRegisterFields(RegisterFields.username);
        }
    });

    registerPassword.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) {
            enableRegisterFields(RegisterFields.password);
        }
    });

    registerConfirmPassword.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) {

            enableRegisterFields(RegisterFields.confirmPassword);
        }
    });

    registerName.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) {
            enableRegisterFields(RegisterFields.name);
        }
    });

    registerSurname.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) {
            enableRegisterFields(RegisterFields.surname);
        }
    });

    registerEmail.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) {
            enableRegisterFields(RegisterFields.email);
        }
    });

    registerPhone.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) {
            enableRegisterFields(RegisterFields.phone);

        }
    });

    buttonRegister.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Try to register user to database

            // Hide Progress Bar, and reEnable button
            ProgressBar progressBarRegisterButton = (ProgressBar) findViewById(R.id.progressBarRegisterButton);

            buttonRegister.setClickable(false);
            progressBarRegisterButton.setVisibility(View.VISIBLE);
            buttonRegister.setVisibility(View.INVISIBLE);

            // Progress Bar Can cancel the task
            progressBarRegisterButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!registerAsyncTask.isCancelled())
                        registerAsyncTask.cancel(true);

                }
            });

            // Login User
            if (!registerAsyncTask.isCancelled()) {
                registerAsyncTask = new RegisterAsyncTask();
            }
            registerAsyncTask.execute(app.library);

        }
    });

}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

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

    NewBlogNotification.cancel(this);

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    searchController.suggestionPageSize = getResources().getInteger(R.integer.home_suggestions_pagesize);
    isLandscape = getResources().getBoolean(R.bool.home_support_landscape);

    mSuggestionsAdaptor = new SuggestionAdapter(this, new ArrayList<Item>());
    mGridViewSuggestions.setAdapter(mSuggestionsAdaptor);
    mGridViewSuggestions.setOnItemClickListener(this);

    mEditTextQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override//from   ww w.  j  av  a2s. c om
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                performSearch(v.getText().toString());
                return true;
            }
            return false;
        }
    });
    mEditTextQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 2) {
                if (mGridViewSuggestions.isShown()) {
                    mSuggestionsAdaptor.clear();
                    mSuggestionsAdaptor.notifyDataSetChanged();
                }
                searchController.suggestions(HomeActivity.this, s.toString());
            } else {
                onTaskFinished(null);
            }
        }

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

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

    mProfilesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item);
    mSpinnerProfiles.setAdapter(mProfilesAdapter);

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (mBlogFragment == null) {
        mBlogFragment = new HomeBlogFragment();
    }
    fragmentTransaction.replace(R.id.activity_home_fragment_blog, mBlogFragment);
    fragmentTransaction.commit();
}

From source file:com.gmail.taneza.ronald.carbs.main.BaseFoodDbListFragment.java

private void addSearchTextListener(ClearableEditText searchEditText) {

    searchEditText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }/*  w  ww .  j ava2  s.co  m*/

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            restartLoader();
        }
    });

    // This listener is called when the Enter key is pressed
    searchEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // Ignore the Enter key because we already do the processing every time the text changes
            return true;
        }
    });
}

From source file:com.miz.mizuu.fragments.SearchWebMoviesFragment.java

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

    mToolbar = (Toolbar) v.findViewById(R.id.toolbar);
    ((MizActivity) getActivity()).setSupportActionBar(mToolbar);

    mProgressBar = (ProgressBar) v.findViewById(R.id.progressBar1);
    v.findViewById(R.id.spinner1).setVisibility(View.GONE);

    mListView = (ListView) v.findViewById(R.id.listView1);
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*  w w w.j  a  v a 2  s.  c  o  m*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            showMovie(arg2);
        }
    });
    mListView.setEmptyView(v.findViewById(R.id.no_results));
    v.findViewById(R.id.no_results).setVisibility(View.GONE);

    // Both the ProgressBar and ListView have been set, so let's hide the ProgressBar
    hideProgressBar();

    mSearchField = (EditText) v.findViewById(R.id.editText1);
    mSearchField.setSelection(mSearchField.length());
    mSearchField.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) {
            if (s.toString().length() > 0)
                searchForMovies();
            else {
                mSearchTask.cancel(true);
                mResults.clear();
                mAdapter.notifyDataSetChanged();
            }
        }
    });
    mSearchField.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    || actionId == EditorInfo.IME_ACTION_SEARCH)
                searchForMovies();
            return true;
        }
    });
}

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

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

    mHeightView.addTextChangedListener(new TextWatcher() {
        @Override//from  ww w  .  j a v a 2  s . 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 editable) {
            float height = 0;
            try {
                height = Float.parseFloat(editable.toString());
            } catch (Exception e) {
            }
            mPage.getData().putFloat(Profile.HEIGHT, (editable != null) ? height : 0);
            mPage.notifyDataChanged();
        }
    });

    mWeightView.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            float weight = 0;
            try {
                weight = Float.parseFloat(arg0.toString());
            } catch (Exception e) {

            }
            mPage.getData().putFloat(Profile.WEIGHT, (arg0 != null) ? weight : 0);
            mPage.notifyDataChanged();
        }
    });
}

From source file:com.hufeiya.SignIn.fragment.SignInFragment.java

private void initContentViews(View view) {
    TextWatcher textWatcher = new TextWatcher() {
        @Override//from   w  w  w  . j a v  a2s . com
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            /* no-op */
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // showing the floating action button if text is entered
            if (s.length() == 0) {
                mDoneFab.hide();
            } else {
                mDoneFab.show();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            /* no-op */
        }
    };
    progressBar = (ProgressBar) view.findViewById(R.id.empty);
    phone = (EditText) view.findViewById(R.id.phone);
    phone.addTextChangedListener(textWatcher);
    pass = (EditText) view.findViewById(R.id.pass);
    pass.addTextChangedListener(textWatcher);
    mDoneFab = (FloatingActionButton) view.findViewById(R.id.done);
    mDoneFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.done:

                progressBar.setVisibility(View.VISIBLE);

                AsyncHttpHelper.login(phone.getText().toString(), pass.getText().toString(),
                        SignInFragment.this);
                break;
            default:
                throw new UnsupportedOperationException("The onClick method has not been implemented for "
                        + getResources().getResourceEntryName(v.getId()));
            }
        }
    });

}

From source file:com.wenwen.chatuidemo.activity.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ????/*w ww.j  av  a2  s .  c  o  m*/
    if (DemoHXSDKHelper.getInstance().isLogined()) {
        autoLogin = true;
        startActivity(new Intent(LoginActivity.this, MainActivity.class));
        return;
    }
    setContentView(R.layout.activity_login);
    usernameEditText = (EditText) findViewById(R.id.username);
    if (DemoApplication.getInstance().getUserName() != null
            && !DemoApplication.getInstance().getUserName().equals("")) {
        usernameEditText.setText(DemoApplication.getInstance().getUserName());
    }
    passwordEditText = (EditText) findViewById(R.id.password);
    loginhandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            int key = msg.what;
            switch (key) {
            case 1:
                EMChatManager.getInstance().login(MD5.md5(usernameEditText.getText().toString().trim()),
                        MD5.md5("ys_" + passwordEditText.getText().toString().trim()).toUpperCase(),
                        new EMCallBack() {
                            @Override
                            public void onSuccess() {
                                // ?????
                                DemoApplication.getInstance()
                                        .setUserName(usernameEditText.getText().toString().trim());
                                DemoApplication.getInstance().setPassword(
                                        MD5.md5("ys_" + passwordEditText.getText().toString().trim())
                                                .toUpperCase());
                                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                                pd.dismiss();
                                finish();
                            }

                            @Override
                            public void onProgress(int progress, String status) {

                            }

                            @Override
                            public void onError(final int code, final String message) {
                                //  loginFailure2Umeng(start,code,message);
                            }
                        });
                break;
            }
            super.handleMessage(msg);
        }
    };
    // ????
    usernameEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            passwordEditText.setText(null);
        }

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

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

}

From source file:ca.uwaterloo.sh6choi.czshopper.ui.FloatLabelLayout.java

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }//  w  ww  .  ja v  a2s .c  o  m
    mEditText = editText;

    // Update the label visibility with no animation
    updateLabelVisibility(false);

    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            updateLabelVisibility(true);
        }

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

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

    // Add focus listener to the EditText so that we can notify the label that it is activated.
    // Allows the use of a ColorStateList for the text color on the label
    mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean focused) {
            updateLabelVisibility(true);
        }
    });

    // If we do not have a valid hint, try and retrieve it from the EditText
    if (TextUtils.isEmpty(mHint)) {
        setHint(mEditText.getHint());
    }
}

From source file:com.layer.messenger.makemoji.MakeMojiAtlasComposer.java

/**
 * Prepares this AtlasMessageComposer for use.
 *
 * @return this AtlasMessageComposer./*from  w w  w  .  j ava  2  s .co m*/
 */
public MakeMojiAtlasComposer init(LayerClient layerClient, ParticipantProvider participantProvider) {
    LayoutInflater.from(getContext()).inflate(com.layer.atlas.R.layout.atlas_message_composer, this);

    mLayerClient = layerClient;
    mParticipantProvider = participantProvider;

    mAttachButton = (ImageView) findViewById(com.layer.atlas.R.id.attachment);
    mAttachButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LinearLayout menu = (LinearLayout) mAttachmentMenu.getContentView();
            menu.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mAttachmentMenu.showAsDropDown(v, 0, -menu.getMeasuredHeight() - v.getHeight());
        }
    });

    mMessageEditText = (EditText) findViewById(com.layer.atlas.R.id.message_edit_text);
    mMessageEditText.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) {
            if (mConversation == null || mConversation.isDeleted())
                return;
            if (s.length() > 0) {
                mSendButton.setEnabled(isEnabled());
                mConversation.send(LayerTypingIndicatorListener.TypingIndicator.STARTED);
            } else {
                mSendButton.setEnabled(false);
                mConversation.send(LayerTypingIndicatorListener.TypingIndicator.FINISHED);
            }
        }
    });

    mSendButton = (Button) findViewById(com.layer.atlas.R.id.send_button);
    final MojiInputLayout analytics = new MojiInputLayout(getContext());
    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!mTextSender.requestSend(Moji.toHtml(mMessageEditText.getText())))
                return;
            analytics.setInputText(mMessageEditText.getText());
            analytics.manualSaveInputToRecentsAndBackend();
            mMessageEditText.setText("");
            mSendButton.setEnabled(false);
        }
    });
    applyStyle();
    return this;
}

From source file:app.com.vaipo.ContactsFragment.java

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

    progressGenerator = new ProgressGenerator(this);
    btnContacts = (ActionProcessButton) rootView.findViewById(R.id.dialTo);
    btnContacts.setMode(ActionProcessButton.Mode.ENDLESS);

    contactEditText = (EditText) rootView.findViewById(R.id.contacts_btn);
    isContactNameSelected = false;//w  w  w .  j  a v a 2  s  .co  m
    btnContacts.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isState(State.LAUNCH_CONTACTS)) {
                progressGenerator.start(btnContacts);

                mCallback.onContactsBtnClicked();
            } else if (isState(State.DIAL)) {
                String number = sharedPreferences.getString("number", "");
                //mOutGoingNumber = contactEditText.getText().toString();
                setupDialMsg(mOutGoingNumber, number);
                enterState(State.END);
            } else if (isState(State.END)) {
                setupEndMsg();
                enterState(State.LAUNCH_CONTACTS);
            }
        }
    });

    contactEditText.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) {
            if (s.length() == 0) {
                enterState(State.LAUNCH_CONTACTS);
                mOutGoingNumber = "";
            } else {
                if (Utils.inCall()) {
                    enterState(State.END);
                } else {
                    enterState(State.DIAL);
                }
                if (!isContactNameSelected)
                    mOutGoingNumber = s.toString();
            }
        }
    });

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver,
            new IntentFilter(Utils.END_VAIPO_CALL));
    return rootView;
}