androidx.appcompat.app.AlertDialog.Builder Java Examples
The following examples show how to use
androidx.appcompat.app.AlertDialog.Builder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From cythara with GNU General Public License v3.0 | 6 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == RECORD_AUDIO_PERMISSION) { if (grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { startRecording(); } else { AlertDialog alertDialog = new Builder(MainActivity.this).create(); alertDialog.setTitle(R.string.permission_required); alertDialog.setMessage(getString(R.string.microphone_permission_required)); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok), (dialog, which) -> { dialog.dismiss(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { finishAffinity(); } else { finish(); } }); alertDialog.show(); } } } }
Example #2
Source File: PasswordResetActivity.java From particle-android with Apache License 2.0 | 6 votes |
public void onPasswordResetClicked(View v) { SEGAnalytics.track("Auth: Request password reset"); final String email = emailView.getText().toString(); if (isEmailValid(email)) { performReset(); } else { new Builder(this) .setTitle(getString(R.string.reset_password_dialog_title)) .setMessage(getString(R.string.reset_paassword_dialog_please_enter_a_valid_email)) .setPositiveButton(R.string.ok, (dialog, which) -> { dialog.dismiss(); emailView.requestFocus(); }) .show(); } }
Example #3
Source File: DiscoverDeviceActivity.java From particle-android with Apache License 2.0 | 6 votes |
private void onWifiDisabled() { log.d("Wi-Fi disabled; prompting user"); new AlertDialog.Builder(this) .setTitle(R.string.wifi_required) .setPositiveButton(R.string.enable_wifi, (dialog, which) -> { dialog.dismiss(); log.i("Enabling Wi-Fi at the user's request."); wifiFacade.setWifiEnabled(true); wifiListFragment.scanAsync(); }) .setNegativeButton(R.string.exit_setup, (dialog, which) -> { dialog.dismiss(); finish(); }) .show(); }
Example #4
Source File: DiscoverDeviceActivity.java From particle-android with Apache License 2.0 | 6 votes |
private void onMaxAttemptsReached() { if (!isResumed) { finish(); return; } String errorMsg = Phrase.from(this, R.string.unable_to_connect_to_soft_ap) .put("device_name", getString(R.string.device_name)) .format().toString(); new AlertDialog.Builder(this) .setTitle(R.string.error) .setMessage(errorMsg) .setPositiveButton(R.string.ok, (dialog, which) -> { dialog.dismiss(); startActivity(new Intent(DiscoverDeviceActivity.this, GetReadyActivity.class)); finish(); }) .show(); }
Example #5
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 6 votes |
/** * Shows message in an AlertDialog. * * @param message contains identify results processed into a string. */ private void showAlertDialog(StringBuilder message) { Builder alertDialogBuilder = new Builder(this); // set title alertDialogBuilder.setTitle("Number of elements found"); // set dialog message alertDialogBuilder .setMessage(message) .setCancelable(false) .setPositiveButton("Ok", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show the alert dialog alertDialog.show(); }
Example #6
Source File: MainActivity.java From LocationShare with GNU General Public License v3.0 | 6 votes |
public void shareLocation(View view) { if (!validLocation(lastLocation)) { return; } String linkChoice = PreferenceManager.getDefaultSharedPreferences(this).getString("prefLinkType", ""); if (linkChoice.equals(getResources().getString(R.string.always_ask))) { new Builder(this).setTitle(R.string.choose_link) .setCancelable(true) .setItems(R.array.link_names, new onClickShareListener()) .create() .show(); } else { shareLocationText(formatLocation(lastLocation, linkChoice)); } }
Example #7
Source File: MainActivity.java From LocationShare with GNU General Public License v3.0 | 6 votes |
public void copyLocation(View view) { if (!validLocation(lastLocation)) { return; } String linkChoice = PreferenceManager.getDefaultSharedPreferences(this).getString("prefLinkType", ""); if (linkChoice.equals(getResources().getString(R.string.always_ask))) { new Builder(this).setTitle(R.string.choose_link) .setCancelable(true) .setItems(R.array.link_names, new onClickCopyListener()) .create() .show(); } else { copyLocationText(formatLocation(lastLocation, linkChoice)); } }
Example #8
Source File: NumberPickerDialog.java From cythara with GNU General Public License v3.0 | 5 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final NumberPicker numberPicker = new NumberPicker(getActivity()); Bundle arguments = getArguments(); int currentValue = arguments.getInt("current_value", 440); numberPicker.setMinValue(400); numberPicker.setMaxValue(500); numberPicker.setValue(currentValue); if (MainActivity.isDarkModeEnabled()) { int color = getResources().getColor(R.color.colorTextDark); numberPicker.setTextColor(color); numberPicker.setDividerColor(color); numberPicker.setSelectedTextColor(color); } Builder builder = new Builder(new ContextThemeWrapper(getActivity(), R.style.AppTheme)); builder.setMessage(R.string.choose_a_frequency); builder.setPositiveButton("OK", (dialog, which) -> valueChangeListener.onValueChange(numberPicker, numberPicker.getValue(), numberPicker.getValue())); builder.setNegativeButton("CANCEL", (dialog, which) -> { }); builder.setView(numberPicker); return builder.create(); }
Example #9
Source File: PasswordResetActivity.java From particle-android with Apache License 2.0 | 5 votes |
private void onResetAttemptFinished(String content) { new AlertDialog.Builder(this) .setMessage(content) .setPositiveButton(R.string.ok, (dialog, which) -> { dialog.dismiss(); finish(); }) .show(); }
Example #10
Source File: DiscoverDeviceActivity.java From particle-android with Apache License 2.0 | 5 votes |
private void onLocationDisabled() { log.d("Location disabled; prompting user"); new Builder(this).setTitle(R.string.location_required) .setMessage(R.string.location_required_message) .setPositiveButton(R.string.enable_location, ((dialog, which) -> { dialog.dismiss(); log.i("Sending user to enabling Location services."); startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); })) .setNegativeButton(R.string.exit_setup, ((dialog, which) -> { dialog.dismiss(); finish(); })) .show(); }
Example #11
Source File: DiscoverDeviceActivity.java From particle-android with Apache License 2.0 | 5 votes |
private void onDeviceClaimedByOtherUser() { String dialogMsg = getString(R.string.dialog_title_owned_by_another_user, getString(R.string.device_name), sparkCloud.getLoggedInUsername()); new Builder(this) .setTitle(getString(R.string.change_owner_question)) .setMessage(dialogMsg) .setPositiveButton(getString(R.string.change_owner), (dialog, which) -> { dialog.dismiss(); log.i("Changing owner to " + sparkCloud.getLoggedInUsername()); resetWorker(); discoverProcessWorker.needToClaimDevice = true; discoverProcessWorker.gotOwnershipInfo = true; discoverProcessWorker.isDetectedDeviceClaimed = false; showProgressDialog(); startConnectWorker(); }) .setNegativeButton(R.string.cancel, (dialog, which) -> { dialog.dismiss(); startActivity(new Intent(DiscoverDeviceActivity.this, GetReadyActivity.class)); finish(); }) .show(); }
Example #12
Source File: PermissionsFragment.java From particle-android with Apache License 2.0 | 5 votes |
public void ensurePermission(final @NonNull String permission) { Builder dialogBuilder = new AlertDialog.Builder(getActivity()) .setCancelable(false); if (ActivityCompat.checkSelfPermission(getActivity(), permission) != PERMISSION_GRANTED || ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) { dialogBuilder.setTitle(R.string.location_permission_dialog_title) .setMessage(R.string.location_permission_dialog_text) .setPositiveButton(R.string.got_it, (dialog, which) -> { dialog.dismiss(); requestPermission(permission); }); } else { // user has explicitly denied this permission to setup. // show a simple dialog and bail out. dialogBuilder.setTitle(R.string.location_permission_denied_dialog_title) .setMessage(R.string.location_permission_denied_dialog_text) .setPositiveButton(R.string.settings, (dialog, which) -> { dialog.dismiss(); Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); String pkgName = getActivity().getApplicationInfo().packageName; intent.setData(Uri.parse("package:" + pkgName)); startActivity(intent); }) .setNegativeButton(R.string.exit_setup, (dialog, which) -> { Client client = (Client) getActivity(); client.onUserDeniedPermission(permission); }); } dialogBuilder.show(); }
Example #13
Source File: ListPreference.java From MaterialPreferenceLibrary with Apache License 2.0 | 4 votes |
@Override protected void onPrepareDialogBuilder(Builder builder) { super.onPrepareDialogBuilder(builder); if (mEntries == null || mEntryValues == null) { throw new IllegalStateException( "ListPreference requires an entries array and an entryValues array."); } mClickedDialogEntryIndex = getValueIndex(); // final ListView listView=new ListView(getContext()); // listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // listView.setOnItemClickListener(new OnItemClickListener() // { // @Override // public void onItemClick(final AdapterView<?> parent,final View view,final int position,final long id) // { // listView.setItemChecked(position,true); // if(position>=0&&getEntryValues()!=null) // { // String value=getEntryValues()[position].toString(); // if(callChangeListener(value)&&isPersistent()) // setValue(value); // } // mDialog.dismiss(); // } // }); // listView.setAdapter(new ArrayAdapter<>(getContext(),R.layout.mpl__simple_list_item_single_choice,entries)); // builder.setView(listView); builder.setSingleChoiceItems(new ArrayAdapter<>(getContext(), R.layout.mpl__simple_list_item_single_choice, mEntries), mClickedDialogEntryIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mClickedDialogEntryIndex = which; /* * Clicking on an item simulates the positive button * click, and dismisses the dialog. */ ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE); dialog.dismiss(); } }); /* * The typical interaction for list-based dialogs is to have * click-on-an-item dismiss the dialog instead of the user having to * press 'Ok'. */ builder.setPositiveButton(null, null); }