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.myapps.upesse.upes_spefest.ui.activity.CommentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.activity_comments, container, false);
    RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.rvComments);
    mEditText = (EditText) rootView.findViewById(R.id.etComment);
    final Button sendButton = (Button) rootView.findViewById(R.id.btnSendComment);

    final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);
    mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.item_comment,
            CommentViewHolder.class, commentsRef) {
        @Override//  ww  w. j a va  2 s .  c  o m
        protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) {
            Author author = comment.getAuthor();
            viewHolder.commentAuthor.setText(author.getFull_name());
            if (author.getProfile_picture() == null) {
                viewHolder.commentPhoto.setImageResource(R.drawable.ic_person_outline_black);
            } else {
                try {
                    GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto);
                } catch (Exception e) {
                }
            }
            viewHolder.authorRef = author.getUid();
            viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp()));
            viewHolder.commentText.setText(comment.getText());
        }
    };
    sendButton.setEnabled(false);
    mEditText.setHint(R.string.new_comment_hint);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });
    mEditText.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) {
            if (editable.length() > 0) {
                sendButton.setEnabled(true);
            } else {
                sendButton.setEnabled(false);
            }
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Clear input box and hide keyboard.
            final Editable commentText = mEditText.getText();
            mEditText.setText("");
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user == null) {
                Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show();
            }

            Author author = new Author(user.getDisplayName(),
                    user.getPhotoUrl() != null ? user.getPhotoUrl().toString() : null, user.getUid());

            Comment comment = new Comment(author, commentText.toString(), ServerValue.TIMESTAMP);
            commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError error, DatabaseReference firebase) {
                    if (error != null) {
                        Log.w(TAG, "Error posting comment: " + error.getMessage());
                        Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show();
                        mEditText.setText(commentText);
                    }
                }
            });
        }
    });
    mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mCommentsView.setAdapter(mAdapter);
    return rootView;
}

From source file:com.cw.litenote.note_add.Note_addText.java

TextWatcher setTextWatcher() {
    return new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if (!isTextAdded())
                mMenu.findItem(R.id.ADD_TEXT_NOTE).setVisible(false);
            else//from   w  w w .  j  a  va 2s . co  m
                mMenu.findItem(R.id.ADD_TEXT_NOTE).setVisible(true);
        }

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

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

From source file:fr.cph.chicago.core.activity.BusBoundActivity.java

