Java Code Examples for androidx.appcompat.app.alertdialog#setButton()
The following examples show how to use
androidx.appcompat.app.alertdialog#setButton() .
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: MenuHelper.java From webTube with GNU General Public License v3.0 | 6 votes |
public void homepageTutorial() { if (!sp.getBoolean("homepageLearned", false)) { AlertDialog dialog = new AlertDialog.Builder(context).create(); dialog.setTitle(context.getString(R.string.home)); dialog.setMessage(context.getString(R.string.homePageHelp)); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", (dialog1, buttonId) -> { dialog1.dismiss(); SharedPreferences.Editor editor = sp.edit(); editor.putBoolean("homepageLearned", true); editor.apply(); }); dialog.show(); } }
Example 3
Source File: SortFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
public void onItemDismiss(final int position) { final Times times = Times.getTimesAt(position); AlertDialog dialog = new AlertDialog.Builder(getActivity()).create(); dialog.setTitle(R.string.delete); dialog.setMessage(getString(R.string.delCityConfirm, times.getName())); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> { times.delete(); mAdapter.notifyItemRemoved(position); }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> { dialogInterface.cancel(); mAdapter.notifyDataSetChanged(); }); dialog.show(); }
Example 4
Source File: SortFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
public void onItemDismiss(final int position) { final Times times = Times.getTimesAt(position); AlertDialog dialog = new AlertDialog.Builder(getActivity()).create(); dialog.setTitle(R.string.delete); dialog.setMessage(getString(R.string.delCityConfirm, times.getName())); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> { times.delete(); mAdapter.notifyItemRemoved(position); }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> { dialogInterface.cancel(); mAdapter.notifyDataSetChanged(); }); dialog.show(); }
Example 5
Source File: MenuHelper.java From webTube with GNU General Public License v3.0 | 6 votes |
public void homepageTutorial() { if (!sp.getBoolean("homepageLearned", false)) { AlertDialog dialog = new AlertDialog.Builder(context).create(); dialog.setTitle(context.getString(R.string.home)); dialog.setMessage(context.getString(R.string.homePageHelp)); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", (dialog1, buttonId) -> { dialog1.dismiss(); SharedPreferences.Editor editor = sp.edit(); editor.putBoolean("homepageLearned", true); editor.apply(); }); dialog.show(); } }
Example 6
Source File: DoodleDrawActivity.java From djl-demo with Apache License 2.0 | 6 votes |
@Override protected void onPostExecute(Boolean result) { if (result) { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); paintView.init(metrics, imageView, textView, predictor); progressBar.setVisibility(View.GONE); containerView.setVisibility(View.VISIBLE); } else { AlertDialog alertDialog = new AlertDialog.Builder(DoodleDrawActivity.this).create(); alertDialog.setTitle("Error"); alertDialog.setMessage("Failed to load model"); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", (dialog, which) -> finish()); } }
Example 7
Source File: FormFragment.java From shaky-android with Apache License 2.0 | 6 votes |
/** * Validates the message and returns true if the form is valid. */ private boolean validate(@NonNull String message) { if (message.trim().length() == 0) { AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create(); alertDialog.setMessage(getString(R.string.shaky_empty_feedback_message)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.shaky_empty_feedback_confirm), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); return false; } return true; }
Example 8
Source File: MenuHelper.java From webTube with GNU General Public License v3.0 | 5 votes |
private void show_noVideo_dialog() { AlertDialog dialog = new AlertDialog.Builder(context/**/).create(); dialog.setTitle(context.getString(R.string.error_no_video)); dialog.setMessage(context.getString(R.string.error_select_video_and_retry)); dialog.setCancelable(true); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok).toUpperCase(), (dialog1, buttonId) -> dialog1.dismiss()); dialog.show(); }
Example 9
Source File: MainActivity.java From Once with Apache License 2.0 | 5 votes |
private void showDialog(String message) { AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setMessage(message); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); }
Example 10
Source File: AlertDialogFragment.java From edx-app-android with Apache License 2.0 | 5 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle args = getArguments(); final int titleResId = args.getInt(ARG_TITLE_RES); final int messageResId = args.getInt(ARG_MESSAGE_RES); final CharSequence title = titleResId != 0 ? getText(titleResId) : args.getString(ARG_TITLE); final CharSequence message = messageResId != 0 ? getText(messageResId) : args.getString(ARG_MESSAGE); final AlertDialog alertDialog = new AlertDialog.Builder(getContext()) .setMessage(message) .create(); alertDialog.setCanceledOnTouchOutside(false); if (title != null) { alertDialog.setTitle(title); } if (positiveButtonAttr != null) { alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, positiveButtonAttr.getText(), positiveButtonAttr.getOnClickListener()); } if (negativeButtonAttr != null) { alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, negativeButtonAttr.getText(), negativeButtonAttr.getOnClickListener()); } return alertDialog; }
Example 11
Source File: MenuHelper.java From webTube with GNU General Public License v3.0 | 5 votes |
private void show_noVideo_dialog() { AlertDialog dialog = new AlertDialog.Builder(context/**/).create(); dialog.setTitle(context.getString(R.string.error_no_video)); dialog.setMessage(context.getString(R.string.error_select_video_and_retry)); dialog.setCancelable(true); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok).toUpperCase(), (dialog1, buttonId) -> dialog1.dismiss()); dialog.show(); }
Example 12
Source File: DhikrFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
private void deleteDhikr() { AlertDialog dialog = new AlertDialog.Builder(getActivity()).create(); dialog.setTitle(R.string.delete); dialog.setMessage(getString(R.string.delConfirmDhikr, mDhikrs.get(0).getTitle())); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> mViewModel.deleteDhikr(mDhikrs.get(0))); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> { }); dialog.show(); }
Example 13
Source File: DhikrFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
private void deleteDhikr() { AlertDialog dialog = new AlertDialog.Builder(getActivity()).create(); dialog.setTitle(R.string.delete); dialog.setMessage(getString(R.string.delConfirmDhikr, mDhikrs.get(0).getTitle())); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> mViewModel.deleteDhikr(mDhikrs.get(0))); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> { }); dialog.show(); }
Example 14
Source File: SharedMediaActivity.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
public void requestSdCardPermissions() { AlertDialog textDialog = AlertDialogsHelper.getTextDialog(this, R.string.sd_card_write_permission_title, R.string.sd_card_permissions_message); textDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), REQUEST_CODE_SD_CARD_PERMISSIONS); } }); textDialog.show(); }
Example 15
Source File: AboutActivity.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
@OnClick(R.id.about_link_changelog) public void onChangelog() { AlertDialog alertDialog = AlertDialogsHelper.showChangelogDialog(this); alertDialog.setButton( DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), (dialogInterface, i) -> { }); alertDialog.show(); }
Example 16
Source File: MainActivity.java From prayer-times-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String lang = LocaleUtils.getLanguage("en", "de", "tr"); final String file = lang + "/hadis.db"; final String url = App.API_URL + "/files/hadis." + lang + ".db"; File f = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file); if (f.exists()) { try { if (SqliteHelper.get().getCount() == 0) { SqliteHelper.get().close(); ((Object) null).toString(); } } catch (Exception e) { if (f.exists() && !f.delete()) { Log.e("BaseActivity", "could not delete " + f.getAbsolutePath()); } finish(); } setDefaultFragment(new HadithFragment()); moveToFrag(getDefaultFragment()); } else if (!App.isOnline()) { Toast.makeText(this, R.string.no_internet, Toast.LENGTH_SHORT).show(); } else { AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setTitle(R.string.hadith); dialog.setMessage(getString(R.string.dlHadith)); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> { File f1 = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file); if (!f1.getParentFile().mkdirs()) { Log.e("BaseActivity", "could not mkdirs " + f1.getParent()); } final ProgressDialog dlg = new ProgressDialog(MainActivity.this); dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dlg.setCancelable(false); dlg.setCanceledOnTouchOutside(false); dlg.show(); Ion.with(MainActivity.this).load(url).progressDialog(dlg).write(f1).setCallback((e, result) -> { dlg.dismiss(); if (e != null) { e.printStackTrace(); Crashlytics.logException(e); Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_LONG).show(); finish(); } else if (result.exists()) { openHadithFrag(); } }); }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> dialogInterface.cancel()); dialog.show(); } }
Example 17
Source File: MainActivity.java From prayer-times-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String lang = LocaleUtils.getLanguage("en", "de", "tr"); final String file = lang + "/hadis.db"; final String url = App.API_URL + "/files/hadis." + lang + ".db"; File f = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file); if (f.exists()) { try { if (SqliteHelper.get().getCount() == 0) { SqliteHelper.get().close(); ((Object) null).toString(); } } catch (Exception e) { if (f.exists() && !f.delete()) { Log.e("BaseActivity", "could not delete " + f.getAbsolutePath()); } finish(); } setDefaultFragment(new HadithFragment()); moveToFrag(getDefaultFragment()); } else if (!App.isOnline()) { Toast.makeText(this, R.string.no_internet, Toast.LENGTH_SHORT).show(); } else { AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setTitle(R.string.hadith); dialog.setMessage(getString(R.string.dlHadith)); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> { File f1 = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file); if (!f1.getParentFile().mkdirs()) { Log.e("BaseActivity", "could not mkdirs " + f1.getParent()); } final ProgressDialog dlg = new ProgressDialog(MainActivity.this); dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dlg.setCancelable(false); dlg.setCanceledOnTouchOutside(false); dlg.show(); Ion.with(MainActivity.this).load(url).progressDialog(dlg).write(f1).setCallback((e, result) -> { dlg.dismiss(); if (e != null) { e.printStackTrace(); Crashlytics.logException(e); Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_LONG).show(); finish(); } else if (result.exists()) { openHadithFrag(); } }); }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> dialogInterface.cancel()); dialog.show(); } }
Example 18
Source File: MainActivity.java From YouTube-In-Background with MIT License | 4 votes |
/** * Handles selected item from action bar * * @param item the selected item from the action bar * @return boolean */ @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); Locale locale = getResources().getConfiguration().locale; //noinspection SimplifiableIfStatement switch (id) { case R.id.action_about: DateFormat monthFormat = new SimpleDateFormat("MMMM", locale); DateFormat yearFormat = new SimpleDateFormat("yyyy", locale); Date date = new Date(); AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle("Teocci"); alertDialog.setIcon(R.mipmap.ic_launcher); alertDialog.setMessage( "Dedicated to the person who gives me a reason to smile even on the dullest of days." + ".\n" + "누리 고마워~ Thanks for been in my life." + "\n\n" + "YiB v" + BuildConfig.VERSION_NAME + "\n\[email protected]\n\n" + monthFormat.format(date) + " " + yearFormat.format(date) + ".\n" ); alertDialog.setButton( AlertDialog.BUTTON_NEUTRAL, "OK", (dialog, which) -> dialog.dismiss() ); alertDialog.show(); return true; case R.id.action_clear_list: YouTubeSqlDb.getInstance() .videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED) .deleteAll(); recentlyPlayedFragment.clearRecentlyPlayedList(); return true; case R.id.action_remove_account: SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); String chosenAccountName = sp.getString(ACCOUNT_NAME, null); if (chosenAccountName != null) { sp.edit().remove(ACCOUNT_NAME).apply(); } return true; case R.id.action_search: item.expandActionView(); return true; } return super.onOptionsItemSelected(item); }