/** * 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) { } }
private void showInfoDialog() { final View layout = Views.inflate(this, R.layout.info_dialog); final TextView text = layout.findViewById(R.id.info_text); text.setText(getText(infoTextId)); new AlertDialog.Builder(this) .setView(layout) .setPositiveButton(android.R.string.ok, null) .show(); }
@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) { } } } });
public void findSource(final long questId, final QuestGroup group, @Nullable final Location location, final Listener listener) { if(dontShowAgain || isWithinSurveyDistance(questId, group, location)) { listener.onFindQuestSourceResult(SURVEY); } else { View inner = LayoutInflater.from(activity).inflate( R.layout.quest_source_dialog_layout, null, false); final CheckBox checkBox = inner.findViewById(R.id.checkBoxDontShowAgain); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); alertDialogBuilder .setTitle(R.string.quest_source_dialog_title) .setView(inner) .setPositiveButton(R.string.quest_generic_confirmation_yes, (dialog, which) -> { ++timesShown; dontShowAgain = checkBox.isChecked(); listener.onFindQuestSourceResult(SURVEY); }) .setNegativeButton(android.R.string.cancel, null); checkBox.setVisibility(timesShown < 2 ? View.GONE : View.VISIBLE); alertDialogBuilder.show(); } }
@Override public void onClick() { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(c); alertBuilder.setTitle(dialogTitle); final WebView wv = new WebView(c); wv.getSettings().setSupportZoom(supportZoom); if (!supportZoom) { wv.getSettings().setLoadWithOverviewMode(true); wv.getSettings().setUseWideViewPort(true); } if (isStringUrl) { wv.loadUrl(htmlString); } else { wv.loadData(htmlString, "text/html; charset=utf-8", "UTF-8"); } alertBuilder.setView(wv); alertBuilder.setNegativeButton(dialogNegativeButton, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { wv.destroy(); dialog.dismiss(); } }); final AlertDialog dialog = alertBuilder.create(); dialog.show(); } };
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 onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if(key.equals(Prefs.OAUTH_ACCESS_TOKEN_SECRET)) { updateOsmAuthSummary(); } else if(key.equals(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS)) { ApplyNoteVisibilityChangedTask task = applyNoteVisibilityChangedTask.get(); task.setPreference(getPreferenceScreen().findPreference(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS)); task.execute(); } else if(key.equals(Prefs.AUTOSYNC)) { if(Prefs.Autosync.valueOf(prefs.getString(Prefs.AUTOSYNC,"ON")) != Prefs.Autosync.ON) { new AlertDialog.Builder(getContext()) .setView(R.layout.dialog_tutorial_upload) .setPositiveButton(android.R.string.ok, null) .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(); } }
private void confirmUndo(final OsmQuest quest) { Element element = questController.getOsmElement(quest); View inner = LayoutInflater.from(this).inflate(R.layout.dialog_undo, null, false); ImageView icon = inner.findViewById(R.id.icon); icon.setImageResource(quest.getType().getIcon()); TextView text = inner.findViewById(R.id.text); text.setText(QuestUtilKt.getHtmlQuestTitle(getResources(), quest.getType(), element)); new AlertDialog.Builder(this) .setTitle(R.string.undo_confirm_title) .setView(inner) .setPositiveButton(R.string.undo_confirm_positive, (dialog, which) -> { questController.undo(quest); questAutoSyncer.triggerAutoUpload(); answersCounter.subtractOneUnsynced(quest.getChangesSource()); }) .setNegativeButton(R.string.undo_confirm_negative, null) .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(); } }
@UiThread private void requestOAuthorized() { if(dontShowRequestAuthorizationAgain) return; View inner = LayoutInflater.from(this).inflate( R.layout.dialog_authorize_now, null, false); final CheckBox checkBox = inner.findViewById(R.id.checkBoxDontShowAgain); new AlertDialog.Builder(this) .setView(inner) .setPositiveButton(android.R.string.ok, (dialog, which) -> { Intent intent = new Intent(MainActivity.this, SettingsActivity.class); intent.putExtra(SettingsActivity.EXTRA_LAUNCH_AUTH, true); startActivity(intent); }) .setNegativeButton(R.string.later, (dialog, which) -> { dontShowRequestAuthorizationAgain = checkBox.isChecked(); }).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 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 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(); }