List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.ichi2.anki.CramDeckFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // Currently in a layout without a container, so no // reason to create our view. return null; }//from w w w .ja v a 2s.c om mFragmented = getActivity().getClass() != CramDeckActivity.class; View main = inflater.inflate(R.layout.cram_deck, null); mCramDeckName = (EditText) main.findViewById(R.id.cram_deck_name); mCramDeckName.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { if (mCramDeckName.getText().length() == 0) { mCreateButton.setEnabled(false); } else { mCreateButton.setEnabled(true); } } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); mDecks = (LinearLayout) main.findViewById(R.id.cram_deck_decks_button); mDeckLabel = (TextView) main.findViewById(R.id.cram_deck_decks_text); mDecks.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDecksDialog(); } }); mSteps = (EditText) main.findViewById(R.id.cram_deck_steps); // mOrder mLimit = (EditText) main.findViewById(R.id.cram_deck_limit); mInterval = (EditText) main.findViewById(R.id.cram_deck_interval); mCreateButton = (Button) main.findViewById(R.id.cram_deck_create); mCreateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { mDeck.put("steps", DeckOptions.getDelays(mSteps.getText().toString())); // mDeck.put("search", ) // mDeck.put("order", value); mDeck.put("limit", Integer.parseInt(mLimit.getText().toString())); mDeck.put("fmult", Integer.parseInt(mLimit.getText().toString()) / 100.0); } catch (JSONException e) { throw new RuntimeException(e); } closeCramDeckAdder(); } }); mCancelButton = (Button) main.findViewById(R.id.cram_deck_cancel); mCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { closeCramDeckAdder(); } }); mCol = Collection.currentCollection(); if (mCol == null) { return null; } mDeck = mCol.getDecks().current(); try { if (mDeck.getInt("dyn") == 0) { String currentDeckName = mDeck.getString("name"); ArrayList<String> names = mCol.getDecks().allNames(); int n = 1; String cramDeckName = "Cram 1"; while (names.contains(cramDeckName)) { n++; cramDeckName = "Cram " + n; } mCol.getDecks().newDyn(cramDeckName); mDeck = mCol.getDecks().current(); mDeck.put("search", "\'deck:" + currentDeckName + "\'"); } mCramDeckName.setText(mDeck.getString("name")); mDeckLabel.setText(mDeck.getString("search")); mSteps.setText(DeckOptions.getDelays(mDeck.getJSONArray("delays"))); // TODO: set mOrder mLimit.setText(Integer.toString(mDeck.getInt("limit"))); mInterval.setText(Integer.toString((int) (mDeck.getDouble("fmult") * 100))); } catch (JSONException e) { throw new RuntimeException(e); } if (!mFragmented) { main.setBackgroundResource(R.drawable.white_wallpaper); } Themes.showThemedToast(this.getActivity(), "not yet implemented", false); return main; }
From source file:com.example.Bama.chat.chatuidemo.activity.ContactlistFragment.java
private void initViewsAndListener(View view, Bundle savedInstanceState) { //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/*from w ww .j a v a 2 s. c o m*/ inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) view.findViewById(R.id.list); sidebar = (Sidebar) view.findViewById(R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) view.findViewById(R.id.query); query.setHint(R.string.search); clearSearch = (ImageButton) view.findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().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(); } }); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.ADD_FRIEND.equals(username)) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } else if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = HCApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else if (Constant.CHAT_ROOM.equals(username)) { //?? startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class)); } else { // demo?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); registerForContextMenu(listView); }
From source file:fr.cph.chicago.fragment.BusFragment.java
private final void addView() { mAdapter = new BusAdapter(mActivity); mListView.setAdapter(mAdapter);/*from w ww.java 2 s . c o m*/ mTextFilter.setVisibility(TextView.VISIBLE); mTextFilter.addTextChangedListener(new TextWatcher() { private BusData busData = DataHolder.getInstance().getBusData(); private List<BusRoute> busRoutes = null; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { busRoutes = new ArrayList<BusRoute>(); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { List<BusRoute> busRoutes = busData.getRoutes(); for (BusRoute busRoute : busRoutes) { if (StringUtils.containsIgnoreCase(busRoute.getId(), s.toString().trim()) || StringUtils.containsIgnoreCase(busRoute.getName(), s.toString().trim())) { this.busRoutes.add(busRoute); } } } @Override public void afterTextChanged(Editable s) { mAdapter.setRoutes(busRoutes); mAdapter.notifyDataSetChanged(); } }); }
From source file:color.kidpaint.com.kidpaintcolor.dialog.FillToolDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = getActivity().getLayoutInflater(); AlertDialog.Builder builder = new CustomAlertDialogBuilder(mContext); builder.setTitle(R.string.fill_tool_dialog_title); final View view = inflater.inflate(R.layout.dialog_fill_tool, null); mColorToleranceSeekBar = (SeekBar) view.findViewById(R.id.color_tolerance_seek_bar); mColorToleranceSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override//w w w . j a v a 2 s . co m public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mColorTolerance = progress; updateColorToleranceText(mColorTolerance); mColorToleranceEditText.setCursorVisible(false); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mColorToleranceEditText = (EditText) view.findViewById(R.id.fill_tool_dialog_color_tolerance_input); mColorToleranceEditText.setCursorVisible(false); mColorToleranceEditText.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) { try { mColorTolerance = Integer.parseInt(s.toString()); if (mColorTolerance > 100) { mColorTolerance = 100; updateColorToleranceText(mColorTolerance); } mColorToleranceSeekBar.setProgress(mColorTolerance); mOnFillToolDialogChangedListener.updateColorTolerance(mColorTolerance); } catch (NumberFormatException e) { Log.e("Error parsing tolerance", "result was null"); } } }); mColorToleranceEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.fill_tool_dialog_color_tolerance_input) { mColorToleranceEditText.setCursorVisible(true); } } }); builder.setView(view); builder.setNeutralButton(R.string.done, this); return builder.create(); }
From source file:com.easemob.qixin.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/*from w ww . jav a2 s.c o m*/ inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(R.id.list); sidebar = (Sidebar) getView().findViewById(R.id.sidebar); sidebar.setListView(listView); View huanxinView = getView().findViewById(R.id.huanxin_contact_list); View groupView = getView().findViewById(R.id.group_contact_list); huanxinView.setOnClickListener(this); groupView.setOnClickListener(this); // ? query = (EditText) getView().findViewById(R.id.query); query.setHint(R.string.search); clearSearch = (ImageButton) getView().findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().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(); } }); list = new ArrayList<QXUser>(); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, loadConversationsWithRecentChat()); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { startActivity(new Intent(getActivity(), PersonalInfoActivity.class).putExtra("userId", adapter.getItem(position).getHXid())); } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); registerForContextMenu(listView); }
From source file:com.insthub.O2OMobile.Activity.C15_EditPriceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.c15_edit_price); mMyService = (MY_SERVICE) getIntent().getSerializableExtra(SERVICE); nTitle = (TextView) findViewById(R.id.top_view_title); nTitle.setText(getString(R.string.modify_service)); mBack = (ImageView) findViewById(R.id.top_view_back); mType = (TextView) findViewById(R.id.service_type); mPrice = (EditText) findViewById(R.id.price); mSave = (Button) findViewById(R.id.save); if (mMyService != null) { mType.setText(mMyService.service_type.title); mPrice.setText(mMyService.price); mPrice.setSelection(mMyService.price.length()); }/* ww w . jav a 2 s .c om*/ mServiceModel = new ServiceModel(this); mServiceModel.addResponseListener(this); mSave.setOnClickListener(this); mBack.setOnClickListener(this); mPrice.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (s.toString().length() > 0) { if (s.toString().substring(0, 1).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); } } if (s.toString().length() > 1) { if (s.toString().substring(0, 1).equals("0")) { if (!s.toString().substring(1, 2).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } boolean flag = false; for (int i = 0; i < s.toString().length() - 1; i++) { String getstr = s.toString().substring(i, i + 1); if (getstr.equals(".")) { flag = true; break; } } if (flag) { int i = s.toString().indexOf("."); if (s.toString().length() - 3 > i) { String getstr = s.toString().substring(0, i + 3); mPrice.setText(getstr); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } @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.activiti.android.app.fragments.account.ServerFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final LinearLayout backField = (LinearLayout) viewById(R.id.account_action_server_container); final Button actionContinue = (Button) viewById(R.id.account_action_server); actionContinue.setOnClickListener(new View.OnClickListener() { @Override// w w w . j av a 2 s .c om public void onClick(View v) { String value = createHostnameURL(hostname.getText().toString(), https.isChecked()); if (value == null) { hostname.setError("Your hostname seems invalid"); } else { // TODO Heartbeat SignInFragment.with(getActivity()).hostname(hostname.getText().toString()) .https(https.isChecked()).display(); } } }); https = (CheckBox) viewById(R.id.signing_https); hostname = (MaterialEditText) viewById(R.id.signing_hostname); hostname.requestFocus(); UIUtils.showKeyboard(getActivity(), hostname); if (hostname.getText().length() == 0) { actionContinue.setEnabled(false); backField.setBackgroundColor(getResources().getColor(R.color.accent_disable)); } hostname.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 (s.length() == 0) { actionContinue.setEnabled(false); backField.setBackgroundColor(getResources().getColor(R.color.accent_disable)); } else { actionContinue.setEnabled(true); backField.setBackgroundColor(getResources().getColor(R.color.accent)); } } }); }
From source file:com.money.manager.ex.assetallocation.AssetClassEditFragment.java
private void initializeNameEdit(View view) { final EditText edit = (EditText) view.findViewById(R.id.nameEdit); if (edit == null) return;/*from w ww .j a va 2 s . co m*/ edit.setText(assetClass.getName()); edit.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) { // edit.getText().toString() String newValue = s.toString(); assetClass.setName(newValue); } }); }
From source file:cn.kangeqiu.kq.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;//from w ww.j a v a 2 s .c o m inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(R.id.list); sidebar = (Sidebar) getView().findViewById(R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(R.id.query); String strSearch = getResources().getString(R.string.search); query.setHint(strSearch); clearSearch = (ImageButton) getView().findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().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(); } }); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = BaseApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else { // demo?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); }
From source file:com.nextgis.maplibui.fragment.LayerGeneralSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_layer_general, container, false); TextView path = (TextView) v.findViewById(R.id.layer_local_lath); path.setText(String.format(getString(R.string.layer_local_path), mLayer.getPath())); TextView remote = (TextView) v.findViewById(R.id.layer_remote_path); String remoteUrl = null;//from www . j a va 2 s.c om if (mLayer instanceof NGWVectorLayer) remoteUrl = ((NGWVectorLayer) mLayer).getRemoteUrl(); if (mLayer instanceof RemoteTMSLayer) remoteUrl = ((RemoteTMSLayer) mLayer).getURL(); if (remoteUrl != null) { remote.setText(String.format(getString(R.string.layer_remote_path), remoteUrl)); remote.setVisibility(View.VISIBLE); } mEditText = (EditText) v.findViewById(R.id.layer_name); mEditText.setText(mLayer.getName()); mEditText.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) { mActivity.setTitle(s.toString()); mActivity.mLayerName = s.toString(); } }); // Gets the index value TextViews final TextView leftIndexValue = (TextView) v.findViewById(R.id.leftIndexValue); final TextView rightIndexValue = (TextView) v.findViewById(R.id.rightIndexValue); // Gets the RangeBar and set range mRangeBar = (RangeBar) v.findViewById(R.id.rangebar); int nMinZoom = mActivity.mLayerMinZoom < mRangeBar.getRightIndex() ? (int) mActivity.mLayerMinZoom : mRangeBar.getRightIndex(); int nMaxZoom = mActivity.mLayerMaxZoom < mRangeBar.getRightIndex() ? (int) mActivity.mLayerMaxZoom : mRangeBar.getRightIndex(); mRangeBar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() { @Override public void onIndexChangeListener(RangeBar rangeBar, int leftThumbIndex, int rightThumbIndex) { mActivity.mLayerMinZoom = leftThumbIndex; mActivity.mLayerMaxZoom = rightThumbIndex; ControlHelper.setZoomText(getActivity(), leftIndexValue, R.string.min, leftThumbIndex); ControlHelper.setZoomText(getActivity(), rightIndexValue, R.string.max, rightThumbIndex); } }); mRangeBar.setThumbIndices(nMinZoom, nMaxZoom); if (mLayer instanceof VectorLayer) { final VectorLayer vectorLayer = (VectorLayer) mLayer; Button deleteFeatures = (Button) v.findViewById(R.id.delete_features); deleteFeatures.setVisibility(View.VISIBLE); deleteFeatures.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.are_you_sure) .setMessage(R.string.delete_features).setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new DeleteFeaturesTask().execute(vectorLayer); } }).create(); builder.show(); } }); } return v; }