List of usage examples for android.app AlertDialog show
public void show()
From source file:com.mdlive.sav.MDLiveSearchProvider.java
/** * Instantiating array adapter to populate the listView * The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item * * @param list : Dependent users array list *//*from w w w.ja v a2 s. c o m*/ private void showListViewDialog(final ArrayList<String> list, final TextView selectedText, final String key, final ArrayList<HashMap<String, String>> typeList) { /*We need to get the instance of the LayoutInflater*/ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MDLiveSearchProvider.this); LayoutInflater inflater = getLayoutInflater(); View convertView = inflater.inflate(R.layout.mdlive_screen_popup, null); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.popupListview); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); lv.setAdapter(adapter); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final AlertDialog dialog = alertDialog.create(); dialog.show(); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String SelectedText = list.get(position); HashMap<String, String> localMap = typeList.get(position); for (Map.Entry entry : localMap.entrySet()) { if (SelectedText.equals(entry.getValue().toString())) { postParams.put(key, entry.getKey().toString()); break; //breaking because its one to one map } } specialityBasedOnProvider(SelectedText, key); String oldChoice = selectedText.getText().toString(); selectedText.setText(SelectedText); dialog.dismiss(); // if user selects a different Provider type, then reload this screen if (!oldChoice.equals(SelectedText)) { SharedPreferences sharedpreferences = getSharedPreferences( PreferenceConstants.MDLIVE_USER_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PreferenceConstants.PROVIDER_MODE, SelectedText); int providerType = MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText) == null ? MDLiveConfig.UNMAPPED : MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText); if (providerType == MDLiveConfig.UNMAPPED) editor.putString(PreferenceConstants.PROVIDERTYPE_ID, ""); else editor.putString(PreferenceConstants.PROVIDERTYPE_ID, String.valueOf(providerType)); editor.commit(); // now reload the screen //recreate(); } } }); }
From source file:com.loadsensing.app.LoginActivity.java
public void onClick(View v) { // this gets the resources in the xml file // and assigns it to a local variable of type EditText EditText usernameEditText = (EditText) findViewById(R.id.txt_username); EditText passwordEditText = (EditText) findViewById(R.id.txt_password); // the getText() gets the current value of the text box // the toString() converts the value to String data type // then assigns it to a variable of type String String sUserName = usernameEditText.getText().toString(); String sPassword = passwordEditText.getText().toString(); // Definimos constructor de alerta para los avisos posteriores AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog = new AlertDialog.Builder(this).create(); // call the backend using Get parameters String address = SERVER_HOST + "?user=" + sUserName + "&pass=" + sPassword + ""; if (sUserName.equals("") || sPassword.equals("")) { // error alert alertDialog.setTitle(getResources().getString(R.string.error)); alertDialog.setMessage(getResources().getString(R.string.empty_fields)); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; }/*from w ww . j a v a 2s . c o m*/ }); alertDialog.show(); } else if (!checkConnection(this.getApplicationContext())) { alertDialog.setTitle(getResources().getString(R.string.error)); alertDialog.setMessage(getResources().getString(R.string.error_no_internet)); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.show(); } else { try { showBusyCursor(true); progress = ProgressDialog.show(this, getResources().getString(R.string.pantalla_espera_title), getResources().getString(R.string.iniciando_sesion), true); Log.d(DEB_TAG, "Requesting to " + address); JSONObject json = JsonClient.connectJSONObject(address); CheckBox rememberUserPassword = (CheckBox) findViewById(R.id.remember_user_password); if (rememberUserPassword.isChecked()) { setSharedPreference("login", sUserName); setSharedPreference("password", sPassword); } else { setSharedPreference("login", ""); setSharedPreference("password", ""); } if (json.getString("session") != "0") { progress.dismiss(); // Guardamos la session en SharedPreferences para utilizarla // posteriormente setSharedPreference("session", json.getString("session")); // Sessin correcta. StartActivity de la home Intent intent = new Intent(); intent.setClass(this.getApplicationContext(), HomeActivity.class); startActivity(intent); } else { progress.dismiss(); alertDialog.setTitle(getResources().getString(R.string.error)); alertDialog.setMessage(getResources().getString(R.string.error_login)); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.show(); } } catch (JSONException e) { progress.dismiss(); Log.d(DEB_TAG, "Error parsing data " + e.toString()); } showBusyCursor(false); } }
From source file:com.TakeTaxi.jy.OnrouteScreen.java
public void alertdialog_canceljob() { String check = Query.jobQuery("clientcancel", job_id, 0, driver_id); if (check.equals("done")) { AlertDialog dcancelbuilder = new AlertDialog.Builder(OnrouteScreen.this).create(); dcancelbuilder.setMessage("Job has been cancelled.\n"); dcancelbuilder.setButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent openStart = new Intent("com.TakeTaxi.jy.TakeTaxiActivity"); startActivity(openStart); }//from w w w. ja va2 s. c om }); dcancelbuilder.show(); } else { Toast.makeText(getBaseContext(), "Could not connect to server.\nPlease try again.", Toast.LENGTH_SHORT) .show(); } }
From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java
private void showAlertDialog(String alertMessage) { AlertDialog.Builder builder = new AlertDialog.Builder(OpenHABWidgetListActivity.this); builder.setMessage(alertMessage).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { }/*from ww w. j ava 2 s .com*/ }); AlertDialog alert = builder.create(); alert.show(); }
From source file:net.networksaremadeofstring.cyllell.ViewEnvironments_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { list = (ListView) this.getActivity().findViewById(R.id.environmentsListView); settings = this.getActivity().getSharedPreferences("Cyllell", 0); try {/*from ww w .j ava 2 s . c o m*/ Cut = new Cuts(getActivity()); } catch (Exception e) { e.printStackTrace(); } dialog = new ProgressDialog(getActivity()); dialog.setTitle("Contacting Chef"); dialog.setMessage("Please wait: Prepping Authentication protocols"); dialog.setIndeterminate(true); if (listOfEnvironments.size() < 1) { dialog.show(); } updateListNotify = new Handler() { public void handleMessage(Message msg) { int tag = msg.getData().getInt("tag", 999999); if (msg.what == 0) { if (tag != 999999) { listOfEnvironments.get(tag).SetSpinnerVisible(); } } else if (msg.what == 1) { //Get rid of the lock CutInProgress = false; //the notifyDataSetChanged() will handle the rest } else if (msg.what == 99) { if (tag != 999999) { Toast.makeText(ViewEnvironments_Fragment.this.getActivity(), "An error occured during that operation.", Toast.LENGTH_LONG).show(); listOfEnvironments.get(tag).SetErrorState(); } } EnvironmentAdapter.notifyDataSetChanged(); } }; final Handler handler = new Handler() { public void handleMessage(Message msg) { //Once we've checked the data is good to use start processing it if (msg.what == 0) { OnClickListener listener = new OnClickListener() { public void onClick(View v) { //Log.i("OnClick","Clicked"); GetMoreDetails((Integer) v.getTag()); } }; OnLongClickListener listenerLong = new OnLongClickListener() { public boolean onLongClick(View v) { selectForCAB((Integer) v.getTag()); return true; } }; EnvironmentAdapter = new EnvironmentListAdaptor(getActivity().getBaseContext(), listOfEnvironments, listener, listenerLong); list = (ListView) getView().findViewById(R.id.environmentsListView); if (list != null) { if (EnvironmentAdapter != null) { list.setAdapter(EnvironmentAdapter); } else { //Log.e("EnvironmentAdapter","EnvironmentAdapter is null"); } } else { //Log.e("List","List is null"); } dialog.dismiss(); } else if (msg.what == 200) { dialog.setMessage("Sending request to Chef..."); } else if (msg.what == 201) { dialog.setMessage("Parsing JSON....."); } else if (msg.what == 202) { dialog.setMessage("Populating UI!"); } else { //Close the Progress dialog dialog.dismiss(); //Alert the user that something went terribly wrong AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create(); alertDialog.setTitle("API Error"); alertDialog.setMessage("There was an error communicating with the API:\n" + msg.getData().getString("exception")); alertDialog.setButton2("Back", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { getActivity().finish(); } }); alertDialog.setIcon(R.drawable.icon); alertDialog.show(); } } }; Thread dataPreload = new Thread() { public void run() { if (listOfEnvironments.size() > 0) { handler.sendEmptyMessage(0); } else { try { handler.sendEmptyMessage(200); Environments = Cut.GetEnvironments(); handler.sendEmptyMessage(201); JSONArray Keys = Environments.names(); for (int i = 0; i < Keys.length(); i++) { listOfEnvironments.add( new Environment(Keys.getString(i), Environments.getString(Keys.getString(i)) .replaceFirst("^(https://|http://).*/environments/", ""))); } handler.sendEmptyMessage(202); handler.sendEmptyMessage(0); } catch (Exception e) { Message msg = new Message(); Bundle data = new Bundle(); data.putString("exception", e.getMessage()); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } } return; } }; dataPreload.start(); return inflater.inflate(R.layout.environments_landing, container, false); }
From source file:com.otaupdater.SettingsActivity.java
@Override @SuppressWarnings("deprecation") public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference == accountPref) { showAccountDialog();/* www. j a v a 2 s.com*/ } else if (preference == notifPref) { cfg.setShowNotif(notifPref.isChecked()); } else if (preference == wifidlPref) { cfg.setWifiOnlyDl(wifidlPref.isChecked()); } else if (preference == autodlPref) { if (cfg.hasProKey()) { cfg.setAutoDlState(autodlPref.isChecked()); } else { Utils.showProKeyOnlyFeatureDialog(this, this); cfg.setAutoDlState(false); autodlPref.setChecked(false); } } else if (preference == resetWarnPref) { cfg.clearIgnored(); } else if (preference == prokeyPref) { if (cfg.hasProKey()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); if (cfg.isKeyRedeemCode()) { builder.setMessage(R.string.prokey_redeemed_thanks); } else { builder.setMessage(R.string.prokey_thanks); } builder.setNeutralButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } else { showGetProKeyDialog(); } } else if (preference == donatePref) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Config.SITE_BASE_URL + Config.DONATE_URL))); } else { return super.onPreferenceTreeClick(preferenceScreen, preference); } return true; }
From source file:no.ntnu.idi.socialhitchhiking.Main.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try {//from w w w.j a v a2s. co m initLoadingScreen(); new Thread() { public void run() { setConnection(Main.this); user = getApp().getUser(); if (user == null) { loginButtonClicked(); } else { initMainScreen(); if (!isSession()) { resetSession(); } } } }.start(); } catch (Exception e) { AlertDialog ad = new AlertDialog.Builder(Main.this).create(); ad.setTitle("Server error"); ad.setMessage( "The server is not responding.. Please try again later or contact the system administrator."); ad.setButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); System.exit(0); } }); ad.show(); } }
From source file:bander.notepad.NoteEditAppCompat.java
/** * Delete a note, confirm when preferred. * * @param context Context to use.//from ww w . j a v a 2 s . c om * @param uri ID of the note to delete. */ private void deleteNote(Context context, Uri uri) { final Uri noteUri = uri; SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); Boolean deleteConfirmation = preferences.getBoolean("deleteConfirmation", true); if (deleteConfirmation) { AlertDialog alertDialog = new AlertDialog.Builder(context) // .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.dialog_delete).setMessage(R.string.delete_confirmation) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { // OnClickListener public void onClick(DialogInterface dialog, int which) { getContentResolver().delete(noteUri, null, null); finish(); } }).setNegativeButton(android.R.string.cancel, null).create(); alertDialog.show(); } else { getContentResolver().delete(noteUri, null, null); finish(); } }
From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java
/** * ??Android//from ww w.j a va2 s. com * * @param exception */ private void androidException(Exception exception) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); try { throw exception; } catch (IOException e) { if (e.getMessage().startsWith("Network unreachable")) { builder.setTitle("No network"); builder.setMessage( "LGame-Android Remote needs local network access. Please make sure that your wireless network is activated. You can click on the Settings button below to directly access your network settings."); builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); } }); } else { builder.setTitle("Unknown I/O Exception"); builder.setMessage(e.getMessage().toString()); } } catch (HttpException e) { if (e.getMessage().startsWith("401")) { builder.setTitle("HTTP 401: Unauthorized"); builder.setMessage( "The supplied username and/or password is incorrect. Please check your settings."); builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent()); } }); } } catch (RuntimeException e) { builder.setTitle("RuntimeException"); builder.setMessage(e.getStackTrace().toString()); } catch (Exception e) { builder.setTitle("Exception"); builder.setMessage(e.getMessage()); } finally { exception.printStackTrace(); builder.setCancelable(true); builder.setNegativeButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); final AlertDialog alert = builder.create(); try { alert.show(); } catch (Throwable e) { } finally { LSystem.destroy(); } } }
From source file:com.dwdesign.tweetings.fragment.StatusFragment.java
protected void translate(final ParcelableStatus status) { ThreadPolicy tp = ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);//www . j ava 2 s.c o m String language = Locale.getDefault().getLanguage(); String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType=" + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language + "&text="; url = url + URLEncoder.encode(status.text_plain); try { HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(new HttpGet(url)); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } String finalString = s.toString(); finalString = finalString .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", ""); finalString = finalString.replace("</string>", ""); AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); builder.setTitle(getString(R.string.translate)); builder.setMessage(finalString); builder.setCancelable(true); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }