List of usage examples for android.app AlertDialog setCancelable
public void setCancelable(boolean flag)
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayUploadResultDialog(Bundle extras) { int descriptionId = extras.getInt(UploaderService.INTENT_KEY_RESULT_DESCRIPTION); try {//from w ww . java 2 s . c o m String descriptionContent = getString(descriptionId); Log.d("displayUploadResultDialog(): Received extras: %s", descriptionId); // display dialog AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.uploader_result_dialog_title); alertDialog.setMessage(descriptionContent); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } catch (NotFoundException ex) { Log.w("displayUploadResultDialog(): Invalid string id received with intent extras: %s", descriptionId); MyApplication.getAnalytics().sendException(ex, Boolean.FALSE); ACRA.getErrorReporter().handleSilentException(ex); } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayNewVersionDownloadOptions(Bundle extras) { UpdateInfo updateInfo = (UpdateInfo) extras.getSerializable(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO); // display dialog AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View dialogLayout = inflater.inflate(R.layout.new_version, null); dialogBuilder.setView(dialogLayout); final AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.updater_dialog_new_version_available); // load data// ww w. j a v a 2 s .c om ArrayAdapter<UpdateInfo.DownloadLink> adapter = new UpdateDialogArrayAdapter(alertDialog.getContext(), inflater, updateInfo.getDownloadLinks()); ListView listView = (ListView) dialogLayout.findViewById(R.id.download_options_list); listView.setAdapter(adapter); // bind events final CheckBox disableAutoUpdateCheckCheckbox = (CheckBox) dialogLayout .findViewById(R.id.download_options_disable_auto_update_check_checkbox); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { DownloadLink downloadLink = (DownloadLink) parent.getItemAtPosition(position); Log.d("displayNewVersionDownloadOptions(): Selected position: %s", downloadLink.getLabel()); boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked(); Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s", disableAutoUpdateCheckCheckboxChecked); if (disableAutoUpdateCheckCheckboxChecked) { MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false); } MyApplication.getAnalytics().sendUpdateAction(downloadLink.getLabel()); String link = downloadLink.getLink(); try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link))); } catch (ActivityNotFoundException ex) { Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show(); } alertDialog.dismiss(); } }); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked(); Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s", disableAutoUpdateCheckCheckboxChecked); if (disableAutoUpdateCheckCheckboxChecked) { MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false); } } }); alertDialog.show(); }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayNotCompatibleDialog() { // check if displayed in this app run if (showNotCompatibleDialog) { // check if not disabled in preferences boolean showCompatibilityWarningEnabled = MyApplication.getPreferencesProvider() .getShowCompatibilityWarning(); if (showCompatibilityWarningEnabled) { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // check if device contains telephony hardware (some tablets doesn't report even if have) // NOTE: in the future this may need to be expanded when new specific features appear PackageManager packageManager = getPackageManager(); boolean noRadioDetected = !(packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_GSM) || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA))); // show dialog if something is not supported if (noRadioDetected) { Log.d("displayNotCompatibleDialog(): Not compatible because of radio: %s, phone type: %s", noRadioDetected, telephonyManager.getPhoneType()); //use custom layout to show "don't show this again" checkbox AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View dialogLayout = inflater.inflate(R.layout.dont_show_again_dialog, null); final CheckBox dontShowAgainCheckbox = (CheckBox) dialogLayout .findViewById(R.id.dont_show_again_dialog_checkbox); dialogBuilder.setView(dialogLayout); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.main_dialog_not_compatible_title); StringBuilder stringBuilder = new StringBuilder( getString(R.string.main_dialog_not_compatible_begin)); if (noRadioDetected) { stringBuilder.append(getString(R.string.main_dialog_no_compatible_mobile_radio_message)); }//w ww .ja v a 2s . c o m // text set this way to prevent checkbox from disappearing when text is too long TextView messageTextView = (TextView) dialogLayout .findViewById(R.id.dont_show_again_dialog_textview); messageTextView.setText(stringBuilder.toString()); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean dontShowAgainCheckboxChecked = dontShowAgainCheckbox.isChecked(); Log.d("displayNotCompatibleDialog(): Don't show again checkbox checked = %s", dontShowAgainCheckboxChecked); if (dontShowAgainCheckboxChecked) { MyApplication.getPreferencesProvider().setShowCompatibilityWarning(false); } } }); alertDialog.show(); } } showNotCompatibleDialog = false; } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void startUploaderServiceWithCheck() { String runningTaskClassName = MyApplication.getBackgroundTaskName(); if (runningTaskClassName != null) { Log.d("startUploaderService(): Another task is running in background: %s", runningTaskClassName); backgroundTaskHelper.showTaskRunningMessage(runningTaskClassName); return;/* w ww . j a va 2 s .c o m*/ } // check API key String apiKey = MyApplication.getPreferencesProvider().getApiKey(); if (!Validator.isOpenCellIdApiKeyValid(apiKey)) { final String apiKeyLocal = apiKey; AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); if (StringUtils.isNullEmptyOrWhitespace(apiKey)) { alertDialog.setTitle(R.string.main_dialog_api_key_empty_title); alertDialog.setMessage(getString(R.string.main_dialog_api_key_empty_message)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_register), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.preferences_opencellid_org_sign_up_link))); startActivity(browserIntent); } catch (ActivityNotFoundException ex) { Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show(); } } }); } else { alertDialog.setTitle(R.string.main_dialog_api_key_invalid_title); alertDialog.setMessage(getString(R.string.main_dialog_api_key_invalid_message)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_upload), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startUploaderService(apiKeyLocal); } }); } alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.dialog_enter_api_key), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startPreferencesActivity(); } }); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); return; } else { startUploaderService(apiKey); } }
From source file:at.alladin.rmbt.android.loopmode.LoopModeTestFragment.java
public boolean onBackPressed() { if (loopService == null) { return false; }//ww w .j a va 2s . co m else if (loopService.isRunning() || (loopService.getLoopModeResults().getMaxTests() > loopService .getLoopModeResults().getNumberOfTests())) { AlertDialog stopDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.test_dialog_abort_title).setMessage(R.string.loop_mode_test_dialog_abort) .setPositiveButton(android.R.string.yes, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { stopLoopService(); ((RMBTMainActivity) getActivity()).popBackStackFull(); } }).setNegativeButton(android.R.string.no, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); stopDialog.setCancelable(false); stopDialog.show(); } else if (loopService.getLoopModeResults().getMaxTests() <= loopService.getLoopModeResults() .getNumberOfTests()) { //if max tests is reached simply remove this fragment without alert dialog stopLoopService(); return false; } return true; }
From source file:org.odk.collect.android.activities.FormHierarchyActivity.java
/** * Creates and displays dialog with the given errorMsg. *///from w ww.j ava 2 s. c o m private void createErrorDialog(String errorMsg) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "createErrorDialog", "show."); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_info); alertDialog.setTitle(getString(R.string.error_occured)); alertDialog.setMessage(errorMsg); DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { switch (i) { case DialogInterface.BUTTON_POSITIVE: Collect.getInstance().getActivityLogger().logInstanceAction(this, "createErrorDialog", "OK"); FormController formController = Collect.getInstance().getFormController(); formController.jumpToIndex(currentIndex); break; } } }; alertDialog.setCancelable(false); alertDialog.setButton(getString(R.string.ok), errorListener); alertDialog.show(); }
From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java
private void showNotConnectedDialog(final Dialog dialog) { AlertDialog notConnectedAlert = new AlertDialog.Builder(SettingsActivity.this) .setMessage(R.string.sett_dialog_notConnected_message) .setPositiveButton(R.string.sett_yes, new DialogInterface.OnClickListener() { @Override// w w w . j a v a2s . c om public void onClick(DialogInterface dialogInterface, int i) { dialog.dismiss(); dialogInterface.dismiss(); } }).setNegativeButton(R.string.sett_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); dialog.show(); } }).create(); notConnectedAlert.getWindow().setGravity(Gravity.CENTER); notConnectedAlert.setCancelable(false); notConnectedAlert.show(); }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void startNetworkTypeSystemActivity() { try {/* ww w. j a va2 s . c o m*/ startActivity(createDataRoamingSettingsIntent()); } catch (ActivityNotFoundException ex) { Log.w("askAndSetGpsEnabled(): Could not open Settings to change network type", ex); MyApplication.getAnalytics().sendException(ex, Boolean.FALSE); ACRA.getErrorReporter().handleSilentException(ex); AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this) .setMessage(R.string.dialog_could_not_open_network_type_settings) .setPositiveButton(R.string.dialog_ok, null).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.show(); } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
public void displayHelpOnClick(View view) { int titleId = View.NO_ID; int messageId = View.NO_ID; switch (view.getId()) { case R.id.main_gps_status_tablerow: titleId = R.string.main_help_gps_status_title; messageId = R.string.main_help_gps_status_description; break;/*www . java 2 s . com*/ case R.id.main_invalid_system_time_tablerow: titleId = R.string.main_help_invalid_system_time_title; messageId = R.string.main_help_invalid_system_time_description; break; case R.id.main_stats_today_locations_tablerow: titleId = R.string.main_help_today_locations_title; messageId = R.string.main_help_today_locations_description; break; case R.id.main_stats_today_cells_tablerow: titleId = R.string.main_help_today_cells_title; messageId = R.string.main_help_today_cells_description; break; case R.id.main_stats_local_locations_tablerow: titleId = R.string.main_help_local_locations_title; messageId = R.string.main_help_local_locations_description; break; case R.id.main_stats_local_cells_tablerow: titleId = R.string.main_help_local_cells_title; messageId = R.string.main_help_local_cells_description; break; case R.id.main_stats_global_locations_tablerow: titleId = R.string.main_help_global_locations_title; messageId = R.string.main_help_global_locations_description; break; case R.id.main_stats_global_cells_tablerow: titleId = R.string.main_help_global_cells_title; messageId = R.string.main_help_global_cells_description; break; case R.id.main_last_network_type_tablerow: titleId = R.string.main_help_last_network_type_title; messageId = R.string.main_help_last_network_type_description; break; case R.id.main_last_cell_id_tablerow: titleId = R.string.main_help_last_cell_id_title; messageId = R.string.main_help_last_cell_id_description; break; case R.id.main_last_lac_tablerow: titleId = R.string.main_help_last_lac_title; messageId = R.string.main_help_last_lac_description; break; case R.id.main_last_mcc_tablerow: titleId = R.string.main_help_last_mcc_title; messageId = R.string.main_help_last_mcc_description; break; case R.id.main_last_mnc_tablerow: titleId = R.string.main_help_last_mnc_title; messageId = R.string.main_help_last_mnc_description; break; case R.id.main_last_signal_strength_tablerow: titleId = R.string.main_help_last_signal_strength_title; messageId = R.string.main_help_last_signal_strength_description; break; case R.id.main_last_latitude_tablerow: titleId = R.string.main_help_last_latitude_title; messageId = R.string.main_help_last_latitude_description; break; case R.id.main_last_longitude_tablerow: titleId = R.string.main_help_last_longitude_title; messageId = R.string.main_help_last_longitude_description; break; case R.id.main_last_gps_accuracy_tablerow: titleId = R.string.main_help_last_gps_accuracy_title; messageId = R.string.main_help_last_gps_accuracy_description; break; case R.id.main_last_date_time_tablerow: titleId = R.string.main_help_last_date_time_title; messageId = R.string.main_help_last_date_time_description; break; } Log.d("displayHelpOnClick(): Displaying help for title: %s", titleId); if (titleId != View.NO_ID && messageId != View.NO_ID) { AlertDialog dialog = new AlertDialog.Builder(this).setTitle(titleId).setMessage(messageId) .setPositiveButton(R.string.dialog_ok, null).create(); dialog.setCanceledOnTouchOutside(true); dialog.setCancelable(true); dialog.show(); } }
From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java
/****************************************************************************************************************** * ALERT DIALOG//from ww w. j a v a2 s .com *****************************************************************************************************************/ private void showAlertDialog(JSONObject data, final String callback) { try { String title = data.optString(Cobalt.kJSAlertTitle); String message = data.optString(Cobalt.kJSMessage); boolean cancelable = data.optBoolean(Cobalt.kJSAlertCancelable, false); JSONArray buttons = data.has(Cobalt.kJSAlertButtons) ? data.getJSONArray(Cobalt.kJSAlertButtons) : new JSONArray(); AlertDialog alertDialog = new AlertDialog.Builder(mContext).setTitle(title).setMessage(message) .create(); alertDialog.setCancelable(cancelable); if (buttons.length() == 0) { alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (callback != null) { try { JSONObject data = new JSONObject(); data.put(Cobalt.kJSAlertButtonIndex, 0); sendCallback(callback, data); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + ".AlertDialog - onClick: JSONException"); exception.printStackTrace(); } } } }); } else { int buttonsLength = Math.min(buttons.length(), 3); for (int i = 0; i < buttonsLength; i++) { int buttonId; switch (i) { case 0: default: buttonId = DialogInterface.BUTTON_NEGATIVE; break; case 1: buttonId = DialogInterface.BUTTON_NEUTRAL; break; case 2: buttonId = DialogInterface.BUTTON_POSITIVE; break; } alertDialog.setButton(buttonId, buttons.getString(i), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (callback != null) { int buttonIndex; switch (which) { case DialogInterface.BUTTON_NEGATIVE: default: buttonIndex = 0; break; case DialogInterface.BUTTON_NEUTRAL: buttonIndex = 1; break; case DialogInterface.BUTTON_POSITIVE: buttonIndex = 2; break; } try { JSONObject data = new JSONObject(); data.put(Cobalt.kJSAlertButtonIndex, buttonIndex); sendCallback(callback, data); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + ".AlertDialog - onClick: JSONException"); exception.printStackTrace(); } } } }); } } alertDialog.show(); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - showAlertDialog: JSONException"); exception.printStackTrace(); } }