List of usage examples for android.widget EditText getText
@Override
public Editable getText()
From source file:adventure_fragments.Climbing.java
public void AddItemNow() { final EditText input; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Add item to list"); input = new EditText(getActivity()); int maxLength = 20; input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) }); builder.setView(input);//from w w w . ja v a2 s . co m builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String item_name = input.getText().toString(); if (item_name.equals("")) { Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show(); } else if (item_name.equals(" ")) { Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show(); } else if (item_name.equals(" ")) { Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show(); } else if (item_name.equals("This app sucks")) { Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show(); } else { ItemClass itemClass = new ItemClass(item_name, 0); db.addItemClimbing(itemClass); adapt.add(itemClass); adapt.notifyDataSetChanged(); list = db.getAllItemsClimbing(); adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list); listItem = (ListView) getActivity().findViewById(R.id.listview_climb); listItem.setAdapter(adapt); count = listItem.getCount(); if (count > 0) { nothingtext.setVisibility(View.GONE); } else if (count == 0) { nothingtext.setVisibility(View.VISIBLE); } } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { list = db.getAllItemsClimbing(); adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list); listItem = (ListView) getActivity().findViewById(R.id.listview_climb); listItem.setAdapter(adapt); dialog.dismiss(); } }); builder.show(); }
From source file:org.anhonesteffort.flock.SubscriptionStripeFragment.java
private void initCardNumberHelper() { final EditText cardNumberView = (EditText) subscriptionActivity.findViewById(R.id.card_number); final EditText cardExpirationView = (EditText) subscriptionActivity.findViewById(R.id.card_expiration); cardNumberView.setOnTouchListener(new View.OnTouchListener() { @Override/*from ww w . ja v a2 s. c om*/ public boolean onTouch(View v, MotionEvent event) { if (cardNumberView.getText() != null && cardNumberView.getText().toString().contains("*")) { cardNumberView.setText(""); } return false; } }); if (cardNumberTextWatcher != null) cardNumberView.removeTextChangedListener(cardNumberTextWatcher); cardNumberTextWatcher = 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) { String cardNumber = s.toString().replace(" ", ""); String formattedCardNumber = ""; for (int i = 0; i < cardNumber.length(); i++) { if (i > 0 && i % 4 == 0) formattedCardNumber += " "; formattedCardNumber += cardNumber.charAt(i); } cardNumberView.removeTextChangedListener(this); cardNumberView.setText(formattedCardNumber); cardNumberView.setSelection(formattedCardNumber.length()); cardNumberView.addTextChangedListener(this); if (!cardNumber.contains("*") && cardNumber.length() == 16) cardExpirationView.requestFocus(); } }; cardNumberView.addTextChangedListener(cardNumberTextWatcher); }
From source file:com.ibm.hellotodoadvanced.MainActivity.java
/** * Launches a dialog for adding a new TodoItem. Called when plus button is tapped. * * @param view The plus button that is tapped. *//* w ww. j a va2 s . c o m*/ public void addTodo(View view) { final Dialog addDialog = new Dialog(this); // UI settings for dialog pop-up addDialog.setContentView(R.layout.add_edit_dialog); addDialog.setTitle("Add Todo"); TextView textView = (TextView) addDialog.findViewById(android.R.id.title); if (textView != null) { textView.setGravity(Gravity.CENTER); } addDialog.setCancelable(true); Button add = (Button) addDialog.findViewById(R.id.Add); addDialog.show(); // When done is pressed, send POST request to create TodoItem on Bluemix add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo); final String name = itemToAdd.getText().toString(); // If text was added, continue with normal operations if (!name.isEmpty()) { // Create JSON for new TodoItem, id should be 0 for new items String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}"; // Create POST request with the Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.POST); HashMap headers = new HashMap(); List<String> contentType = new ArrayList<>(); contentType.add("application/json"); List<String> accept = new ArrayList<>(); accept.add("Application/json"); headers.put("Content-Type", contentType); headers.put("Accept", accept); request.setHeaders(headers); request.send(getApplicationContext(), json, new ResponseListener() { // On success, update local list with new TodoItem @Override public void onSuccess(Response response) { Log.i(TAG, "Item " + name + " created successfully"); loadList(); } // On failure, log errors @Override public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) { String errorMessage = ""; if (response != null) { errorMessage += response.toString() + "\n"; } if (throwable != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); errorMessage += "THROWN" + sw.toString() + "\n"; } if (extendedInfo != null) { errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n"; } if (errorMessage.isEmpty()) errorMessage = "Request Failed With Unknown Error."; Log.e(TAG, "addTodo failed with error: " + errorMessage); } }); } // Close dialog when finished, or if no text was added addDialog.dismiss(); } }); }
From source file:org.liberty.android.fantastischmemopro.downloader.DownloaderFE.java
@Override protected void initialRetrieve() { mHandler = new Handler(); dlAdapter = new DownloadListAdapter(this, R.layout.filebrowser_item); listView = (ListView) findViewById(R.id.file_list); listView.setAdapter(dlAdapter);/*from w ww. j a v a2 s. c o m*/ final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences.Editor editor = settings.edit(); String prevInput = settings.getString("prev_fe_input", ""); final EditText input = new EditText(this); input.setText(prevInput); new AlertDialog.Builder(this).setTitle(getString(R.string.fe_search_title)) .setMessage(getString(R.string.fe_search_message)).setView(input) .setPositiveButton(getString(R.string.ok_text), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String value = input.getText().toString(); editor.putString("prev_fe_input", value); editor.commit(); mProgressDialog = ProgressDialog.show(DownloaderFE.this, getString(R.string.loading_please_wait), getString(R.string.loading_connect_net), true, true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); new Thread() { public void run() { try { final List<DownloadItem> dil = retrieveList(value); mHandler.post(new Runnable() { public void run() { dlAdapter.addList(dil); mProgressDialog.dismiss(); } }); } catch (final Exception e) { mHandler.post(new Runnable() { public void run() { mProgressDialog.dismiss(); new AlertDialog.Builder(DownloaderFE.this) .setTitle(R.string.downloader_connection_error) .setMessage( getString(R.string.downloader_connection_error_message) + e.toString()) .setPositiveButton(getString(R.string.ok_text), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }) .create().show(); } }); } } }.start(); } }).setNegativeButton(getString(R.string.cancel_text), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { finish(); } }).create().show(); }
From source file:at.flack.FacebookMainActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (((MainActivity) getActivity()).existsCookie()) { View rootView = inflater.inflate(R.layout.fragment_fb_main, container, false); contactList = (ListView) rootView.findViewById(R.id.listview); loadmore = new LoadMoreAdapter(inflater.inflate(R.layout.contacts_loadmore, contactList, false)); cantloadContacts = rootView.findViewById(R.id.nothing_found); TextView padding = new TextView(getActivity()); padding.setHeight(10);//from ww w . java 2 s . c om contactList.addHeaderView(padding); contactList.setHeaderDividersEnabled(false); contactList.addFooterView(loadmore.getView(), null, false); contactList.setFooterDividersEnabled(false); smiley_helper = new SmileyKonverter(); swipe = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container); swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (getActivity() instanceof MainActivity) ((MainActivity) getActivity()).facebookLogin(); } }); contactList.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int topRowVerticalPosition = (contactList == null || contactList.getChildCount() == 0) ? 0 : contactList.getChildAt(0).getTop(); swipe.setEnabled(topRowVerticalPosition >= 0); } }); loadmore.getView().setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { loadmore.setEnabled(false); loadMore(); } }); setProgressbar(rootView.findViewById(R.id.load_screen)); if (MainActivity.getFbcontacts() == null) getProgressbar().setVisibility(View.VISIBLE); updateContacts(getActivity()); contactList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { openMessageActivity(getActivity(), arg2 - 1); } }); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); fab.attachToListView(contactList); fab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent qr = new Intent(getActivity(), NewFbContactActivity.class); startActivityForResult(qr, 1); } }); updateProfilePictures(getActivity()); setRetainInstance(true); return rootView; } else { View rootView = inflater.inflate(R.layout.fragment_facebook_login, container, false); final EditText mail = (EditText) rootView.findViewById(R.id.email); final EditText password = (EditText) rootView.findViewById(R.id.password); final Button login_button = (Button) rootView.findViewById(R.id.login_button); login_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mail.getText().length() <= 0) { Toast.makeText(FacebookMainActivity.this.getActivity(), getResources().getString(R.string.facebook_login_please_enter_valid_mail), Toast.LENGTH_SHORT).show(); return; } if (password.getText().length() <= 0) { Toast.makeText(FacebookMainActivity.this.getActivity(), getResources().getString(R.string.facebook_login_please_enter_valid_pw), Toast.LENGTH_SHORT).show(); return; } login_button.setEnabled(false); login_button.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY); if (((MainActivity) getActivity()).facebookLogin(mail.getText().toString(), password.getText().toString())) { } else { Toast.makeText(FacebookMainActivity.this.getActivity(), getResources().getString(R.string.facebook_login_incorrect_or_offline), Toast.LENGTH_SHORT).show(); password.setText(""); login_button.getBackground().setColorFilter(null); login_button.setEnabled(true); } } }); setRetainInstance(true); return rootView; } }
From source file:com.citrus.sdk.CitrusActivity.java
private void showPrompt() { final AlertDialog.Builder alert = new AlertDialog.Builder(mContext); String message = null;/* ww w .j av a2 s .c o m*/ String title = null; if (passwordPromptShown) { message = "Incorrect Password."; title = "Please Enter Password Again."; } else { message = "Please Enter Your Password For Citrus Account."; title = "Enter Password"; } String positiveButtonText = "Pay"; alert.setTitle(title); alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(mContext); alert.setView(input); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String password = input.getText().toString(); input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); if (!TextUtils.isEmpty(password)) { mPaymentWebview .loadUrl("javascript:(function() { " + "document.getElementById('password').value='" + password + "';" + "document.getElementById(\"verify\").submit();" + "}) ()"); input.clearFocus(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0); String emailId = mCitrusClient.getUserEmailId(); getCookie(emailId, password); dialog.dismiss(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { onBackPressed(); } }); input.requestFocus(); alert.show(); }
From source file:com.ibm.hellotodoadvanced.MainActivity.java
/** * Launches a dialog for updating the TodoItem name. Called when the list item is tapped. * * @param view The TodoItem that is tapped. *///from w w w.j a va 2 s . c o m public void editTodoName(View view) { // Gets position in list view of tapped item final Integer position = mListView.getPositionForView(view); final Dialog editDialog = new Dialog(this); // UI settings for dialog pop-up editDialog.setContentView(R.layout.add_edit_dialog); editDialog.setTitle("Edit Todo"); TextView textView = (TextView) editDialog.findViewById(android.R.id.title); if (textView != null) { textView.setGravity(Gravity.CENTER); } editDialog.setCancelable(true); EditText currentText = (EditText) editDialog.findViewById(R.id.todo); // Get selected TodoItem values final String name = mTodoItemList.get(position).text; final boolean isDone = mTodoItemList.get(position).isDone; final int id = mTodoItemList.get(position).idNumber; currentText.setText(name); Button editDone = (Button) editDialog.findViewById(R.id.Add); editDialog.show(); // When done is pressed, send PUT request to update TodoItem on Bluemix editDone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText editedText = (EditText) editDialog.findViewById(R.id.todo); final String updatedName = editedText.getText().toString(); // If new text is not empty, create JSON with updated info and send PUT request if (!updatedName.isEmpty()) { String json = "{\"text\":\"" + updatedName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}"; // Create PUT REST request using Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.PUT); HashMap headers = new HashMap(); List<String> contentType = new ArrayList<>(); contentType.add("application/json"); List<String> accept = new ArrayList<>(); accept.add("Application/json"); headers.put("Content-Type", contentType); headers.put("Accept", accept); request.setHeaders(headers); request.send(getApplicationContext(), json, new ResponseListener() { // On success, update local list with updated TodoItem @Override public void onSuccess(Response response) { Log.i(TAG, "Item " + updatedName + " updated successfully"); loadList(); } // On failure, log errors @Override public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) { String errorMessage = ""; if (response != null) { errorMessage += response.toString() + "\n"; } if (throwable != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); errorMessage += "THROWN" + sw.toString() + "\n"; } if (extendedInfo != null) { errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n"; } if (errorMessage.isEmpty()) errorMessage = "Request Failed With Unknown Error."; Log.e(TAG, "editTodoName failed with error: " + errorMessage); } }); } editDialog.dismiss(); } }); }
From source file:com.manzdagratiano.gobbledygook.Gobbledygook.java
/** * @brief /*w w w . j av a 2s . c om*/ * @return */ private byte[] getSeedSHA(View view) { EditText password = (EditText) findViewById(R.id.password); byte[] seedSHA = null; MessageDigest hash = null; try { hash = MessageDigest.getInstance(Env.SHA256); seedSHA = hash.digest(password.getText().toString().getBytes()); } catch (NoSuchAlgorithmException e) { Log.e(Env.LOG_CATEGORY, "ERROR: Caught " + e); e.printStackTrace(); } return seedSHA; }
From source file:at.tomtasche.reader.ui.activity.DocumentActivity.java
public void handleError(Throwable error, final Uri uri) { Log.e("OpenDocument Reader", "Error opening file at " + uri.toString(), error); final Uri cacheUri = AndroidFileCache.getCacheFileUri(); for (LoadingListener listener : loadingListeners) { listener.onError(error, uri);/*from w w w . jav a 2 s. c o m*/ // TODO: return here, but only if the listener was registered by a // JUnit test } int errorDescription; if (error == null) { return; } else if (error instanceof EncryptedDocumentException) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.toast_error_password_protected); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); builder.setView(input); builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { loadUri(cacheUri, input.getText().toString()); dialog.dismiss(); } }); builder.setNegativeButton(getString(android.R.string.cancel), null); builder.show(); return; } else if (error instanceof IllegalMimeTypeException || error instanceof ZipException || error instanceof ZipEntryNotFoundException || error instanceof UnsupportedMimeTypeException) { /*AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.toast_error_illegal_file); builder.setMessage(R.string.dialog_upload_file); builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { uploadUri(cacheUri); dialog.dismiss(); } }); builder.setNegativeButton(getString(android.R.string.cancel), null); builder.show();*/ return; } else if (error instanceof FileNotFoundException) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY) || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { errorDescription = R.string.toast_error_find_file; } else { errorDescription = R.string.toast_error_storage; } } else if (error instanceof IllegalArgumentException) { errorDescription = R.string.toast_error_illegal_file; } else if (error instanceof OutOfMemoryError) { errorDescription = R.string.toast_error_out_of_memory; } else { errorDescription = R.string.toast_error_generic; } showCrouton(errorDescription, null, AppMsg.STYLE_ALERT); }