@Override
public final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    App.checkBusData(this);
    if (!this.isFinishing()) {
        setContentView(R.layout.activity_bus_bound);
        ButterKnife.bind(this);

        if (busRouteId == null || busRouteName == null || bound == null || boundTitle == null) {
            final Bundle extras = getIntent().getExtras();
            busRouteId = extras.getString(bundleBusRouteId);
            busRouteName = extras.getString(bundleBusRouteName);
            bound = extras.getString(bundleBusBound);
            boundTitle = extras.getString(bundleBusBoundTitle);
        }/*ww w .j  a  v a 2s  .  c  om*/
        busBoundAdapter = new BusBoundAdapter();
        setListAdapter(busBoundAdapter);
        getListView().setOnItemClickListener((adapterView, view, position, id) -> {
            final BusStop busStop = (BusStop) busBoundAdapter.getItem(position);
            final Intent intent = new Intent(getApplicationContext(), BusActivity.class);

            final Bundle extras = new Bundle();
            extras.putInt(bundleBusStopId, busStop.getId());
            extras.putString(bundleBusStopName, busStop.getName());
            extras.putString(bundleBusRouteId, busRouteId);
            extras.putString(bundleBusRouteName, busRouteName);
            extras.putString(bundleBusBound, bound);
            extras.putString(bundleBusBoundTitle, boundTitle);
            extras.putDouble(bundleBusLatitude, busStop.getPosition().getLatitude());
            extras.putDouble(bundleBusLongitude, busStop.getPosition().getLongitude());

            intent.putExtras(extras);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        });

        filter.addTextChangedListener(new TextWatcher() {
            private List<BusStop> busStopsFiltered;

            @Override
            public void beforeTextChanged(final CharSequence s, final int start, final int count,
                    final int after) {
                busStopsFiltered = new ArrayList<>();
            }

            @Override
            public void onTextChanged(final CharSequence s, final int start, final int before,
                    final int count) {
                if (busStops != null) {
                    Stream.of(busStops).filter(busStop -> StringUtils.containsIgnoreCase(busStop.getName(), s))
                            .forEach(busStopsFiltered::add);
                }
            }

            @Override
            public void afterTextChanged(final Editable s) {
                busBoundAdapter.update(busStopsFiltered);
                busBoundAdapter.notifyDataSetChanged();
            }
        });

        Util.setWindowsColor(this, toolbar, TrainLine.NA);
        toolbar.setTitle(busRouteId + " - " + boundTitle);

        toolbar.setNavigationIcon(arrowBackWhite);
        toolbar.setOnClickListener(v -> finish());

        ObservableUtil.createBusStopBoundObservable(getApplicationContext(), busRouteId, bound)
                .subscribe(onNext -> {
                    busStops = onNext;
                    busBoundAdapter.update(onNext);
                    busBoundAdapter.notifyDataSetChanged();
                }, onError -> {
                    Log.e(TAG, onError.getMessage(), onError);
                    Util.showOopsSomethingWentWrong(getListView());
                });

        Util.trackAction(this, R.string.analytics_category_req, R.string.analytics_action_get_bus,
                BUSES_STOP_URL, 0);

        // Preventing keyboard from moving background when showing up
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    }
}

From source file:ca.ggolda.lendit.fragments.FragChat.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.activity_chat, container, false);

    // Get UserID
    mFirebaseAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mFirebaseAuth.getCurrentUser();
    UserID = user.getUid();// ww  w  .j  a  v  a 2 s. c om
    mUsername = user.getDisplayName();

    mUsername = ANONYMOUS;

    mFirebaseDatabase = FirebaseDatabase.getInstance();

    mUsername = user.getDisplayName();

    mFirebaseStorage = FirebaseStorage.getInstance();

    mMessagesDatabaseReference = mFirebaseDatabase.getReference().child("messages");
    mChatPhotosStorageReference = mFirebaseStorage.getReference().child("chat_photos");

    // Initialize references to views
    mProgressBar = (ProgressBar) v.findViewById(R.id.progressBar);
    mMessageListView = (ListView) v.findViewById(R.id.messageListView);
    mPhotoPickerButton = (ImageButton) v.findViewById(R.id.photoPickerButton);
    mMessageEditText = (EditText) v.findViewById(R.id.messageEditText);
    mSendButton = (Button) v.findViewById(R.id.sendButton);

    // Initialize message ListView and its adapter
    List<InstanceMessage> friendlyMessages = new ArrayList<>();
    mMessageAdapter = new AdapterMessages(getContext(), R.layout.message_slide, friendlyMessages);
    mMessageListView.setAdapter(mMessageAdapter);

    // Initialize progress bar
    mProgressBar.setVisibility(ProgressBar.INVISIBLE);

    // ImagePickerButton shows an image picker to upload a image for a message
    mPhotoPickerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/jpeg");
            intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
            startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER);
        }
    });

    // Enable Send button when there's text to send
    mMessageEditText.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) {
            if (charSequence.toString().trim().length() > 0) {
                mSendButton.setEnabled(true);
            } else {
                mSendButton.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });

    // Send button sends a message and clears the EditText
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // TODO: Send messages on click

            InstanceMessage friendlyMessage = new InstanceMessage(mMessageEditText.getText().toString(),
                    mUsername, null);

            mMessagesDatabaseReference.push().setValue(friendlyMessage);

            // Clear input box
            mMessageEditText.setText("");
        }
    });

    mChildEventListener = new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            InstanceMessage friendlyMessage = dataSnapshot.getValue(InstanceMessage.class);
            mMessageAdapter.add(friendlyMessage);
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    };
    mMessagesDatabaseReference.addChildEventListener(mChildEventListener);

    mAuthStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                //user signed in
                OnSignedInInitialise(user.getDisplayName());
            } else {
                //user signed out
                OnSignedOutCleanUp();
                startActivityForResult(
                        AuthUI.getInstance().createSignInIntentBuilder()
                                .setProviders(AuthUI.EMAIL_PROVIDER, AuthUI.GOOGLE_PROVIDER).build(),
                        RC_SIGN_IN);
            }

        }
    };

    return v;
}

