List of usage examples for android.app AlertDialog setCanceledOnTouchOutside
public void setCanceledOnTouchOutside(boolean cancel)
From source file:produvia.com.scanner.DevicesActivity.java
public void promptLogin(final JSONObject loginService, final JSONObject responseData) { runOnUiThread(new Runnable() { public void run() { try { String type = loginService.getString("type"); //there was a login error. login again if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) { //prompt for username and password and retry: promptUsernamePassword(loginService, responseData, false, null); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) { promptUsernamePassword(loginService, responseData, true, loginService.getString("description")); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) { //prompt for username and password and retry: int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout") : 15;// www. j a v a 2s .c om final AlertDialog alertDialog = new AlertDialog.Builder(DevicesActivity.this).create(); alertDialog.setTitle(loginService.getString("description")); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + countdown + " seconds..."); alertDialog.show(); // new CountDownTimer(countdown * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { try { alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + millisUntilFinished / 1000 + " seconds..."); } catch (JSONException e) { } } @Override public void onFinish() { alertDialog.dismiss(); new Thread(new Runnable() { public void run() { try { JSONArray services = new JSONArray(); services.put(loginService); responseData.put("services", services); WeaverSdkApi.servicesSet(DevicesActivity.this, responseData); } catch (JSONException e) { } } }).start(); } }.start(); } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:com.flipzu.flipzu.ListingsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mFrom = null;/*w w w. j av a 2 s .co m*/ /* init Google Analytics tracker */ initGATracker(); /* event notifier */ if (mListType == fi.FRIENDS) { this.setEmptyText(getText(R.string.loading)); EventNotifier.getInstance().setEventFriends(this); } else if (mListType == fi.ALL) { this.setEmptyText(getText(R.string.loading)); EventNotifier.getInstance().setEventAll(this); } else if (mListType == fi.PROFILE) { this.setEmptyText(getText(R.string.loading)); EventNotifier.getInstance().setEventProfile(this); } else if (mListType == fi.USER) { this.setEmptyText(getText(R.string.loading)); EventNotifier.getInstance().setEventUser(this); } else if (mListType == fi.HOTTEST) { this.setEmptyText(getText(R.string.loading)); EventNotifier.getInstance().setEventHot(this); } else if (mListType == fi.SEARCH) { this.setEmptyText(""); EventNotifier.getInstance().setEventSearch(this); } /* restore settings object */ settings = getSupportActivity().getApplicationContext().getSharedPreferences(PREFS_NAME, 0); if (savedInstanceState != null && mListType == fi.USER) { String username = savedInstanceState.getString("mUser"); String token = settings.getString("token", null); AsyncFlipInterface.getUser(username, token, this); } mBcasts = new ArrayList<BroadcastDataSet>(); if (mListType == fi.USER) { this.mAdapter = new BcastAdapter(getSupportActivity().getApplicationContext(), R.layout.bcast_row_user, mBcasts); } else { this.mAdapter = new BcastAdapter(getSupportActivity().getApplicationContext(), R.layout.bcast_row, mBcasts); } setListAdapter(this.mAdapter); refreshListing(); getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (mListType == fi.PROFILE) { final CharSequence[] items = { getString(R.string.delete_broadcast) }; final int pos = position; AlertDialog.Builder builder = new AlertDialog.Builder(parent.getContext()); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String id = mBcasts.get(pos).getId(); deleteBroadcast(id); } }); AlertDialog alert = builder.create(); alert.setCanceledOnTouchOutside(true); alert.show(); return true; } return true; } }); getListView().setOnScrollListener(this); }
From source file:com.kkbox.toolkit.dialog.KKDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { DialogInterface.OnClickListener positiveListener = new DialogInterface.OnClickListener() { @Override/*from w w w. ja v a 2 s .co m*/ public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onPositive(); } onDialogFinishedByUser(); isDismissed = true; } } }; DialogInterface.OnClickListener neutralListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onNeutral(); } onDialogFinishedByUser(); isDismissed = true; } } }; DialogInterface.OnClickListener negativeListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onNegative(); } onDialogFinishedByUser(); isDismissed = true; } } }; switch (dialogType) { case Type.PROGRESSING_DIALOG: ProgressDialog progressDialog; if (theme != -1) { progressDialog = new ProgressDialog(getActivity(), theme); } else { progressDialog = new ProgressDialog(getActivity()); } progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage(message); progressDialog.setIndeterminate(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(listener != null); return progressDialog; case Type.ALERT_DIALOG: AlertDialog.Builder builder; AlertDialog alertDialog; if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton(positiveButtonText, positiveListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.THREE_CHOICE_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton(positiveButtonText, positiveListener); builder.setNeutralButton(neutralButtonText, neutralListener); builder.setNegativeButton(negativeButtonText, negativeListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.YES_OR_NO_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton(positiveButtonText, positiveListener); builder.setNegativeButton(negativeButtonText, negativeListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.SELECT_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setSingleChoiceItems(entries, selectedIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onEvent(id); } dismiss(); onDialogFinishedByUser(); isDismissed = true; } } }); builder.setNegativeButton(negativeButtonText, negativeListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.CUSTOMIZE_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } if (customizeView != null && customizeView.getParent() != null) { ((ViewGroup) customizeView.getParent()).removeView(customizeView); } builder.setView(customizeView); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } if (!TextUtils.isEmpty(positiveButtonText)) { builder.setPositiveButton(positiveButtonText, positiveListener); } if (!TextUtils.isEmpty(neutralButtonText)) { builder.setNeutralButton(neutralButtonText, neutralListener); } if (!TextUtils.isEmpty(negativeButtonText)) { builder.setNegativeButton(negativeButtonText, negativeListener); } alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.CUSTOMIZE_FULLSCREEN_DIALOG: Dialog dialog; if (theme != -1) { dialog = new Dialog(getActivity(), theme); } else { dialog = new Dialog(getActivity(), android.R.style.Theme_NoTitleBar); } if (customizeView != null && customizeView.getParent() != null) { ((ViewGroup) customizeView.getParent()).removeView(customizeView); } dialog.setContentView(customizeView); return dialog; } return null; }
From source file:nl.spellenclubeindhoven.dominionshuffle.SelectActivity.java
@Override protected Dialog onCreateDialog(int id) { if (DIALOG_MINIMUM <= id && id <= DIALOG_MINIMUM + dialogMimimumCount) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alertDialog = builder .setSingleChoiceItems(/*from w w w . j a v a2s . c om*/ subArray(getResources().getStringArray(R.array.minumum_items_conditional), 0, id - DIALOG_MINIMUM), cardSelector.getLimitMinimum(selectedGroup), onMinClickListener) .create(); alertDialog.setCanceledOnTouchOutside(true); return alertDialog; } else if (DIALOG_MAXIMUM <= id && id <= DIALOG_MAXIMUM + dialogMaximumCount) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alertDialog = builder.setSingleChoiceItems( subArray(getResources().getStringArray(R.array.maximum_items), 0, id - DIALOG_MAXIMUM), cardSelector.getLimitMaximum(selectedGroup), onMaxClickListener).create(); alertDialog.setCanceledOnTouchOutside(true); return alertDialog; } switch (id) { case DIALOG_SOLVE_ERROR: { AlertDialog.Builder builder = new AlertDialog.Builder(this); return builder.setTitle(R.string.solve_dialog_title).setMessage(dialogMessage) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(R.string.ok, null).create(); } case DIALOG_NO_RESULT_ERROR: { AlertDialog.Builder builder = new AlertDialog.Builder(this); return builder.setTitle(R.string.display_result_dialog_title).setMessage(R.string.result_no_result) .setPositiveButton(R.string.ok, null).setIcon(android.R.drawable.ic_dialog_info).create(); } case DIALOG_SORT: { SharedPreferences prefs = getPreferences(MODE_PRIVATE); AlertDialog.Builder builder = new AlertDialog.Builder(this); return builder.setTitle(R.string.sort_cards_dialog_title) .setSingleChoiceItems(getResources().getStringArray(R.array.sort_items), prefs.getInt("sort", CardComparator.SORT_SET_COST_NAME), onSortClickListener) .create(); } case DIALOG_MINMAX: { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alertDialog = builder .setItems(getResources().getStringArray(R.array.minmax_array), onMinMaxClickListener).create(); alertDialog.setCanceledOnTouchOutside(true); return alertDialog; } default: return super.onCreateDialog(id); } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private boolean displayInAirplaneModeDialog() { // check if in airplane mode boolean inAirplaneMode = NetworkUtils.isInAirplaneMode(getApplication()); if (inAirplaneMode) { Log.d("displayInAirplaneModeDialog(): Device is in airplane mode"); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.main_dialog_in_airplane_mode_title); alertDialog.setMessage(getString(R.string.main_dialog_in_airplane_mode_message)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }//w w w . j ava 2s.c o m }); alertDialog.show(); } return inAirplaneMode; }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayUploadResultDialog(Bundle extras) { int descriptionId = extras.getInt(UploaderService.INTENT_KEY_RESULT_DESCRIPTION); try {/* w w w. j av a 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:com.bt.heliniumstudentapp.DayActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() != R.id.i_hwfloating_md) return super.onOptionsItemSelected(item); final ScheduleFragment.week.day day_data = schedule.day_get(schedule.day_get_index(lastPosition) + 2); if (day_data.floatings_get() == 0) { Toast.makeText(this, getString(R.string.homework_floating_no), Toast.LENGTH_SHORT).show(); return true; }/*from ww w .j ava 2 s . co m*/ final AlertDialog.Builder hwf_dialog_builder = new AlertDialog.Builder( new ContextThemeWrapper(this, MainActivity.themeDialog)); AlertDialog hwf_dialog; StringBuilder s; int i; hwf_dialog_builder.setTitle(getString(R.string.homework_floating)); hwf_dialog_builder.setPositiveButton(android.R.string.ok, null); s = new StringBuilder(); for (i = 0; i < day_data.floatings_get(); i++) { s.append(day_data.floating_get(i).course); s.append("\n"); s.append(Html.fromHtml(day_data.floating_get(i).text)); } hwf_dialog_builder.setMessage(s.toString()); hwf_dialog = hwf_dialog_builder.create(); hwf_dialog.setCanceledOnTouchOutside(true); hwf_dialog.show(); hwf_dialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)); return true; }
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);/*from w w w . j av a 2 s . c om*/ alertDialog.setTitle(R.string.updater_dialog_new_version_available); // load data 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 w w . j a va2 s.co 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 w w. j a va 2s . co 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); } }