List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.example.cuisoap.agrimac.homePage.machineDetail.machineInfoFragment.java
public void addTextWatcher() { machine_name.addTextChangedListener(new TextWatcher() { @Override/*from w ww . jav a 2 s .c om*/ 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) { machineDetailData.machine_name = s.toString(); } }); passenger_num.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) { machineDetailData.machine_maxpassenger = s.toString(); } }); power.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) { machineDetailData.machine_power = s.toString(); } }); wheel_distance.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) { machineDetailData.machine_wheeldistance = s.toString(); } }); check_time.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) { machineDetailData.machine_checktime = s.toString(); } }); }
From source file:com.mastercard.masterpasswallet.fragments.addcard.VerifyCardFragment.java
private void setupWidgetFormats() { // format the expiry date to mm/yy mEdtExpiry.addTextChangedListener(new TextWatcher() { @Override//w w w . j a va 2s. c o m public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String text = s.toString(); int selection = mEdtExpiry.getSelectionStart(); String pattern = "[0-9][0-9]\\/[0-9][0-9]"; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(text); if (!m.find()) { // if they have typed the second character if (text.length() == 2 && before == 0) { mEdtExpiry.setText(text + "/"); selection++; } else { // remove anything that isn't a number String cleanText = text.replaceAll("[^0-9.]", ""); // if the / will be added we need to increase the cursor position by 1 if (!text.contains("/")) { selection++; } if (text.length() > 2) { // format the starting numbers text = cleanText.substring(0, 2) + "/" + cleanText.substring(2); } // make sure we only set the text if there are changes (otherwise we infinite loop) if (!text.equals(s.toString())) { // set the text mEdtExpiry.setText(text); } } } // don't allow the date to be greater than 5 characters (including the /) if (text.length() > 5) { mEdtExpiry.setText(text.substring(0, 5)); } // make sure the cursor isn't moved out of bounds if (selection > mEdtExpiry.getText().length()) { selection = mEdtExpiry.getText().length(); } // move the cursor back to where it was mEdtExpiry.setSelection(selection); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:cn.ucai.foraging.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/*from www . ja v a 2s .com*/ inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(cn.ucai.foraging.R.id.list); sidebar = (Sidebar) getView().findViewById(cn.ucai.foraging.R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(cn.ucai.foraging.R.id.query); query.setHint(cn.ucai.foraging.R.string.search); clearSearch = (ImageButton) getView().findViewById(cn.ucai.foraging.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(), cn.ucai.foraging.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 = ((DemoHXSDKHelper) HXSDKHelper.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 if (Constant.CHAT_ROBOT.equals(username)) { //Robot? startActivity(new Intent(getActivity(), RobotsActivity.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(cn.ucai.foraging.R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); progressBar = (View) getView().findViewById(cn.ucai.foraging.R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:com.todoroo.astrid.notes.EditNoteActivity.java
private void setUpInterface() { timerView = commentsBar.findViewById(R.id.timer_container); commentButton = commentsBar.findViewById(R.id.commentButton); commentField = (EditText) commentsBar.findViewById(R.id.commentField); final boolean showTimerShortcut = preferences.getBoolean(R.string.p_show_timer_shortcut, false); if (showTimerShortcut) { commentField.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/*from w w w .j a v a 2 s.co m*/ public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { timerView.setVisibility(View.GONE); commentButton.setVisibility(View.VISIBLE); } else { timerView.setVisibility(View.VISIBLE); commentButton.setVisibility(View.GONE); } } }); } commentField.setHorizontallyScrolling(false); commentField.setMaxLines(Integer.MAX_VALUE); commentField.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { AndroidUtilities.hideSoftInputForViews(activity, commentField); return true; } return false; } }); commentField.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { commentField.setCursorVisible(true); } }); commentField.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { commentButton.setVisibility( (s.length() > 0 || pendingCommentPicture != null) ? View.VISIBLE : View.GONE); if (showTimerShortcut) { timerView.setVisibility( (s.length() > 0 || pendingCommentPicture != null) ? View.GONE : View.VISIBLE); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // } }); commentField.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (commentField.getText().length() > 0) { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) { // commentField.setCursorVisible(false); addComment(); } } return false; } }); commentButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { addComment(); } }); final ClearImageCallback clearImage = new ClearImageCallback() { @Override public void clearImage() { pendingCommentPicture = null; pictureButton.setImageResource(cameraButton); } }; pictureButton = (ImageButton) commentsBar.findViewById(R.id.picture); pictureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (pendingCommentPicture != null) { actFmCameraModule.showPictureLauncher(clearImage); } else { actFmCameraModule.showPictureLauncher(null); } respondToPicture = true; } }); if (!TextUtils.isEmpty(task.getNotes())) { TextView notes = new TextView(getContext()); notes.setLinkTextColor(Color.rgb(100, 160, 255)); notes.setTextSize(18); notes.setText(task.getNotes()); notes.setPadding(5, 10, 5, 10); Linkify.addLinks(notes, Linkify.ALL); } if (activity != null) { String uri = activity.getIntent().getStringExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS); if (uri != null) { pendingCommentPicture = Uri.parse(uri); setPictureButtonToPendingPicture(); } } }
From source file:com.mg.axe.androiddevelop.view.SearchViewLayout.java
@Override protected void onFinishInflate() { mCollapsed = (ViewGroup) findViewById(R.id.search_box_collapsed); mSearchIcon = findViewById(R.id.search_magnifying_glass); mCollapsedSearchBox = findViewById(R.id.search_box_start_search); mCollapsedHintView = (TextView) findViewById(R.id.search_box_collapsed_hint); mExpanded = (ViewGroup) findViewById(R.id.search_expanded_root); mSearchEditText = (EditText) mExpanded.findViewById(R.id.search_expanded_edit_text); mBackButtonView = mExpanded.findViewById(R.id.search_expanded_back_button); mExpandedSearchIcon = findViewById(R.id.search_expanded_magnifying_glass); // Convert a long click into a click to expand the search box, and then long click on the // search view. This accelerates the long-press scenario for copy/paste. mCollapsedSearchBox.setOnLongClickListener(new OnLongClickListener() { @Override//from ww w. j a v a 2 s . c o m public boolean onLongClick(View view) { mCollapsedSearchBox.performClick(); mSearchEditText.performLongClick(); return false; } }); mCollapsed.setOnClickListener(mSearchViewOnClickListener); mSearchIcon.setOnClickListener(mSearchViewOnClickListener); mCollapsedSearchBox.setOnClickListener(mSearchViewOnClickListener); mSearchEditText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { Utils.showInputMethod(v); } else { Utils.hideInputMethod(v); } } }); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { callSearchListener(); Utils.hideInputMethod(v); return true; } return false; } }); mSearchEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (mSearchEditText.getText().length() > 0) { if (mExpandedSearchIcon.getVisibility() != View.VISIBLE) { Utils.fadeIn(mExpandedSearchIcon, ANIMATION_DURATION); } } else { Utils.fadeOut(mExpandedSearchIcon, ANIMATION_DURATION); } if (mSearchBoxListener != null) mSearchBoxListener.onTextChanged(s, start, before, count); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if (mSearchBoxListener != null) mSearchBoxListener.beforeTextChanged(s, start, count, after); } @Override public void afterTextChanged(Editable s) { if (mSearchBoxListener != null) mSearchBoxListener.afterTextChanged(s); } }); mBackButtonView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { collapse(); } }); mExpandedSearchIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { callSearchListener(); Utils.hideInputMethod(v); } }); mCollapsedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.transparent)); mExpandedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), R.color.default_color_expanded)); mBackgroundTransition = new TransitionDrawable(new Drawable[] { mCollapsedDrawable, mExpandedDrawable }); mBackgroundTransition.setCrossFadeEnabled(true); setBackgroundCompat(); Utils.setPaddingAll(SearchViewLayout.this, 8); super.onFinishInflate(); }
From source file:cn.ucai.SuperWechat.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 av a 2 s. c om*/ 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); 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(); } }); // 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 = ((DemoHXSDKHelper) HXSDKHelper.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 if (Constant.CHAT_ROBOT.equals(username)) { //Robot? startActivity(new Intent(getActivity(), RobotsActivity.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); progressBar = (View) getView().findViewById(R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } setMupdateContactReceiver(); }
From source file:cn.ucai.chatuidemo.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/* w w w . j av 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); 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(); } }); // 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 = ((DemoHXSDKHelper) HXSDKHelper.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 if (Constant.CHAT_ROBOT.equals(username)) { //Robot? startActivity(new Intent(getActivity(), RobotsActivity.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); progressBar = (View) getView().findViewById(R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } UpdateContactListLitener(); }
From source file:com.nps.micro.view.TestsSectionFragment.java
@Override protected View buildRootView(LayoutInflater inflater, ViewGroup container) { View rootView = inflater.inflate(layout, container, false); runButton = (Button) rootView.findViewById(R.id.runButton); runButton.setOnClickListener(new OnClickListener() { @Override/* w w w. j a v a 2s. com*/ public void onClick(View v) { prepareScenarios(); } }); repeatsInput = (EditText) rootView.findViewById(R.id.repeatsInput); repeatsInput.setText(String.valueOf(model.getRepeats())); repeatsInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setRepeats(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); repeatsButton = (Button) rootView.findViewById(R.id.setRepeatsButton); repeatsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.repeats).setItems(R.array.repeats_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { repeatsInput.setText(getResources().getStringArray(R.array.repeats_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); outSizeInput = (EditText) rootView.findViewById(R.id.packetOutSizeInput); outSizeInput.setText(String.valueOf(model.getStreamOutSize())); outSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamOutSize(Short.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); outSizeButton = (Button) rootView.findViewById(R.id.setOutSizeButton); outSizeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.out_size).setItems(R.array.out_size_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { outSizeInput.setText(getResources().getStringArray(R.array.out_size_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); inSizeInput = (EditText) rootView.findViewById(R.id.packetInSizeInput); inSizeInput.setText(String.valueOf(model.getStreamInSizes()[0])); inSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String[] vals = s.toString().split(" "); List<Short> intVals = new ArrayList<Short>(); for (String val : vals) { try { intVals.add(Short.valueOf(val)); } catch (NumberFormatException e) { // TODO Auto-generated catch block } } short[] array = new short[intVals.size()]; for (int i = 0; i < intVals.size(); i++) array[i] = intVals.get(i); model.setStreamInSize(array); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); inSizeButton = (Button) rootView.findViewById(R.id.setInSizeButton); inSizeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.in_size).setItems(R.array.in_size_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { inSizeInput.setText(getResources().getStringArray(R.array.in_size_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); radioStorageGroup = (RadioGroup) rootView.findViewById(R.id.storageRadioGroup); externalStorageRadio = (RadioButton) rootView.findViewById(R.id.externalStorageRadio); internalStorageRadio = (RadioButton) rootView.findViewById(R.id.internalStorageRadio); switch (model.getStorageType()) { case EXTERNAL: externalStorageRadio.setChecked(true); break; case INTERNAL: internalStorageRadio.setChecked(true); break; } externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); radioStorageGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.internalStorageRadio: model.setStorageType(Storage.Type.INTERNAL); break; case R.id.externalStorageRadio: model.setStorageType(Storage.Type.EXTERNAL); break; } } }); saveLogsCheckBox = (CheckBox) rootView.findViewById(R.id.saveLogsCheckBox); saveLogsCheckBox.setChecked(model.isSaveLogs()); saveLogsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setSaveLogs(isChecked); externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); } }); streamBufferSizeInput = (EditText) rootView.findViewById(R.id.bufferSizeEditText); streamBufferSizeInput.setText(String.valueOf(model.getStreamBufferSize())); streamBufferSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamBufferSize(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); memoryUnitSpinner = (Spinner) rootView.findViewById(R.id.memoryUnitSpinner); memoryUnitSpinner.setSelection(model.getStreamBufferUnit().getIndex()); memoryUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { model.setStreamBufferUnit(MemoryUnit.fromIndex(pos)); } @Override public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); saveStreamCheckBox = (CheckBox) rootView.findViewById(R.id.saveStreamDataCheckbox); saveStreamCheckBox.setChecked(model.isSaveStreams()); streamBufferSizeInput.setEnabled(saveStreamCheckBox.isChecked()); memoryUnitSpinner.setEnabled(saveStreamCheckBox.isChecked()); streamQueueSize = (EditText) rootView.findViewById(R.id.streamQueueSize); streamQueueSize.setText(String.valueOf(model.getStreamQueueSize())); streamQueueSize.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamQueueSize(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize()); radioQueueGroup = (RadioGroup) rootView.findViewById(R.id.queueRadioGroup); autoStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.autoBufferRadio); manualStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.manualBufferRadio); if (model.isAutoStreamQueueSize()) { autoStreamQueueSizeRadio.setChecked(true); } else { manualStreamQueueSizeRadio.setChecked(true); } autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); radioQueueGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.autoBufferRadio: model.setAutoStreamQueueSize(true); streamQueueSize.setEnabled(false); break; case R.id.manualBufferRadio: model.setAutoStreamQueueSize(false); streamQueueSize.setEnabled(true); break; } } }); saveStreamCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setSaveStreams(isChecked); externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); streamBufferSizeInput.setEnabled(isChecked); memoryUnitSpinner.setEnabled(isChecked); autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize()); } }); simulateEditText = (EditText) rootView.findViewById(R.id.simulateComputationsEditText); simulateEditText.setText(String.valueOf(model.getSimulateComputations())); simulateEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { model.setSimulateComputations(Short.valueOf(s.toString())); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); normalPriorityCheckBox = (CheckBox) rootView.findViewById(R.id.normalPriorityCheckbox); normalPriorityCheckBox.setChecked(model.isNormalThreadPriority()); normalPriorityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setNormalThreadPriority(isChecked); } }); hiPriorityAndroidCheckBox = (CheckBox) rootView.findViewById(R.id.hiAndroidPriorityCheckbox); hiPriorityAndroidCheckBox.setChecked(model.isHiAndroidThreadPriority()); hiPriorityAndroidCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setHiAndroidThreadPriority(isChecked); } }); hiPriorityJavaCheckBox = (CheckBox) rootView.findViewById(R.id.hiJavaPriorityCheckbox); hiPriorityJavaCheckBox.setChecked(model.isHiJavaThreadPriority()); hiPriorityJavaCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setHiJavaThreadPriority(isChecked); } }); extendedDevicesCombination = (CheckBox) rootView.findViewById(R.id.extendedDevicesCheckBox); extendedDevicesCombination.setChecked(model.isExtendedDevicesCombination()); extendedDevicesCombination.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setExtendedDevicesCombination(isChecked); } }); fastHub = (CheckBox) rootView.findViewById(R.id.fastHubCheckBox); fastHub.setChecked(model.isFastHub()); fastHub.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setFastHub(isChecked); } }); autoEnableGraphCheckBox = (CheckBox) rootView.findViewById(R.id.autoEnableGraphCheckBox); autoEnableGraphCheckBox.setChecked(model.isAutoEnableGraph()); autoEnableGraphCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setAutoEnableGraph(isChecked); } }); createSequenceChooser(rootView); createDeviceChooser(rootView, runButton); updateStatus(rootView); return rootView; }
From source file:com.google.reviewit.ServerSettingsFragment.java
private void init() { final AutoCompleteTextView urlInput = (AutoCompleteTextView) v(R.id.urlInput); ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.urls)); urlInput.setAdapter(adapter);// w ww . ja v a2 s .co m v(R.id.pasteCredentialsButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); String pasteData = item.getText().toString(); if (!pasteData.contains("/.gitcookies")) { return; } pasteData = pasteData.substring(pasteData.indexOf("/.gitcookies")); pasteData = pasteData.substring(pasteData.lastIndexOf(",") + 1); int pos = pasteData.indexOf("="); String user = pasteData.substring(0, pos); pasteData = pasteData.substring(pos + 1); String password = pasteData.substring(0, pasteData.indexOf("\n")); WidgetUtil.setText(v(R.id.userInput), user); WidgetUtil.setText(v(R.id.passwordInput), password); // hide keyboard if it is open View view = getActivity().getCurrentFocus(); if (view != null) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(view.getWindowToken(), 0); } } } }); ((EditText) v(R.id.urlInput)).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 (Strings.isNullOrEmpty(textOf(R.id.nameInput))) { try { String host = new URL(s.toString()).getHost(); int pos = host.indexOf("."); WidgetUtil.setText(v(R.id.nameInput), pos > 0 ? host.substring(0, pos) : host); } catch (MalformedURLException e) { // ignore } } displayCredentialsInfo(s.toString()); } }); v(R.id.saveServerSettings).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { enabledForm(false); if (!isServerInputComplete()) { widgetUtil.showError(R.string.incompleteInput); enabledForm(true); return; } if (!isUrlValid()) { widgetUtil.showError(R.string.invalidUrl); enabledForm(true); return; } if (!hasUniqueName()) { widgetUtil.showError(getString(R.string.duplicate_server_name, textOf(R.id.nameInput))); enabledForm(true); return; } setVisible(v(R.id.statusTestConnection, R.id.statusTestConnectionProgress)); WidgetUtil.setText(v(R.id.statusTestConnectionText), null); new AsyncTask<Void, Void, String>() { private TextView status; private View statusTestConnectionProgress; private View statusTestConnection; @Override protected void onPreExecute() { super.onPreExecute(); status = tv(R.id.statusTestConnectionText); statusTestConnectionProgress = v(R.id.statusTestConnectionProgress); statusTestConnection = v(R.id.statusTestConnection); } @Override protected String doInBackground(Void... v) { return testConnection(); } protected void onPostExecute(String errorMsg) { if (errorMsg != null) { enabledForm(true); status.setTextColor(widgetUtil.color(R.color.statusFailed)); status.setText(getString(R.string.test_server_connection_failed)); setInvisible(statusTestConnectionProgress); new AlertDialog.Builder(getContext()).setTitle(getString(R.string.error_title)) .setMessage(getString(R.string.connection_failed, errorMsg)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setNegativeButton(getString(R.string.save_anyway), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { setGone(statusTestConnection); onServerSave(saveServerSettings()); } }) .setIcon(android.R.drawable.ic_dialog_alert).show(); } else { status.setTextColor(widgetUtil.color(R.color.statusOk)); status.setText(getString(R.string.test_server_connection_ok)); setGone(statusTestConnection); onServerSave(saveServerSettings()); } } }.execute(); } }); enabledForm(true); setGone(v(R.id.statusTestConnection)); }
From source file:com.brq.wallet.activity.export.MrdDecryptDataActivity.java
/** * Called when the activity is first created. *///from w ww .j a v a 2 s.c o m @Override public void onCreate(Bundle savedInstanceState) { this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.export_decrypt_private_key_activity); _mbwManager = MbwManager.getInstance(this); // Get parameters _encryptedData = getIntent().getStringExtra("encryptedData"); // Decode the header of the encrypted private key try { _header = MrdExport.V1.extractHeader(_encryptedData); } catch (DecodingException e) { Toast.makeText(this, R.string.unrecognized_format, Toast.LENGTH_SHORT).show(); finish(); return; } _taskExecutionServiceController = new TaskExecutionServiceController(); _taskExecutionServiceController.bind(this, this); _progressUpdater = new ProgressUpdater(); passwordEdit = (EditText) findViewById(R.id.password); passwordEdit.addTextChangedListener(new TextNormalizer(PASS_NORMALIZER, passwordEdit)); passwordEdit.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 (isValidPassword(s)) { startKeyStretching(); } updatePasswordText(); } }); if (savedInstanceState != null) { setPassword(savedInstanceState.getString("password")); } updatePasswordText(); showKeyboardOrStartStretching(); }