From source file:com.activiti.android.ui.fragments.task.create.CreateStandaloneTaskDialogFragment.java

@Override
public void onStart() {
    super.onStart();
    if (getDialog() != null) {
        descriptionET = ((EditText) ((MaterialDialog) getDialog()).getCustomView()
                .findViewById(R.id.create_task_description));
        nameET = ((EditText) ((MaterialDialog) getDialog()).getCustomView()
                .findViewById(R.id.create_task_name));
        nameET.setSelection(nameET.getText().length());
        ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
        nameET.addTextChangedListener(new TextWatcher() {
            @Override/*from   www.jav  a 2  s  .  c  o m*/
            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 (s.length() == 0) {
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(true);
                }
            }
        });
        UIUtils.showKeyboard(getActivity(), nameET);
    }
}

From source file:com.github.rutvijkumar.twittfuse.fragments.ComposeDialog.java

private void setActionsListeners() {

    tweetIt.setOnClickListener(new OnClickListener() {

        @Override//from  w w  w  .  ja v a  2 s.  c om
        public void onClick(View v) {
            String tweetBody = tweetTextara.getEditableText().toString();

            if (!Util.isNetworkAvailable(activity)) {
                Util.postTweetOffline(tweetBody, replyToTweetId);
                dismiss();
                Toast.makeText(activity, "Network unavailable :Tweet will be saved and posted later ",
                        Toast.LENGTH_LONG).show();

            } else {

                if (replyToTweetId != null) {
                    postReply(tweetBody, replyToTweetId);
                } else {
                    postTweet(tweetBody);
                }
            }

        }
    });

    tweetTextara.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            int availableChar = 0;
            String typedTweetText = tweetTextara.getEditableText().toString().trim();
            availableChar = CHARS_LIMIT - typedTweetText.length();
            String updatedRemainingChars = String.valueOf((CHARS_LIMIT - typedTweetText.length()));
            remainingChars.setText(updatedRemainingChars);
            if (availableChar < 0) {
                tweetIt.setEnabled(false);
                tweetIt.setBackgroundColor(getResources().getColor(R.color.TwitterBlue_disabled));
                remainingChars.setTextColor(getResources().getColor(R.color.Red));
            } else {
                tweetIt.setEnabled(true);
                tweetIt.setBackgroundColor(getResources().getColor(R.color.TwitterBlue));
                remainingChars.setTextColor(getResources().getColor(android.R.color.black));

            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:com.heske.alexandria.activities.AddBookFragment.java

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

    if (getArguments() != null) {
        String addBookText = getArguments().getString(KEY_ADD_BOOK_TEXT);
        if (!addBookText.isEmpty())
            etvEan.setText(addBookText);
    }// w  w  w .ja  v  a2s .co  m

    etvEan.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) {
            //Wait for user to initiate text entry.
            //Otherwise, on config change, a 13-digit number
            //might be left over and be seen as a duplicate book
            if (mIsInitState) {
                mIsInitState = false;
                return;
            }
            String ean = s.toString();
            //catch isbn10 numbers
            if (ean.length() == 10 && !ean.startsWith("978")) {
                ean = "978" + ean;
            }
            if (ean.length() < 13) {
                return;
            }
            addBook(ean);
        }
    });

    if (!Utils.isNetworkAvailable(getActivity())) {
        etvEan.setText(getString(R.string.error_no_network_short));
        etvEan.setEnabled(false);
        tv_no_network.setVisibility(View.VISIBLE);
    } else
        tv_no_network.setVisibility(View.GONE);
    return rootView;
}

