List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:me.philio.pinentry.PinEntryView.java
/** * Create views and add them to the view group *//*from w ww. ja v a 2s.c om*/ @TargetApi(21) private void addViews() { // Add a digit view for each digit for (int i = 0; i < mDigits; i++) { DigitView digitView = new DigitView(getContext()); digitView.setWidth(mDigitWidth); digitView.setHeight(mDigitHeight); digitView.setBackgroundResource(mDigitBackground); digitView.setTextColor(mDigitTextColor); digitView.setTextSize(mDigitTextSize); digitView.setGravity(Gravity.CENTER); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { digitView.setElevation(mDigitElevation); } addView(digitView); } // Add an "invisible" edit text to handle input mEditText = new EditText(getContext()); mEditText.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); mEditText.setTextColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); mEditText.setCursorVisible(false); mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mDigits) }); mEditText.setInputType(InputType.TYPE_CLASS_NUMBER); mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); mEditText.setPadding(mEditText.getPaddingLeft(), mEditText.getPaddingTop(), mEditText.getPaddingRight(), 100); mEditText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // Update the selected state of the views int length = mEditText.getText().length(); for (int i = 0; i < mDigits; i++) { getChildAt(i) .setSelected(hasFocus && (mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER && (i == length || (i == mDigits - 1 && length == mDigits))))); } // Make sure the cursor is at the end mEditText.setSelection(length); // Provide focus change events to any listener if (mOnFocusChangeListener != null) { mOnFocusChangeListener.onFocusChange(PinEntryView.this, hasFocus); } } }); 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) { int length = s.length(); for (int i = 0; i < mDigits; i++) { if (s.length() > i) { String mask = mMask == null || mMask.length() == 0 ? String.valueOf(s.charAt(i)) : mMask; ((TextView) getChildAt(i)).setText(mask); } else { ((TextView) getChildAt(i)).setText(""); } if (mEditText.hasFocus()) { getChildAt(i).setSelected(mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER && (i == length || (i == mDigits - 1 && length == mDigits)))); } } if (length == mDigits && mPinEnteredListener != null) { mPinEnteredListener.pinEntered(s.toString()); } } }); addView(mEditText); }
From source file:mn.today.TheHubActivity.java
/** Launches the process of creating a new Flow Object by * developing a Custom Dialog Box and determining valid * user input.//w w w .ja v a2 s.co m * */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) public void createNewFlow() { //Create edit text field for name entry final EditText nameInputET = new EditText(TheHubActivity.this); AlertDialog.Builder customDialog = generateCustomDialog(nameInputET); customDialog.setPositiveButton("???", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (nameInputET.getText().toString().equals("")) { // Need to optimize this so that the dialog does NOT disappear and just display toast Toast.makeText(TheHubActivity.this, " ? ? ?? :(", Toast.LENGTH_LONG).show(); createNewFlow(); //Recall the dialog } else { ToDay newF = new ToDay(nameInputET.getText().toString(), 0); if (adapter != null) { rvContent.add(newF); // Set the Flow Manager Index and add to List View Content adapter.notifyDataSetChanged(); } manager.save(newF.getUuid(), newF); } } }); customDialog.setNegativeButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); customDialog.show(); }
From source file:com.piusvelte.sonet.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);//w w w . ja v a2 s . c om mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE); mServiceName = Sonet.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID); mSonetWebView = new SonetWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mSonetWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.finish(); } } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mSonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, BuildConfig.FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; case MYSPACE: mSonetOAuth = new SonetOAuth(BuildConfig.MYSPACE_KEY, BuildConfig.MYSPACE_SECRET); asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FOURSQUARE: mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, BuildConfig.FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mSonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Sonet.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; case IDENTICA: mSonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET); asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case GOOGLEPLUS: mSonetWebView.open(String.format(GOOGLEPLUS_AUTHORIZE, BuildConfig.GOOGLECLIENT_ID, "urn:ietf:wg:oauth:2.0:oob")); break; case CHATTER: mSonetWebView.open(String.format(CHATTER_URL_AUTHORIZE, BuildConfig.CHATTER_KEY, CHATTER_CALLBACK.toString())); break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }
From source file:com.piusvelte.sonet.core.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/*from ww w. j a v a2 s.c o m*/ mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE); mServiceName = Sonet.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID); mSonetWebView = new SonetWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mSonetWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.finish(); } } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mSonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; case MYSPACE: mSonetOAuth = new SonetOAuth(MYSPACE_KEY, MYSPACE_SECRET); asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FOURSQUARE: mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mSonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Sonet.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; case IDENTICA: mSonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET); asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case GOOGLEPLUS: mSonetWebView.open( String.format(GOOGLEPLUS_AUTHORIZE, GOOGLE_CLIENTID, "urn:ietf:wg:oauth:2.0:oob")); break; case CHATTER: mSonetWebView .open(String.format(CHATTER_URL_AUTHORIZE, CHATTER_KEY, CHATTER_CALLBACK.toString())); break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }
From source file:de.hshannover.f4.trust.ironcontrol.view.AdvancedRequestFragment.java
public Dialog createSearchSaveDialog() { AlertDialog.Builder publishSaveDialog = new AlertDialog.Builder(getActivity()); publishSaveDialog.setTitle(R.string.save); publishSaveDialog.setMessage(R.string.saving_search_message); final EditText input = new EditText(getActivity()); input.setText(etName.getText().toString()); publishSaveDialog.setView(input);/*w w w . j a v a2 s. c o m*/ publishSaveDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { if (saveSearch(input.getText().toString()) == null) { Toast.makeText(getActivity(), "not saved", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(), "Search: " + input.getText().toString() + " is saved", Toast.LENGTH_SHORT).show(); } } }); publishSaveDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { } }); return publishSaveDialog.create(); }
From source file:org.envirocar.app.activity.ListTracksFragment.java
/** * Change one item/* ww w. j a v a 2 s . c o m*/ */ @Override public boolean onContextItemSelected(MenuItem item) { final Track track; synchronized (this) { track = tracksList.get(itemSelect); } switch (item.getItemId()) { // Edit the trackname case R.id.editName: if (track.isLocalTrack()) { logger.info("editing track: " + itemSelect); final EditText input = new EditText(getActivity()); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.editTrack)) .setMessage(getString(R.string.enterTrackName)).setView(input) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); logger.info("New name: " + value.toString()); track.setName(value); dbAdapter.updateTrack(track); tracksList.get(itemSelect).setName(value); updateTrackListView(); Crouton.showText(getActivity(), getString(R.string.nameChanged), Style.INFO); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } else { Crouton.showText(getActivity(), R.string.not_possible_for_remote, Style.INFO); } return true; // Edit the track description case R.id.editDescription: if (track.isLocalTrack()) { logger.info("editing track: " + itemSelect); final EditText input2 = new EditText(getActivity()); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.editTrack)) .setMessage(getString(R.string.enterTrackDescription)).setView(input2) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input2.getText().toString(); logger.info("New description: " + value.toString()); track.setDescription(value); dbAdapter.updateTrack(track); trackListView.collapseGroup(itemSelect); updateTrackListView(); trackListAdapter.updateTrackChildView(track); Crouton.showText(getActivity(), getString(R.string.descriptionChanged), Style.INFO); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } else { Crouton.showText(getActivity(), R.string.not_possible_for_remote, Style.INFO); } return true; // Show that track in the map case R.id.startMap: logger.info("Show in Map"); logger.info(Environment.getExternalStorageDirectory().toString()); File f = new File(Environment.getExternalStorageDirectory() + "/Android"); if (f.isDirectory()) { // if (track.isLazyLoadingMeasurements()) { // dbAdapter.loadMeasurements(track); // } List<Measurement> measurements = track.getMeasurements(); logger.info("Count of measurements in the track: " + String.valueOf(measurements.size())); String[] trackCoordinates = extractCoordinates(measurements); if (trackCoordinates.length != 0) { logger.info(String.valueOf(trackCoordinates.length)); Intent intent = new Intent(getActivity().getApplicationContext(), org.envirocar.app.activity.Map.class); Bundle bundle = new Bundle(); bundle.putStringArray("coordinates", trackCoordinates); intent.putExtras(bundle); startActivity(intent); } else { Crouton.showText(getActivity(), getString(R.string.trackContainsNoCoordinates), Style.INFO); } } else { Crouton.showText(getActivity(), getString(R.string.noSdCard), Style.INFO); } return true; // Delete only selected track case R.id.deleteTrack: /* * we need to check the database if the track might have * transisted to a remote track due to uploading */ Track dbRefTrack = dbAdapter.getTrack(track.getTrackId(), true); if (dbRefTrack.isLocalTrack()) { logger.info("deleting item: " + itemSelect); dbAdapter.deleteTrack(track.getTrackId()); Crouton.showText(getActivity(), getString(R.string.trackDeleted), Style.INFO); tracksList.remove(itemSelect); updateTrackListView(); } else { createRemoteDeleteDialog(track, (RemoteTrack) dbRefTrack); } return true; // Share track case R.id.shareTrack: try { // if (track.isLazyLoadingMeasurements()) { // dbAdapter.loadMeasurements(track); // } Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("application/json"); Uri shareBody = Uri.fromFile(Util.saveTrackAndReturnFile(track, isObfuscationEnabled()).getFile()); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "EnviroCar Track " + track.getName()); sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, shareBody); startActivity(Intent.createChooser(sharingIntent, "Share via")); } catch (JSONException e) { logger.warn(e.getMessage(), e); Crouton.showText(getActivity(), R.string.error_json, Style.ALERT); } catch (IOException e) { logger.warn(e.getMessage(), e); Crouton.showText(getActivity(), R.string.error_io, Style.ALERT); } catch (TrackWithoutMeasurementsException e) { logger.warn(e.getMessage(), e); if (isObfuscationEnabled()) { Crouton.showText(getActivity(), R.string.uploading_track_no_measurements_after_obfuscation_long, Style.ALERT); } else { Crouton.showText(getActivity(), R.string.uploading_track_no_measurements_after_obfuscation_long, Style.ALERT); } } return true; // Upload track case R.id.uploadTrack: if (UserManager.instance().isLoggedIn()) { // if (track.isLazyLoadingMeasurements()) { // dbAdapter.loadMeasurements(track); // } startTrackUpload(false, track); } else { Crouton.showText(getActivity(), R.string.hint_login_first, Style.INFO); } return true; default: return super.onContextItemSelected(item); } }
From source file:bikebadger.RideFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(Constants.APP.TAG, "RideFragment.onCreateView()"); setRetainInstance(true);/*from w ww. j a va 2 s . c o m*/ View view = inflater.inflate(R.layout.fragment_run, container, false); mMessagebarView = (TextView) view.findViewById(R.id.run_messagebarView); mStartedTextView = (TextView) view.findViewById(R.id.run_startedTextView); mDurationTextView = (TextView) view.findViewById(R.id.run_durationTextView); mSpeedTextView = (TextView) view.findViewById(R.id.run_speedTextView); mTargetSpeedTextView = (TextView) view.findViewById(R.id.run_targetSpeedTextView); mAverageSpeedTextView = (TextView) view.findViewById(R.id.run_avgSpeedTextView); mStartStopButton = (ImageButton) view.findViewById(R.id.run_startButton); mTargetEditButton = (Button) view.findViewById(R.id.target_editButton); mArrowView = (ImageView) view.findViewById(R.id.img1); // set up startstop buttons mPlayButtonClickListener = new View.OnClickListener() { @Override public void onClick(View v) { if (mRide == null) { startReceivingTimerUpdates(); startReceivingLocationUpdates(); // RideManager starts the location services mRide = mRideManager.startNewRun(); } else { mRideManager.startTrackingRun(mRide); } //MediaUtil.Beep(); mRideManager.SpeakWords("Starting"); updateUI(); mRide.StartStopwatch(); MyToast.Show(getActivity().getApplicationContext(), "Starting", Color.BLACK); } }; mStartStopButton.setOnClickListener(mPlayButtonClickListener); mPauseButtonClickListener = new View.OnClickListener() { @Override public void onClick(View v) { //MediaUtil.Beep(); mRideManager.SpeakWords("Stopping"); mRideManager.stopRun(); updateUI(); stopReceivingTimerUpdates(); if (mRide != null) mRide.PauseStopwatch(); MyToast.Show(getActivity().getApplicationContext(), "Stopped", Color.BLACK); } }; // Reset the average mResetButton = (ImageButton) view.findViewById(R.id.run_resetButton); mResetButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //MediaUtil.Beep(); if (mRide != null && mRideManager.isTrackingRun(mRide)) { mRide.ResetAverageSpeed(); } updateUI(); } }); mWaypointButton = (ImageButton) view.findViewById(R.id.run_waypointButton); mWaypointButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //MediaUtil.Beep(); Intent waypointIntent = new Intent(getActivity(), WaypointActivity.class); waypointIntent.putExtra("location", mRideManager.GetLastKnowLocation()); startActivityForResult(waypointIntent, Constants.APP.ACTION_WAYPOINT_REQUEST_CODE); updateUI(); } }); mTargetEditButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); final EditText einput = new EditText(getActivity()); alert.setTitle("Target Average Speed"); alert.setMessage("Edit the target average speed."); einput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); einput.setText(mTargetSpeedTextView.getText()); alert.setView(einput); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String sValue = einput.getText().toString(); double targetVal; try { targetVal = Double.parseDouble(sValue); } catch (NumberFormatException nfe) { targetVal = 0; Log.d("RunTracker", "Error parsing mSpeedIntervalSeconds"); } if (targetVal > 78700 && targetVal < 78800) { final SharedPreferences myPrefs = PreferenceManager .getDefaultSharedPreferences(getActivity().getApplicationContext()); myPrefs.edit().putBoolean("Hacked", true).commit(); AppManager.SimpleNotice(getActivity(), "Full Version Hack", "You now have access to the full paid version for free."); //getActivity().finish(); } else { if (mRide != null) { mRide.SetTargetAvgSpeed(targetVal); } else if (mRideManager != null) { mRideManager.SetDefaultTargetAvgSpeed(targetVal); } mTargetSpeedTextView.setText(sValue); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); } }); // do we start now? if (mRideManager != null && mRideManager.IsStartNow()) { startReceivingTimerUpdates(); startReceivingLocationUpdates(); mRide = mRideManager.startNewRun(); mRideManager.SpeakWords("Starting"); } // Trying to fix flicker issue // if(isVisible()) // updateUI(); return view; }
From source file:it.unime.mobility4ckan.MainActivity.java
private void setDatasetName() { DinamicView dinamicView = new DinamicView(getApplicationContext()); dinamicView.getNoteLabel().setText(getString(R.string.note_dialog)); dinamicView.getNoteLabel().setTextSize(12); nameText = new EditText(getApplicationContext()); nameText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); nameText.setGravity(Gravity.CENTER); nameText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); nameText.setTextColor(Color.BLACK); nameText.setSingleLine(true);//from w w w .j av a 2s . com nameText.setTextSize(18); dinamicView.getBodyLayout().addView(nameText); final AlertDialog mDialog = new AlertDialog.Builder(this) .setMessage(getString(R.string.inserisci_nome_dataset)).setView(dinamicView).setCancelable(false) .setPositiveButton("OK", null).create(); mDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = mDialog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { datasetName = nameText.getText().toString().trim().toLowerCase(); String regexp = "^[a-z-0-9_]*$"; Matcher matcher = Pattern.compile(regexp).matcher(datasetName); if (matcher.find()) { mDialog.dismiss(); datasetNameText.setText(datasetName); startTimer(); } else { nameText.getText().clear(); nameText.setError(getString(R.string.note_dialog)); } } }); } }); mDialog.show(); }
From source file:de.sindzinski.wetter.MainActivity.java
public void addLocationSettingDialog() { String locationSetting = ""; final EditText input = new EditText(MainActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.dialog_title_add_location_setting); builder.setView(input);/*from w w w .j a v a 2 s . c o m*/ // Set the action buttons builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // User clicked OK, so save the mSelectedItems results somewhere // or return them to the component that opened the dialog String locationSetting = input.getText().toString().toLowerCase().replaceAll("\\s+", ""); locationSetting = Utility.wordFirstCap(locationSetting, "/"); locationSetting = Utility.wordFirstCap(locationSetting, ","); if (locationSetting.compareTo("") != 0) { Utility.setPreferredLocation(getApplicationContext(), locationSetting); Utility.resetLocationStatus(getApplicationContext()); WetterSyncAdapter.syncImmediately(getApplicationContext()); reInitializeNavigation(); } } }).setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setNeutralButton(R.string.dialog_current_location, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // User clicked OK, so save the mSelectedItems results somewhere // or return them to the component that opened the dialog onCurrentLocation(); } }) // .setNeutralButton(R.string.dialog_place_picker, new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int id) { //// startPlacePicker(); // } // }) ; AlertDialog dialog = builder.create(); dialog.show(); }
From source file:org.bobstuff.bobball.ActivityStateEnum.java
private void promptUsername() { activityState = ActivityStateEnum.GAMELOST_TOPSCORE; final EditText input = new EditText(this); final String defaultName = Preferences.loadValue("defaultName", getString(R.string.defaultName)); input.setHint(defaultName);/* ww w. ja v a 2 s . c o m*/ new AlertDialog.Builder(this).setTitle(R.string.namePrompt).setMessage(R.string.highScoreAchieved) .setView(input).setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); String valueString = value.toString().trim(); if (valueString.isEmpty()) { valueString = defaultName; } scores.addScore(valueString, gameManager.getCurrGameState().getPlayer(playerId).getScore()); showTopScores(); } }).show(); }