/** * helper method to open the license dialog / or website * * @param ctx Context for startActivity * @param libsBuilder * @param library */ private void openLicense(Context ctx, LibsBuilder libsBuilder, Library library) { try { if (libsBuilder.showLicenseDialog && !TextUtils.isEmpty(library.getLicense().getLicenseDescription())) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(Html.fromHtml(library.getLicense().getLicenseDescription())); builder.create().show(); } else { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(library.getLicense().getLicenseWebsite())); ctx.startActivity(browserIntent); } } catch (Exception ex) { } }
@Override public void onClick(View v) { boolean consumed = false; if (LibsConfiguration.getInstance().getListener() != null) { consumed = LibsConfiguration.getInstance().getListener().onExtraClicked(v, Libs.SpecialButton.SPECIAL3); } if (!consumed && !TextUtils.isEmpty(libsBuilder.aboutAppSpecial3Description)) { try { AlertDialog alert = new AlertDialog.Builder(ctx) .setMessage(Html.fromHtml(libsBuilder.aboutAppSpecial3Description)) .create(); alert.show(); TextView alertText = (TextView) alert.findViewById(android.R.id.message); if (alertText != null) { alertText.setMovementMethod(LinkMovementMethod.getInstance()); } } catch (Exception ex) { } } } });
@Override public void onClick(View v) { boolean consumed = false; if (LibsConfiguration.getInstance().getListener() != null) { consumed = LibsConfiguration.getInstance().getListener().onExtraClicked(v, Libs.SpecialButton.SPECIAL1); } if (!consumed && !TextUtils.isEmpty(libsBuilder.aboutAppSpecial1Description)) { try { AlertDialog alert = new AlertDialog.Builder(ctx) .setMessage(Html.fromHtml(libsBuilder.aboutAppSpecial1Description)) .create(); alert.show(); TextView alertText = (TextView) alert.findViewById(android.R.id.message); if (alertText != null) { alertText.setMovementMethod(LinkMovementMethod.getInstance()); } } catch (Exception ex) { } } } });
@Override public Builder setMessage(CharSequence message) { super.setMessage(message); return this; }
@Override public Builder setMessage(int messageId) { super.setMessage(getContext().getString(messageId)); return this; }
.setMessage(message) .setPositiveButton(android.R.string.ok, null) .create();
.setMessage(R.string.invalidation_dialog_message) .setPositiveButton(R.string.invalidate_confirmation, (dialog, which) -> { downloadedTilesDao.removeAll();
new AlertDialog.Builder(this) .setTitle("觉得还不错?") .setMessage("您的支持是我动力来源!\n请考虑为我买杯咖啡醒醒脑,甚至其他…… ;)") .setPositiveButton("为我买杯咖啡", new DialogInterface.OnClickListener() { @Override
.setMessage(R.string.confirmation_cancel_prev_download_title) .setPositiveButton(android.R.string.ok, (dialog, which) -> downloadAreaConfirmed(enclosingBBox)) .setNegativeButton(android.R.string.cancel, null)
private void requestLocationSettingsToBeOn() { if(LocationUtil.isLocationOn(getContext())) { state = LocationState.ENABLED; nextStep(); } else { final AlertDialog dlg = new AlertDialog.Builder(getContext()) .setMessage(R.string.turn_on_location_request) .setPositiveButton(android.R.string.yes, (dialog, which) -> { dialog.dismiss(); Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(viewIntent, LOCATION_TURN_ON_REQUEST); }) .setNegativeButton(android.R.string.no, (dialog, which) -> cancelTurnLocationOnDialog()) .setOnCancelListener(dialog -> cancelTurnLocationOnDialog()) .create(); // the user may turn on location in the pull-down-overlay, without actually going into // settings dialog registerForLocationProviderChanges(dlg); dlg.show(); } }
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { // must be for someone else... if(requestCode != LOCATION_PERMISSION_REQUEST) return; if(permissions.length == 0 || !permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION)) return; if(grantResults[0] == PackageManager.PERMISSION_GRANTED) { requestLocationPermissions(); // retry then... } else { new AlertDialog.Builder(getContext()) .setMessage(R.string.no_location_permission_warning) .setPositiveButton(R.string.retry, (dialog, which) -> requestLocationPermissions()) .setNegativeButton(android.R.string.cancel, (dialog, which) -> deniedLocationPermissions()) .setOnCancelListener(dialog -> deniedLocationPermissions()) .show(); } }
/** Request to close the form through user interaction (back button, clicked other quest,..), * requires user confirmation if any changes have been made */ @UiThread public void onClickClose(final Runnable confirmed) { if (!isRejectingClose()) { onDiscard(); confirmed.run(); } else { new AlertDialog.Builder(getActivity()) .setMessage(R.string.confirmation_discard_title) .setPositiveButton(R.string.confirmation_discard_positive, (dialog, which) -> { onDiscard(); confirmed.run(); }) .setNegativeButton(R.string.confirmation_discard_negative, null) .show(); } }
private void askUserToSendErrorReport(final Activity activityCtx, final int titleResourceId, String error) { final String report = "Describe how to reproduce it here:\n\n\n\n" + getDeviceInformationString() + "\n" + error; new Handler(Looper.getMainLooper()).post(() -> { new AlertDialog.Builder(activityCtx) .setTitle(titleResourceId) .setMessage(R.string.crash_message) .setPositiveButton(R.string.crash_compose_email, (dialog, which) -> sendEmail(activityCtx, report)) .setNegativeButton(android.R.string.no, (dialog, which) -> Toast.makeText(activityCtx, "\uD83D\uDE22",Toast.LENGTH_SHORT).show()) .setCancelable(false) .show(); }); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_reset: new AlertDialog.Builder(getContext()) .setMessage(R.string.pref_quests_reset) .setPositiveButton(android.R.string.ok, (dialog, which) -> onReset()) .setNegativeButton(android.R.string.cancel, null) .show(); return true; case R.id.action_deselect_all: onDeselectAll(); return true; } return super.onOptionsItemSelected(item); }
@Override public void onCheckedChanged(final CompoundButton compoundButton, boolean b) { item.visible = b; updateSelectionStatus(); visibleQuestTypeDao.setVisible(item.questType, item.visible); if(b && item.questType.getDefaultDisabledMessage() > 0) { new AlertDialog.Builder(compoundButton.getContext()) .setTitle(R.string.enable_quest_confirmation_title) .setMessage(item.questType.getDefaultDisabledMessage()) .setPositiveButton(android.R.string.yes, null) .setNegativeButton(android.R.string.no, (dialog, which) -> compoundButton.setChecked(false)) .show(); } } }
public void readSignature(View view) { Log.e("Signature", LibraryUtilsKt.getApkSignature(this)); new AlertDialog.Builder(this) .setTitle("APK") .setMessage(LibraryUtilsKt.getApkSignature((this))) .show(); }
@Override public void onClick(View v) { boolean consumed = false; if (LibsConfiguration.getInstance().getListener() != null) { consumed = LibsConfiguration.getInstance().getListener().onExtraClicked(v, Libs.SpecialButton.SPECIAL2); } if (!consumed && !TextUtils.isEmpty(libsBuilder.aboutAppSpecial2Description)) { try { AlertDialog alert = new AlertDialog.Builder(ctx) .setMessage(Html.fromHtml(libsBuilder.aboutAppSpecial2Description)) .create(); alert.show(); TextView alertText = (TextView) alert.findViewById(android.R.id.message); if (alertText != null) { alertText.setMovementMethod(LinkMovementMethod.getInstance()); } } catch (Exception ex) { } } } });
@Override public void onSequenceCanceled(TapTarget lastTarget) { final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) .setTitle("Uh oh") .setMessage("You canceled the sequence") .setPositiveButton("Oops", null).show(); TapTargetView.showFor(dialog, TapTarget.forView(dialog.getButton(DialogInterface.BUTTON_POSITIVE), "Uh oh!", "You canceled the sequence at step " + lastTarget.id()) .cancelable(false) .tintTarget(false), new TapTargetView.Listener() { @Override public void onTargetClick(TapTargetView view) { super.onTargetClick(view); dialog.dismiss(); } }); } });
/** * Show the dialog. {@link #show()} is a wrapper to ensure backwards compatibility */ AlertDialog showDialog(DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) { AlertDialog.Builder builder; if (mThemeResId != -1) { builder = new AlertDialog.Builder(mContext, mThemeResId); } else { builder = new AlertDialog.Builder(mContext); } return builder .setCancelable(false) .setTitle(mTitle) .setMessage(mRationale) .setPositiveButton(mPositiveButtonText, positiveListener) .setNegativeButton(mNegativeButtonText, negativeListener) .show(); }
AlertDialog createSupportDialog(Context context, Dialog.OnClickListener listener) { AlertDialog.Builder builder; if (theme > 0) { builder = new AlertDialog.Builder(context, theme); } else { builder = new AlertDialog.Builder(context); } return builder .setCancelable(false) .setPositiveButton(positiveButton, listener) .setNegativeButton(negativeButton, listener) .setMessage(rationaleMsg) .create(); }