List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.hardcopy.retrowatchle.WatchControlFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_watch_control, container, false); mEditGmailAddr = (EditText) rootView.findViewById(R.id.edit_email_addr); String defaultAddr = Settings.getInstance(mContext).getGmailAddress(); if (defaultAddr != null && !defaultAddr.isEmpty()) mEditGmailAddr.setText(defaultAddr); mEditGmailAddr.addTextChangedListener(new TextWatcher() { @Override// w w w . j a v a 2 s . c o m public void onTextChanged(CharSequence s, int start, int before, int count) { String addr = s.toString(); if (addr != null && !addr.isEmpty()) { mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_SET_EMAIL_ADDRESS, 0, 0, addr, null, null); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); mSpinnerClockStyle = (Spinner) rootView.findViewById(R.id.spinner_clock_style); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.clock_style_array, R.layout.spinner_simple_item2); adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item); mSpinnerClockStyle.setPrompt(mContext.getString(R.string.clock_style_title)); mSpinnerClockStyle.setAdapter(adapter); mSpinnerClockStyle.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mPresetClockStyle > -1 && mPresetClockStyle != position) { mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_CLOCK_STYLE, position, 0, null, null, null); } mPresetClockStyle = position; } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); mSpinnerIndicator = (Spinner) rootView.findViewById(R.id.spinner_show_indicator); ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(mContext, R.array.clock_indicator_array, R.layout.spinner_simple_item2); adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item); mSpinnerIndicator.setPrompt(mContext.getString(R.string.clock_indicator_title)); mSpinnerIndicator.setAdapter(adapter2); mSpinnerIndicator.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mPresetIndicator > -1 && mPresetIndicator != position) { mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_SHOW_INDICATOR, position, 0, null, null, null); } mPresetIndicator = position; } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // 'Run in background' setting mCheckBackground = (CheckBox) rootView.findViewById(R.id.check_background_service); mCheckBackground.setChecked(Settings.getInstance(mContext).getRunInBackground()); mCheckBackground.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Settings.getInstance(mContext).setRunInBackground(isChecked); mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_RUN_IN_BACKGROUND, 0, 0, null, null, null); } }); return rootView; }
From source file:com.fbartnitzek.tasteemall.filter.AttributeFilterTextTabFragment.java
@Nullable @Override// www . j ava 2s. com public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mEditFilter = (EditText) mRootView.findViewById(R.id.attribute_filter); mEditFilter.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) { mAttributeFilter = s.toString(); // Log.v(LOG_TAG, "afterTextChanged, hashCode=" + this.hashCode() + ", " + "s = [" + s + "]"); getLoaderManager().restartLoader(ATTRIBUTE_VALUES_LOADER_ID, null, AttributeFilterTextTabFragment.this); } }); mEditFilter.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Log.v(LOG_TAG, "onEditorAction, hashCode=" + this.hashCode() + ", " + "v = [" + v + "], actionId = [" + actionId + "], event = [" + event + "]"); if (actionId == EditorInfo.IME_ACTION_SEARCH) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mEditFilter.getWindowToken(), 0); return true; } return false; } }); // focus editFilter - thx for: http://stackoverflow.com/a/26012003/5477716 mEditFilter.requestFocus(); InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); mValuesRecycler = (RecyclerView) mRootView.findViewById(R.id.attribute_filter_list); mValuesRecycler.setLayoutManager(new LinearLayoutManager(getContext())); mAttributeValuesAdapter = new AttributeValuesAdapter(this); mValuesRecycler.setAdapter(mAttributeValuesAdapter); return mRootView; }
From source file:com.jpventura.alexandria.AddBook.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_add_book, container, false); ean = (EditText) rootView.findViewById(R.id.ean); ean.addTextChangedListener(new TextWatcher() { @Override/* ww w. j a v a 2 s . co m*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { //no need } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //no need } @Override public void afterTextChanged(Editable s) { String ean = s.toString(); //catch isbn10 numbers if (ean.length() == 10 && !ean.startsWith("978")) { ean = "978" + ean; } if (ean.length() < 13) { clearFields(); return; } //Once we have an ISBN, start a book intent Intent bookIntent = new Intent(getActivity(), BookService.class); bookIntent.putExtra(BookService.EAN, ean); bookIntent.setAction(BookService.FETCH_BOOK); getActivity().startService(bookIntent); AddBook.this.restartLoader(); } }); rootView.findViewById(R.id.scan_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // This is the callback method that the system will invoke when your button is // clicked. You might do this by launching another app or by including the //functionality directly in this app. // Hint: Use a Try/Catch block to handle the Intent dispatch gracefully, if you // are using an external app. //when you're done, remove the toast below. Context context = getActivity(); CharSequence text = "This button should let you scan a book for its barcode!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } }); rootView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ean.setText(""); } }); rootView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent bookIntent = new Intent(getActivity(), BookService.class); bookIntent.putExtra(BookService.EAN, ean.getText().toString()); bookIntent.setAction(BookService.DELETE_BOOK); getActivity().startService(bookIntent); ean.setText(""); } }); if (savedInstanceState != null) { ean.setText(savedInstanceState.getString(EAN_CONTENT)); ean.setHint(""); } return rootView; }
From source file:com.gmail.at.faint545.activities.SpeedLimitActivity.java
private void initListeners() { valueEditText.addTextChangedListener(new TextWatcher() { @Override//w ww . j a v a2 s. co 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() < 1) ok.setEnabled(false); else ok.setEnabled(true); } }); ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String value = valueEditText.getText().toString(); new SpeedLimitTask(SpeedLimitActivity.this, target.buildURL(), target.getApiKey()).execute(value); } }); }
From source file:ch.fixme.status.Widget_config.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.widget_config); mPrefs = PreferenceManager.getDefaultSharedPreferences(Widget_config.this); getDirTask = new GetDirTask(); getDirTask.execute(ParseGeneric.API_DIRECTORY); Intent intent = getIntent();/* w ww .j av a 2s . c o m*/ Bundle extras = intent.getExtras(); mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); findViewById(R.id.choose_ok).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Editor edit = mPrefs.edit(); edit.putBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, ((CheckBox) findViewById(R.id.choose_transparency)).isChecked()); edit.commit(); setWidgetAlarm(); finish(); } }); ((CheckBox) findViewById(R.id.choose_transparency)) .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)); ((CheckBox) findViewById(R.id.choose_text)) .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TEXT, Prefs.DEFAULT_WIDGET_TEXT)); ((EditText) findViewById(R.id.choose_update)).addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String inter = s.toString(); if (!"".equals(inter) && !"0".equals(inter)) { Editor edit = mPrefs.edit(); edit.putString(Prefs.KEY_CHECK_INTERVAL, inter); edit.commit(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); }
From source file:alexander.martinz.sample.webserver.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); // enable debugging Config.DEBUG = true;/*from w w w. j a v a 2 s . co m*/ final CustomTabsHelper customTabsHelper = new CustomTabsHelper(getApplicationContext()); customTabsHelper.warmup(); tvIpAddress.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { customTabsHelper.launchUrl(MainActivity.this, buildUrl()); } }); tvIpAddress.setEnabled(false); etPort.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) { boolean valid; final String portString = ((s != null) ? s.toString() : null); if (TextUtils.isEmpty(portString)) { fabToggle.setEnabled(false); return; } try { final int port = Integer.parseInt(portString); valid = ((port <= 65535) && (port >= 1)); } catch (Exception exc) { valid = false; } fabToggle.setEnabled(valid); } }); etPort.setEnabled(true); fabToggle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (webServer == null) { final int port = Integer.parseInt(etPort.getText().toString()); webServer = new DefaultRouter(MainActivity.this, port); } if (webServer.isAlive()) { webServer.stop(); fabToggle.setImageResource(R.drawable.ic_portable_wifi_off_black_24dp); fabToggle.setBackgroundTintList( ContextCompat.getColorStateList(MainActivity.this, R.color.button_off)); tvIpAddress.setTextColor(Color.WHITE); tvIpAddress.setEnabled(false); etPort.setTextColor(Color.WHITE); etPort.setEnabled(true); } else { try { webServer.start(); } catch (IOException ioe) { Log.e(TAG, "Could not start web server!", ioe); return; } fabToggle.setImageResource(R.drawable.ic_wifi_tethering_black_24dp); fabToggle.setBackgroundTintList( ContextCompat.getColorStateList(MainActivity.this, R.color.button_on)); final int color = ContextCompat.getColor(MainActivity.this, R.color.button_on); tvIpAddress.setTextColor(color); tvIpAddress.setEnabled(true); etPort.setTextColor(color); etPort.setEnabled(false); customTabsHelper.mayLaunchUrl(buildUrl()); } } }); }
From source file:com.nononsenseapps.filepicker.ui.NewItemFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setTitle(getDialogTitle()); final View view = inflater.inflate(R.layout.dialog_new_item, container, false); okButton = view.findViewById(R.id.button_ok); okButton.setOnClickListener(new View.OnClickListener() { @Override/*w w w . j ava 2 s .co m*/ public void onClick(final View v) { if (listener != null) { listener.onNewFolder(itemName); } dismiss(); } }); view.findViewById(R.id.button_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { dismiss(); } }); final EditText editText = (EditText) view.findViewById(R.id.edit_text); if (itemName == null) { okButton.setEnabled(false); } else { editText.setText(itemName); validateItemName(); } 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) { itemName = s.toString(); validateItemName(); } }); return view; }
From source file:net.mceoin.cominghome.oauth.OAuthFlowApp.java
@SuppressLint("SetJavaScriptEnabled") @Override// w w w. ja v a 2 s. co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.oauth); this.prefs = PreferenceManager.getDefaultSharedPreferences(this); EditText editPincode = (EditText) findViewById(R.id.editPincode); editPincode.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { Button usePincode = (Button) findViewById(R.id.btn_use_pincode); if (s.length() == 8) { usePincode.setEnabled(true); } else { usePincode.setEnabled(false); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); editPincode.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { if (v.length() == 8) { usePincode(); return true; } } return false; } }); Button usePincode = (Button) findViewById(R.id.btn_use_pincode); usePincode.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { usePincode(); } }); WebView webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(false); try { webView.loadUrl(Constants.AUTHORIZE_URL); } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show(); } }
From source file:com.battlelancer.seriesguide.ui.CheckinActivity.java
@Override protected void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); setContentView(R.layout.checkin);//from www . jav a 2 s . c o m setupNavDrawer(); setupActionBar(); // setup search box mSearchBox = (EditText) findViewById(R.id.editTextCheckinSearch); mSearchBox.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mSearchFilter = !TextUtils.isEmpty(s) ? s.toString() : null; getSupportLoaderManager().restartLoader(LOADER_ID, null, CheckinActivity.this); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); // setup clear button findViewById(R.id.imageButtonClearSearch).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mSearchBox.setText(null); mSearchBox.requestFocus(); } }); mSearchBox.requestFocus(); // setup adapter mAdapter = new CheckinAdapter(this, null, 0); // setup grid view GridView list = (GridView) findViewById(android.R.id.list); list.setAdapter(mAdapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Cursor show = (Cursor) mAdapter.getItem(position); int episodeTvdbId = show.getInt(CheckinQuery.NEXTEPISODE); if (episodeTvdbId <= 0) { return; } // display a check-in dialog CheckInDialogFragment f = CheckInDialogFragment.newInstance(CheckinActivity.this, episodeTvdbId); f.show(getSupportFragmentManager(), "checkin-dialog"); } }); list.setEmptyView(findViewById(R.id.empty)); getSupportLoaderManager().initLoader(LOADER_ID, null, this); }
From source file:com.groupme.sdk.activity.GroupCreateActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_groupcreate); GroupMeConnect connect = GroupMeConnect.getInstance(this); if (!connect.hasValidSession()) { /* fire off the authentication activity. */ startActivityForResult(new Intent(this, AuthorizeActivity.class), AuthorizeActivity.REQUEST_LOGIN); }/* w ww.j a v a 2s. c om*/ mCreateButton = (Button) findViewById(R.id.btn_create_group_alt); mCreateButton.setEnabled(false); mGroupNameEntry = (EditText) findViewById(R.id.group_name_entry); mGroupNameEntry.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence str, int start, int before, int count) { if (!TextUtils.isEmpty(mGroupNameEntry.getText().toString())) { if (mContacts != null && mContacts.size() != 0) { mCreateButton.setEnabled(true); } else { mCreateButton.setEnabled(false); } } else { mCreateButton.setEnabled(false); } } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence str, int start, int before, int count) { } }); getListView().setBackgroundColor(Color.TRANSPARENT); getListView().setCacheColorHint(Color.TRANSPARENT); }