List of usage examples for android.app AlertDialog.Builder setCancelable
public void setCancelable(boolean flag)
From source file:com.xrmaddness.offthegrid.ListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: Intent intent = new Intent(this, SettingsActivity.class); startActivityForResult(intent, SETTINGS_DONE); return true; case R.id.action_my_fingerprint: { String fingerprint;//from ww w. j a va 2s . co m if (pgp == null) { fingerprint = "No keys available, fill in email address first in settings"; } else { fingerprint = pgp.fingerprint(pgp.my_user_id); if (fingerprint == null) { fingerprint = "No key found"; } } AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setMessage(fingerprint); alert.setTitle(R.string.action_my_fingerprint); alert.setPositiveButton("OK", null); alert.setCancelable(true); alert.create().show(); return true; } case R.id.action_add_contact: { if (pgp == null) return true; AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.action_add_contact); alert.setMessage(R.string.dialog_add_contact); // Set an EditText view to get user input final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); Log.d("add_contact", value); add_contact(value); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alert.show(); return true; } case R.id.action_add_group: { if (pgp == null) return true; AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.action_add_group); alert.setMessage(R.string.dialog_add_group); // Set an EditText view to get user input final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); Log.d("add_group", value); add_group(value); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alert.show(); return true; } case R.id.action_show_license: { String license = version_get() + "\n"; AssetManager am = getAssets(); InputStream is; try { is = am.open("license.txt"); license += filestring.is2str(is); is.close(); is = am.open("spongycastle_license.txt"); license += filestring.is2str(is); is.close(); is = am.open("javamail_license.txt"); license += filestring.is2str(is); is.close(); } catch (IOException e) { Log.e("show license", e.getMessage()); } AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setMessage(license); alert.setTitle(R.string.action_show_license); alert.setPositiveButton("OK", null); alert.setCancelable(true); alert.create().show(); return true; } default: return super.onOptionsItemSelected(item); } }
From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java
@Override public void onUpdateCheckCompleted(UpdateManager manager, final Update update) { final AlertDialog.Builder builder = new AlertDialog.Builder(activity); if (update.forceExit) { builder.setTitle(R.string.service_is_not_available); } else if (update.forceUpdate) { builder.setTitle(R.string.update_required); } else {/*from w w w. ja v a2s . c om*/ builder.setTitle(R.string.update_found); } final View dialogContentsView = createUpdatesFoundDialogContentsView(update); builder.setView(dialogContentsView); initializeUpdatesFoundDialogButtons(builder, update); builder.setCancelable(false); final AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:com.xrmaddness.offthegrid.ListActivity.java
void warn_remove_self() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.action_remove_self); alert.setMessage(getString(R.string.dialog_remove_self)); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { }// w w w.j a va 2 s. c o m }); alert.setCancelable(true); alert.show(); }
From source file:org.openhab.habdroid.ui.OpenHABDiscoveryInboxFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { selectedInbox = position; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setPositiveButton(R.string.app_discoveryinbox_approve, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { sendInboxApprove(mDiscoveryInboxAdapter.getItem(selectedInbox).getThingUID()); }/*from w w w . ja va 2 s .com*/ }); builder.setNeutralButton(R.string.app_discoveryinbox_ignore, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { sendInboxIgnore(mDiscoveryInboxAdapter.getItem(selectedInbox).getThingUID()); } }); builder.setNegativeButton(R.string.app_discoveryinbox_delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { sendInboxDelete(mDiscoveryInboxAdapter.getItem(selectedInbox).getThingUID()); } }); builder.setCancelable(true); builder.setTitle(R.string.app_discoveryinbox_deviceaction); builder.show(); }
From source file:com.owncloud.android.ui.activity.ReceiveExternalFilesActivity.java
@Override protected Dialog onCreateDialog(final int id) { final AlertDialog.Builder builder = new Builder(this); switch (id) { case DIALOG_NO_ACCOUNT: builder.setIcon(R.drawable.ic_warning); builder.setTitle(R.string.uploader_wrn_no_account_title); builder.setMessage(/*from w ww. j a v a 2 s . c om*/ String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name))); builder.setCancelable(false); builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) { // using string value since in API7 this // constatn is not defined // in API7 < this constatant is defined in // Settings.ADD_ACCOUNT_SETTINGS // and Settings.EXTRA_AUTHORITIES Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() }); startActivityForResult(intent, REQUEST_CODE__SETUP_ACCOUNT); } else { // since in API7 there is no direct call for // account setup, so we need to // show our own AccountSetupAcricity, get // desired results and setup // everything for ourself Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class); startActivityForResult(intent, REQUEST_CODE__SETUP_ACCOUNT); } } }); builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); case DIALOG_MULTIPLE_ACCOUNT: Account accounts[] = mAccountManager.getAccountsByType(MainApp.getAccountType()); CharSequence dialogItems[] = new CharSequence[accounts.length]; OwnCloudAccount oca; for (int i = 0; i < dialogItems.length; ++i) { try { oca = new OwnCloudAccount(accounts[i], this); dialogItems[i] = oca.getDisplayName() + " @ " + DisplayUtils .convertIdn(accounts[i].name.substring(accounts[i].name.lastIndexOf("@") + 1), false); } catch (Exception e) { Log_OC.w(TAG, "Couldn't read display name of account; using account name instead"); dialogItems[i] = DisplayUtils.convertIdn(accounts[i].name, false); } } builder.setTitle(R.string.common_choose_account); builder.setItems(dialogItems, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]); onAccountSet(mAccountWasRestored); dialog.dismiss(); mAccountSelected = true; mAccountSelectionShowing = false; } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mAccountSelectionShowing = false; dialog.cancel(); finish(); } }); return builder.create(); default: throw new IllegalArgumentException("Unknown dialog id: " + id); } }
From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId())); }/*from ww w . j ava 2s . c om*/ final AlertDialog.Builder builder = new AlertDialog.Builder(this); View v; ListViewHolder viewHolder; AdapterView.AdapterContextMenuInfo contextInfo; String app_name; final String package_name; switch (item.getItemId()) { case R.id.btnUncheckAll: builder.setTitle(R.string.dialog_confirm_title); builder.setMessage(getString(R.string.dialog_uncheck_message)); builder.setCancelable(false); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (lvPackages == null || lvPackages.getAdapter() == null || ((packageAdapter) lvPackages.getAdapter()).selected == null) { //something went wrong return; } ((packageAdapter) lvPackages.getAdapter()).selected.clear(); lvPackages.invalidateViews(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { //do nothing! } }); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.show(); return true; case R.id.btnSave: finish(); return true; case R.id.btnDonate: Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(Constants.DONATION_URL)); startActivity(i); return true; case R.id.btnSettings: Intent settings = new Intent(this, SettingsActivity.class); startActivity(settings); return true; case R.id.btnRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int position = contextInfo.position; long id = contextInfo.id; // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle(R.string.dialog_title_rename_notification); final EditText input = new EditText(this); input.setHint(app_name); builder.setView(input); builder.setPositiveButton(R.string.confirm, null); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); if (b != null) { b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //can't be nothing if (input.getText().length() > 0) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Adding rename for " + package_name + " to " + input.getText()); } JSONObject rename = new JSONObject(); try { rename.put("pkg", package_name); rename.put("to", input.getText()); arrayRenames.put(rename); } catch (JSONException e) { e.printStackTrace(); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); d.dismiss(); } else { input.setText(R.string.error_cant_be_blank); } } }); } } }); d.show(); return true; case R.id.btnRemoveRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null"); } //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle( getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?"); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length())); } JSONArray tmp = new JSONArray(); try { for (int i = 0; i < arrayRenames.length(); i++) { if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) { tmp.put(arrayRenames.getJSONObject(i)); } } } catch (JSONException e) { e.printStackTrace(); } arrayRenames = tmp; if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length())); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); builder.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.nexes.manager.EventHandler.java
/** * This method, handles the button presses of the top buttons found in the * Main activity./* w w w . jav a2 s . com*/ */ @Override public void onClick(View v) { switch (v.getId()) { case R.id.back_button: if (mFileMang.getCurrentDir() != "/") { if (multi_select_flag) { mDelegate.killMultiSelect(true); Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show(); } stopThumbnailThread(); updateDirectory(mFileMang.getPreviousDir()); if (mPathLabel != null) mPathLabel.setText(mFileMang.getCurrentDir()); } break; case R.id.home_button: if (multi_select_flag) { mDelegate.killMultiSelect(true); Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show(); } stopThumbnailThread(); updateDirectory(mFileMang.setHomeDir("/sdcard")); if (mPathLabel != null) mPathLabel.setText(mFileMang.getCurrentDir()); break; case R.id.info_button: Intent info = new Intent(mContext, DirectoryInfo.class); info.putExtra("PATH_NAME", mFileMang.getCurrentDir()); mContext.startActivity(info); break; case R.id.help_button: Intent help = new Intent(mContext, HelpManager.class); mContext.startActivity(help); break; case R.id.manage_button: display_dialog(MANAGE_DIALOG); break; case R.id.multiselect_button: if (multi_select_flag) { mDelegate.killMultiSelect(true); } else { LinearLayout hidden_lay = (LinearLayout) ((Activity) mContext).findViewById(R.id.hidden_buttons); multi_select_flag = true; hidden_lay.setVisibility(LinearLayout.VISIBLE); } break; /* * three hidden buttons for multiselect */ case R.id.hidden_attach: /* check if user selected objects before going further */ if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); break; } ArrayList<Uri> uris = new ArrayList<Uri>(); int length = mMultiSelectData.size(); Intent mail_int = new Intent(); mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE); mail_int.setType("application/mail"); mail_int.putExtra(Intent.EXTRA_BCC, ""); mail_int.putExtra(Intent.EXTRA_SUBJECT, " "); for (int i = 0; i < length; i++) { File file = new File(mMultiSelectData.get(i)); uris.add(Uri.fromFile(file)); } mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); mContext.startActivity(Intent.createChooser(mail_int, "Email using...")); mDelegate.killMultiSelect(true); break; case R.id.hidden_move: case R.id.hidden_copy: /* check if user selected objects before going further */ if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); break; } if (v.getId() == R.id.hidden_move) delete_after_copy = true; mInfoLabel.setText("Holding " + mMultiSelectData.size() + " file(s)"); mDelegate.killMultiSelect(false); break; case R.id.hidden_delete: /* check if user selected objects before going further */ if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); break; } final String[] data = new String[mMultiSelectData.size()]; int at = 0; for (String string : mMultiSelectData) data[at++] = string; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage( "Are you sure you want to delete " + data.length + " files? This cannot be " + "undone."); builder.setCancelable(false); builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new BackgroundWork(DELETE_TYPE).execute(data); mDelegate.killMultiSelect(true); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mDelegate.killMultiSelect(true); dialog.cancel(); } }); builder.create().show(); break; } }
From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java
public void openDialog() { // get prompts.xml view LayoutInflater li = LayoutInflater.from(GetAllVehicalDetails.this); View promptsView = li.inflate(R.layout.prompt, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(GetAllVehicalDetails.this); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(promptsView); alertDialogBuilder.setTitle("Why you want to stop this"); final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to result // edit text //result.setText(userInput.getText()); if (!userInput.getText().toString().trim().isEmpty()) { reason = userInput.getText().toString().trim(); getUserData(reason);/*from ww w. j a va2 s. c om*/ } else { Toast.makeText(GetAllVehicalDetails.this, "Please fill your reason", Toast.LENGTH_LONG).show(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:com.Duo.music.player.Dialogs.GooglePlayMusicAuthenticationDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { parentActivity = getActivity();//from w ww . j a v a 2 s.c om AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); sharedPreferences = parentActivity.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE); View rootView = parentActivity.getLayoutInflater().inflate(R.layout.dialog_google_authentication_layout, null); //Check if this dialog was called from the Welcome sequence. mFirstRun = getArguments().getBoolean(Common.FIRST_RUN); infoText = (TextView) rootView.findViewById(R.id.google_authentication_dialog_text); infoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); infoText.setPaintFlags(infoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext()); final Account[] accounts = accountManager.getAccountsByType("com.google"); final int size = accounts.length; String[] accountNames = new String[size]; for (int i = 0; i < size; i++) { accountNames[i] = accounts[i].name; } //Set the dialog title. builder.setTitle(R.string.sign_in_google_play_music); builder.setCancelable(false); builder.setItems(accountNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { account = accounts[which]; sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit(); AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask( parentActivity.getApplicationContext(), parentActivity, mFirstRun, account.name); task.execute(); } }); return builder.create(); }
From source file:com.jelly.music.player.Dialogs.GooglePlayMusicAuthenticationDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { parentActivity = getActivity();//w w w .j a va2s .c o m AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); sharedPreferences = parentActivity.getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE); View rootView = parentActivity.getLayoutInflater().inflate(R.layout.dialog_google_authentication_layout, null); //Check if this dialog was called from the Welcome sequence. mFirstRun = getArguments().getBoolean(Common.FIRST_RUN); infoText = (TextView) rootView.findViewById(R.id.google_authentication_dialog_text); infoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); infoText.setPaintFlags(infoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext()); final Account[] accounts = accountManager.getAccountsByType("com.google"); final int size = accounts.length; String[] accountNames = new String[size]; for (int i = 0; i < size; i++) { accountNames[i] = accounts[i].name; } //Set the dialog title. builder.setTitle(R.string.sign_in_google_play_music); builder.setCancelable(false); builder.setItems(accountNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { account = accounts[which]; sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit(); AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask( parentActivity.getApplicationContext(), parentActivity, mFirstRun, account.name); task.execute(); } }); return builder.create(); }