List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.grarak.kerneladiutor.fragments.tools.customcontrols.CreateFragment.java
@Override protected void addItems(List<RecyclerViewItem> items) { mEditTextViews.clear();//from w w w .j av a 2 s . c o m mCodeViews.clear(); for (final Items.Setting setting : mSettings) { if (setting.isScript()) { final CodeView codeView = new CodeView(); codeView.setTitle(setting.getName(getActivity())); codeView.setSummary(setting.getDescription(getActivity())); codeView.setRequired(setting.isRequired()); codeView.setCode(setting.getDefault()); codeView.setTesting(setting.getUnit() != Items.Setting.Unit.APPLY); codeView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() { @Override public void onClick(RecyclerViewItem item) { Intent intent = new Intent(getActivity(), EditorActivity.class); intent.putExtra(EditorActivity.TITLE_INTENT, setting.getName(getActivity()).toString()); intent.putExtra(EditorActivity.TEXT_INTENT, codeView.getCode()); startActivityForResult(intent, mSettings.indexOf(setting)); } }); codeView.setOnTestListener(new CodeView.OnTestListener() { @Override public void onTestResult(CodeView codeView, String output) { showFab(); } }); items.add(codeView); mCodeViews.put(setting, codeView); } else if (setting.getUnit() != Items.Setting.Unit.ID) { EditTextView editTextView = new EditTextView(); editTextView.setTitle(setting.getName(getActivity())); if (setting.isRequired()) { editTextView.setHint(getString(R.string.required)); } if (setting.getUnit() == Items.Setting.Unit.INTEGER) { editTextView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); } editTextView.setText(setting.getDefault()); editTextView.setTextWatcher(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) { showFab(); } }); items.add(editTextView); mEditTextViews.put(setting, editTextView); } } }
From source file:com.barak.pix.CommentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_comments, container, false); RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list); mEditText = (EditText) rootView.findViewById(R.id.editText); final Button sendButton = (Button) rootView.findViewById(R.id.send_comment); final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef); mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item, CommentViewHolder.class, commentsRef) { @Override// w ww . j av a2 s .co m protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Author author = comment.getAuthor(); viewHolder.commentAuthor.setText(author.getFull_name()); GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto); 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.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.collabora.xwperf.notxw_contacts.fragments.DetailsFragment.java
@AfterViews void init() {/* www. j a v a 2 s . c o m*/ getLoaderManager().initLoader(contactId, null, contactDetailsLoader); nameEdit.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) { setTitle(s.toString()); } }); }
From source file:com.brettyin.cardshelper.fragment.SignInFragment.java
private void initContentViews(View view) { TextWatcher textWatcher = new TextWatcher() { @Override/*from w w w . j ava2 s . c o m*/ 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.setVisibility(View.GONE); } else { mDoneFab.setVisibility(View.VISIBLE); } } @Override public void afterTextChanged(Editable s) { /* no-op */ } }; mFirstName = (EditText) view.findViewById(R.id.first_name); mFirstName.addTextChangedListener(textWatcher); mLastInitial = (EditText) view.findViewById(R.id.last_initial); mLastInitial.addTextChangedListener(textWatcher); mDoneFab = (DoneFab) view.findViewById(R.id.done); mDoneFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.done: savePlayer(getActivity()); removeDoneFab(new Runnable() { @Override public void run() { if (null == mSelectedAvatarView) { performSignInWithTransition(mAvatarGrid.getChildAt(mSelectedAvatar.ordinal())); } else { performSignInWithTransition(mSelectedAvatarView); } } }); playerActivity.finish(); break; default: throw new UnsupportedOperationException("The onClick method has not been implemented for " + getResources().getResourceEntryName(v.getId())); } } }); }
From source file:com.joncairo.android.todo.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // set up the main activity view to be populated with fragments. setContentView(R.layout.activity_main); // Set up the action bar for tabs final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter to manage tab switching mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//from www .j av a 2 s .c o m public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } // Wire up the to do text entry field mNewToDoName = (EditText) findViewById(R.id.todo_text); mNewToDoName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { DataLoader dataLoader = new DataLoader(getBaseContext(), mDataFileName); dataLoader.setTextInputData(s.toString()); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); // Wire up the to do enter button Button mDoIt = (Button) findViewById(R.id.enter_button); mDoIt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ArrayList<Todo> mToDoToBeAdded = new ArrayList<Todo>(); String newToDoText = setInputText(); // Create a new todo instance Todo newTodo = new Todo(newToDoText); mToDoToBeAdded.add(newTodo); // delete the text //mNewToDoName.setText(""); // append it to the todolist array mtoDoFragment.addItemsToList(mToDoToBeAdded, ""); } }); }
From source file:net.olejon.mdapp.MedicationActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Intent// w ww . j ava 2 s . c om final Intent intent = getIntent(); medicationId = intent.getLongExtra("id", 0); if (medicationId == 0) { mTools.showToast(getString(R.string.medication_could_not_find_medication), 1); finish(); return; } // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout setContentView(R.layout.activity_medication); // View mRelativeLayout = (RelativeLayout) findViewById(R.id.medication_inner_layout); // Toolbar mToolbar = (Toolbar) findViewById(R.id.medication_toolbar); mToolbar.setTitle(""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.medication_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.medication_toolbar_search); // View pager mViewPager = (ViewPager) findViewById(R.id.medication_pager); // Find in text mToolbarSearchEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { String find = mToolbarSearchEditText.getText().toString().trim(); if (find.equals("")) { if (mWebView != null) mWebView.clearMatches(); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (mWebView != null) mWebView.findAllAsync(find); } else { if (mWebView != null) { //noinspection deprecation mWebView.findAll(find); } } } } @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { } }); mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); return true; } return false; } }); }
From source file:com.learnit.LearnIt.activities.EditWord.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); removeActionBarLabelIfNeeded();/*from w ww . ja v a2s . co m*/ dbHelper = FactoryDbHelper.createDbHelper(this, DBHelper.DB_WORDS); utils = new Utils(); oldWord = getIntent().getStringExtra(WORD_TAG); String translation = dbHelper.getTranslation(oldWord); Log.d(LOG_TAG, "got word to edit = " + oldWord + ", trans = " + translation); setContentView(R.layout.edit_word); edtWord = (EditText) findViewById(R.id.edtWord); edtTrans = (EditText) findViewById(R.id.edtTrans); edtWord.setText(oldWord); edtTrans.setText(translation); btnClearWord = (ImageButton) findViewById(R.id.btn_add_word_clear); btnClearTrans = (ImageButton) findViewById(R.id.btn_add_trans_clear); MyBtnTouchListener myBtnTouchListener = new MyBtnTouchListener(); btnClearTrans.setOnClickListener(myBtnTouchListener); btnClearWord.setOnClickListener(myBtnTouchListener); edtWord.addTextChangedListener(new TextWatcher() { @Override 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 (editable.toString() != null && !editable.toString().equals("")) { btnClearWord.setVisibility(View.VISIBLE); } if (editable.length() == 0) { btnClearWord.setVisibility(View.INVISIBLE); } } }); edtTrans.addTextChangedListener(new TextWatcher() { @Override 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 (editable.toString() != null && !editable.toString().equals("")) { btnClearTrans.setVisibility(View.VISIBLE); } if (editable.length() == 0) { btnClearTrans.setVisibility(View.INVISIBLE); } } }); }
From source file:com.example.parking.InputLicenseActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDBAdapter = new DBAdapter(this); Intent intent = getIntent();//from ww w . ja v a 2 s . c om Bundle bundle = intent.getExtras(); if (bundle.getInt("type") == ARRIVING_TYPE) { mType = ARRIVING_TYPE; } else if (bundle.getInt("type") == LEAVING_TYPE) { mType = LEAVING_TYPE; } setContentView(R.layout.activity_input_license); mLicensePlateET = (EditText) findViewById(R.id.et_license_plate); mLetterTV = (TextView) findViewById(R.id.tv_letter); mNumberTV = (TextView) findViewById(R.id.tv_number); mLocationTV = (TextView) findViewById(R.id.tv_location); mScanBT = (Button) findViewById(R.id.bt_scan); mNextBT = (Button) findViewById(R.id.bt_next); mLetterTV.setOnClickListener(mTabClickListener); mNumberTV.setOnClickListener(mTabClickListener); mLocationTV.setOnClickListener(mTabClickListener); changeSelect(R.id.tv_location); changeFragment(R.id.tv_location); mLicensePlateET.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // et.getCompoundDrawables()4? Drawable drawable = mLicensePlateET.getCompoundDrawables()[2]; //???? if (drawable == null) return false; //???? if (event.getAction() != MotionEvent.ACTION_UP) return false; if (event.getX() > mLicensePlateET.getWidth() - mLicensePlateET.getPaddingRight() - drawable.getIntrinsicWidth()) { mLicensePlateET.setText(""); } return false; } }); mScanBT.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Message msg = new Message(); msg.what = EVENT_SCAN_STATE_NOTIFY; mHandler.sendMessage(msg); } }); mLicensePlateET.setInputType(InputType.TYPE_NULL); mLicensePlateET.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 (mLicensePlateET.getText() != null && mLicensePlateET.getText().length() > LICENSE_PLATE_NUMBER_SIZE) { Message msg = new Message(); msg.what = EVENT_INVALID_LICENSE_PLATE; mHandler.sendMessage(msg); } } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); mNextBT.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { if (mLicensePlateET.getText().length() != LICENSE_PLATE_NUMBER_SIZE) { Message msg = new Message(); msg.what = EVENT_INVALID_LICENSE_PLATE; mHandler.sendMessage(msg); return; } new SQLThread().start(); } }); getActionBar().setDisplayHomeAsUpEnabled(true); IntentFilter filter = new IntentFilter(); filter.addAction("ExitApp"); filter.addAction("BackMain"); registerReceiver(mReceiver, filter); }
From source file:com.hyphenate.easeui.ui.EaseContactListFragment.java
@Override protected void setUpView() { EMClient.getInstance().addConnectionListener(connectionListener); contactList = new ArrayList<EaseUser>(); getContactList();// w w w . j a v a 2 s. co m //init list contactListLayout.init(contactList, EaseInitBean.map); if (listItemClickListener != null) { listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EaseUser user = (EaseUser) listView.getItemAtPosition(position); listItemClickListener.onListItemClicked(user); } }); } query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { contactListLayout.filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); hideSoftKeyboard(); } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { hideSoftKeyboard(); return false; } }); }
From source file:com.irccloud.android.activity.PastebinEditorActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC));/*from ww w . java 2 s.co m*/ cloud.recycle(); } setContentView(R.layout.activity_pastebineditor); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { if (!getWindow().isFloating()) { getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } paste = (EditText) findViewById(R.id.paste); filename = (EditText) findViewById(R.id.filename); message = (EditText) findViewById(R.id.message); messages_count = (TextView) findViewById(R.id.messages_count); if (savedInstanceState != null && savedInstanceState.containsKey("message")) message.setText(savedInstanceState.getString("message")); if (savedInstanceState != null && savedInstanceState.containsKey("paste_id")) pasteID = savedInstanceState.getString("paste_id"); else if (getIntent() != null && getIntent().hasExtra("paste_id")) pasteID = getIntent().getStringExtra("paste_id"); if (savedInstanceState != null && savedInstanceState.containsKey("paste_contents")) pastecontents = savedInstanceState.getString("paste_contents"); else if (getIntent() != null && getIntent().hasExtra("paste_contents")) pastecontents = getIntent().getStringExtra("paste_contents"); paste.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) { int count = 0; String lines[] = editable.toString().split("\n"); for (String line : lines) { count += Math.ceil(line.length() / 1080.0f); } messages_count.setText("Text will be sent as " + count + " message" + (count == 1 ? "" : "s")); } }); paste.setText(pastecontents); if (savedInstanceState != null && savedInstanceState.containsKey("filename")) filename.setText(savedInstanceState.getString("filename")); else if (getIntent() != null && getIntent().hasExtra("filename")) filename.setText(getIntent().getStringExtra("filename")); tabHost = (TabLayout) findViewById(android.R.id.tabhost); ViewCompat.setElevation(toolbar, ViewCompat.getElevation(tabHost)); if (pasteID != null) { tabHost.setVisibility(View.GONE); message.setVisibility(View.GONE); findViewById(R.id.message_heading).setVisibility(View.GONE); } else { tabHost.setTabGravity(TabLayout.GRAVITY_FILL); tabHost.setTabMode(TabLayout.MODE_FIXED); tabHost.addTab(tabHost.newTab().setText("Pastebin")); tabHost.addTab(tabHost.newTab().setText("Messages")); tabHost.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { current_tab = tab.getPosition(); if (current_tab == 0) { filename.setVisibility(View.VISIBLE); message.setVisibility(View.VISIBLE); messages_count.setVisibility(View.GONE); findViewById(R.id.filename_heading).setVisibility(View.VISIBLE); findViewById(R.id.message_heading).setVisibility(View.VISIBLE); } else { filename.setVisibility(View.GONE); message.setVisibility(View.GONE); messages_count.setVisibility(View.VISIBLE); findViewById(R.id.filename_heading).setVisibility(View.GONE); findViewById(R.id.message_heading).setVisibility(View.GONE); } } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); if (savedInstanceState != null && savedInstanceState.containsKey("tab")) tabHost.getTabAt(savedInstanceState.getInt("tab")).select(); } NetworkConnection.getInstance().addHandler(this); if (pasteID != null && (pastecontents == null || pastecontents.length() == 0)) { new FetchPastebinTask().execute((Void) null); } if (pasteID != null) { setTitle(R.string.title_activity_pastebin_editor_edit); toolbar.setBackgroundResource(R.drawable.actionbar); } else { setTitle(R.string.title_activity_pastebin_editor); } supportInvalidateOptionsMenu(); result(RESULT_CANCELED); }