List of usage examples for android.app AlertDialog.Builder show
public void show()
From source file:com.myandroidremote.AccountsActivity.java
/** * Sets up the 'connect' screen content. */// ww w.j av a 2s . c o m private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { showLoadingScreen(); } }); builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Register in the background and terminate the activity mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); register((String) account.getText()); // show connecting showLoadingScreen(); } }); final Button exitButton = (Button) findViewById(R.id.exit); exitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); } }
From source file:bluetoothchat.BluetoothChatFragment.java
/** * Function to display simple Alert Dialog * @param title - alert dialog title// w ww .j a v a2 s . com * @param message - alert message * @param status - success/failure (used to set icon) * */ public void showAlertDialog(String title, String message, Boolean status) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle); builder.setTitle(title); builder.setMessage(message); builder.setPositiveButton("OK", null); // Setting Dialog Message builder.setMessage(message); // Setting alert dialog icon builder.setIcon((status) ? R.drawable.success : R.drawable.fail); builder.show(); }
From source file:com.irccloud.android.activity.UploadsActivity.java
public void onIRCEvent(int what, Object o) { IRCCloudJSONObject obj;//from w w w. j av a2 s . co m final File f; switch (what) { case NetworkConnection.EVENT_SUCCESS: obj = (IRCCloudJSONObject) o; f = delete_reqids.get(obj.getInt("_reqid")); if (f != null) { Log.d("IRCCloud", "File deleted successfully"); delete_reqids.remove(obj.getInt("_reqid")); runOnUiThread(new Runnable() { @Override public void run() { adapter.removeFile(f); View.OnClickListener undo = new View.OnClickListener() { @Override public void onClick(View view) { NetworkConnection.getInstance().restoreFile(f.id); adapter.restoreFile(f); } }; if (f.name != null && f.name.length() > 0) Snackbar.make(findViewById(android.R.id.list), f.name + " was deleted.", Snackbar.LENGTH_LONG).setAction("UNDO", undo).show(); else Snackbar.make(findViewById(android.R.id.list), "File was deleted.", Snackbar.LENGTH_LONG).setAction("UNDO", undo).show(); } }); } break; case NetworkConnection.EVENT_FAILURE_MSG: obj = (IRCCloudJSONObject) o; f = delete_reqids.get(obj.getInt("_reqid")); if (f != null) { delete_reqids.remove(obj.getInt("_reqid")); Crashlytics.log(Log.ERROR, "IRCCloud", "Delete failed: " + obj.toString()); runOnUiThread(new Runnable() { @Override public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this); builder.setTitle("Error"); if (f.name != null && f.name.length() > 0) builder.setMessage("Unable to delete '" + f.name + "'. Please try again shortly."); else builder.setMessage("Unable to delete file. Please try again shortly."); builder.setPositiveButton("Close", null); builder.show(); f.deleting = false; adapter.notifyDataSetChanged(); } }); } break; default: break; } }
From source file:study.tdcc.act.MainCalendar.java
/** * ?yes/no?// w ww . j a v a 2 s . com * * @param context * @param titleMsg * @param mainMsg * @param listener */ private static void showYesNoDialog(Context context, int titleMsg, int mainMsg, DialogInterface.OnClickListener listener) { Log.d("DEBUG", "MainCalendar showYesNoDialog Start"); AlertDialog.Builder ad = new AlertDialog.Builder(context); ad.setTitle(titleMsg); ad.setMessage(mainMsg); ad.setPositiveButton(R.string.yes_btn, listener); ad.setNegativeButton(R.string.no_btn, listener); ad.show(); Log.d("DEBUG", "MainCalendar showYesNoDialog End"); }
From source file:me.henrytao.bootstrapandroidlibrarydemo.activity.BaseActivity.java
private void showDonateDialogSuccessCallback(final List<PurchaseItem> data) { PurchaseAdapter adapter = new PurchaseAdapter(this, data); AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.text_donate) .setCancelable(false).setAdapter(adapter, new DialogInterface.OnClickListener() { @Override// ww w . j a v a 2 s . co m public void onClick(DialogInterface dialog, int which) { onDonate(data.get(which)); } }).setPositiveButton(R.string.text_close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new AlertDialog.Builder(BaseActivity.this) .setMessage(getString(R.string.text_donate_help_offer)) .setPositiveButton(R.string.text_close, null).show(); } }); builder.show(); }
From source file:app.socialgps.ui.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(menuItems[position]);//from ww w. j av a2s. co m mDrawerLayout.closeDrawer(mDrawerList); // Fragment mapfragment = new MapsFragment(); // MapsFragment defined at top FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); switch (position) { case 0: // googleMap = (GoogleMap) mapFragment.getMap(); MapsFragment mf = new MapsFragment(); ft.replace(R.id.content_frame, mf).commit(); break; case 1: FriendListFragment flf = new FriendListFragment(); // Toast.makeText(getApplicationContext(), // "Yet to design Contacts view", Toast.LENGTH_LONG).show(); ft.replace(R.id.content_frame, flf).commit(); break; case 2: ContactListFragment clf = new ContactListFragment(); // Toast.makeText(getApplicationContext(), // "Yet to design Contacts view", Toast.LENGTH_LONG).show(); ft.replace(R.id.content_frame, clf).commit(); break; case 3: AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("Logout"); alertDialog.setMessage("Are you sure you want Logout?"); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { d = new DatabaseHandler(getApplicationContext()); Toast.makeText(getApplicationContext(), " logged out " + d.truncate(), Toast.LENGTH_SHORT) .show(); finish(); } }); // Showing Alert Message alertDialog.show(); break; // comment } }
From source file:falcofinder.android.fuehrerschein.chat.AccountsActivity.java
/** * Sets up the 'connect' screen content. *//*from ww w. j ava2s . c o m*/ private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); /* * rimuovo aggiunta account perche' disponible da versione 2.2 * ma voglio compatibilita' con 2.1 builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); */ builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Set "connecting" status SharedPreferences prefs = Util.getSharedPreferences(mContext); prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit(); // Get account name mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); // Register register((String) account.getText()); finish(); } }); } }
From source file:ca.ualberta.cmput301.t03.inventory.AddItemView.java
/** * When the upload photos button is clicked an alert dialog will get created asking the * user if they want to upload a photo or take a photo, either option will result in a returned * bitmap which is handled in onActivityResult. * * Code used://from ww w. j a v a 2s .co m * http://stackoverflow.com/questions/27874038/how-to-make-intent-chooser-for-camera-or-gallery-application-in-android-like-wha */ private void onUploadPhotosButtonClicked() { final CharSequence[] items = { "Take A Photo", "Choose Photo from Gallery" }; AlertDialog.Builder builder = new AlertDialog.Builder(AddItemView.this); builder.setTitle("Attach Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item == 0) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } else if (item == 1) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } } }); builder.show(); }
From source file:ca.zadrox.dota2esportticker.ui.MatchActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intentx;//from ww w .j av a 2 s . c o m switch (item.getItemId()) { case R.id.menu_refresh: setRefreshingState(true); onRefresh(); break; case R.id.menu_debug_notify: intentx = new Intent(ReminderAlarmService.ACTION_NOTIFY_DEBUG); intentx.setClass(this, ReminderAlarmService.class); this.startService(intentx); return true; case R.id.menu_debug_view_live_match: final Intent intent = new Intent(this, LiveGameStatsActivity.class); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLL, (String) null); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLR, (String) null); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_BO, "best of 1"); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNL, "Invasion"); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNR, "Koopa"); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TN, "awesome"); final Context mContext = this; AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Enter Match Id:"); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { intent.putExtra(LiveGameStatsActivity.ARGS_GAME_MID, Long.parseLong(input.getText().toString())); mContext.startActivity(intent); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alert.show(); return true; } return super.onOptionsItemSelected(item); }
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. j ava2 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); }