From source file:com.halzhang.android.apps.startupnews.ui.tablet.DiscussFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);/*from w  ww.j av a 2 s  .  c o  m*/
    View view = inflater.inflate(R.layout.fragment_discuss, null);
    mListView = (ListView) view.findViewById(android.R.id.list);
    mListView.setOnItemClickListener(this);
    mSnDiscuss = new SNDiscuss();
    Bundle args = getArguments();
    SNNew snNew = null;
    if (args != null && args.containsKey(DiscussActivity.ARG_DISCUSS_URL)) {
        mDiscussURL = args.getString(DiscussActivity.ARG_DISCUSS_URL);
    } else {
        throw new IllegalArgumentException("Discuss URL is required!");
    }
    if (args.containsKey(DiscussActivity.ARG_SNNEW)) {
        snNew = (SNNew) args.getSerializable(DiscussActivity.ARG_SNNEW);
        mSnDiscuss.setSnNew(snNew);
    }
    mAdapter = new DiscussCommentAdapter();
    View headerView = inflater.inflate(R.layout.discuss_header_view, null);
    mTitle = (TextView) headerView.findViewById(R.id.discuss_news_title);
    mSubTitle = (TextView) headerView.findViewById(R.id.discuss_news_subtitle);
    mText = (TextView) headerView.findViewById(R.id.discuss_text);

    mSendBtn = (ImageButton) view.findViewById(R.id.discuss_comment_send_btn);
    mSendBtn.setEnabled(false);
    mSendBtn.setOnClickListener(mSendBtnClickListener);
    mCommentEdit = (EditText) view.findViewById(R.id.discuss_comment_edit);
    mCommentEdit.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) {
            mSendBtn.setEnabled(s.length() > 0);
        }
    });
    mListView.addHeaderView(headerView);
    mListView.setAdapter(mAdapter);
    wrapHeaderView(snNew);
    loadData();
    return view;
}

From source file:activities.SpecialityActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.service_list);
    lv = (ListView) findViewById(R.id.list_view);

    inputSearch = (EditText) findViewById(R.id.inputSearch);
    //adapter = new ArrayAdapter<String>(activity, R.layout.service_list_item, R.id.service_name,services);
    adapter = new SpecialityAdapter(this, R.layout.service_list_item, Arrays.asList(services));
    lv.setAdapter(adapter);//from w  w  w.j  a  v a  2  s .co m

    inputSearch.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) {
            adapter.getFilter().filter(s);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    ((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < specialities.size(); i++) {
                // Log.e("key", specialities+"");
                specialities_new = specialities;
                Log.e("key", specialities_new + "");
            }

            //                for(String speciality : specialities) {
            //                    //System.out.println(speciality);
            //                    Log.e("key", speciality);
            //                    key = speciality;
            //                    Log.e("keys", key+" ");
            //                }
            //                Intent returnIntent = new Intent();
            //                Bundle bundle = new Bundle();
            //                bundle.putSerializable("result", specialities_new);
            //               returnIntent.putExtra(bundle);
            //                setResult(1, returnIntent);

            Intent intent = new Intent();
            Bundle bundle1 = new Bundle();
            bundle1.putSerializable("passwords", specialities_new);
            intent.putExtras(bundle1);
            setResult(1, intent);
            finish();

        }
    });

}

From source file:com.blueshift.mvpremote.MVPremoteActivity.java

private void initHostNameBox() {
    HostNameBox = (EditText) findViewById(R.id.hostName);

    if (HostNameBox == null)
        return;/*www  . java2  s  . c o  m*/

    HostNameBox.setText(hostname);
    HostNameBox.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            hostname = HostNameBox.getText().toString();
            setAddr();
        }

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

        }

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