Java Code Examples for androidx.appcompat.app.AlertDialog#setCancelable()

The following examples show how to use androidx.appcompat.app.AlertDialog#setCancelable() . 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: SortFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
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 2
Source File: PrivateActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
@SuppressLint("SetTextI18n")
private void createDownload() {
    LayoutInflater inflater = getLayoutInflater();
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_download, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.file_name_edit_text);
    EditText path = alertLayout.findViewById(R.id.file_path_edit_text);
    TextView download_size = alertLayout.findViewById(R.id.down_text);
    TextView download_warn = alertLayout.findViewById(R.id.down_text_warn);
    AlertDialog alertDialog = createDialog();
    alertDialog.setView(alertLayout);
    alertDialog.setCancelable(false);
    alertDialog.show();
    if (UserPreferences.isDangerousFileExtension(filename1)) {
        download_warn.setVisibility(View.VISIBLE);
        download_warn.setText(String.format(getString(R.string.download_warning), filename1));
    }
    shortcutNameEditText.setHint(filename1);
    path.setText(Environment.DIRECTORY_DOWNLOADS);
    download_size.setText(getResources().getString(R.string.download_file) + " " +file_size_main);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 3
Source File: MainActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
@SuppressLint("SetTextI18n")
public void createDownload() {
    LayoutInflater inflater = getLayoutInflater();
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_download, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.file_name_edit_text);
    EditText path = alertLayout.findViewById(R.id.file_path_edit_text);
    TextView download_size = alertLayout.findViewById(R.id.down_text);
    TextView download_warn = alertLayout.findViewById(R.id.down_text_warn);
    checker = alertLayout.findViewById(R.id.check_off);
    AlertDialog alertDialog = createDialog();
    alertDialog.setView(alertLayout);
    alertDialog.setCancelable(false);
    alertDialog.show();
    if (UserPreferences.isDangerousFileExtension(filename1)) {
        download_warn.setVisibility(View.VISIBLE);
        download_warn.setText(String.format(getString(R.string.download_warning), filename1));
    }
    shortcutNameEditText.setHint(filename1);
    path.setText(Environment.getExternalStorageDirectory().getPath() + File.separator +Environment.DIRECTORY_DOWNLOADS + File.separator + getString(R.string.app_name) + File.separator + "Simplicity Downloads");
    download_size.setText(getResources().getString(R.string.download_file) + " " +file_size_main);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 4
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: SortFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
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 6
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 6 votes vote down vote up
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 7
Source File: LoadableContentView.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private static void toggleButtons(@NonNull AlertDialog dialog, boolean enabled) {
    if (!dialog.isShowing()) return;

    dialog.setCancelable(enabled);

    Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    if (button != null) button.setEnabled(enabled);

    button = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    if (button != null) button.setEnabled(enabled);

    button = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
    if (button != null) button.setEnabled(enabled);
}
 
Example 8
Source File: DialogFragmentAuthenticationInput.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    @SuppressLint("InflateParams")
    final View rootView = LayoutInflater.from(requireActivity()).inflate(R.layout.dialog_fragment_auth_input, null);
    ButterKnife.bind(this, rootView);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(requireContext()).
            setIcon(R.drawable.ic_lock_open_24dp).
            setTitle(getString(R.string.provisioner_authentication_title)).
            setView(rootView);

    updateAuthUI(alertDialogBuilder);
    final AlertDialog alertDialog = alertDialogBuilder.show();
    alertDialog.setCanceledOnTouchOutside(false);
    alertDialog.setCancelable(false);

    final Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if(button != null) {
        button.setOnClickListener(v -> {
            final String pin = pinInput.getEditableText().toString().trim();
            if (validateInput(pin)) {
                ((ProvisionerInputFragmentListener) requireActivity()).onPinInputComplete(pin);
                dismiss();
            }
        });
    }

    return alertDialog;
}
 
Example 9
Source File: DialogFragmentMessage.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    alertDialogBuilder.setTitle(title);
    alertDialogBuilder.setMessage(message);
    final AlertDialog alertDialog = alertDialogBuilder.show();
    alertDialog.setCancelable(false);
    alertDialog.setCanceledOnTouchOutside(false);
    return alertDialog;
}
 
Example 10
Source File: DhikrFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
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 11
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 5 votes vote down vote up
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: AlertDialogFragment.java    From QuickDevFramework with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    String title = getArguments().getString(KEY_TITLE);
    String message = getArguments().getString(KEY_MESSAGE);
    if (!TextUtils.isEmpty(title)) {
        builder.setTitle(title);
    }
    if (iconDrawable != null) {
        builder.setIcon(iconDrawable);
    }
    builder.setMessage(message);
    if (positiveListener != null) {
        builder.setPositiveButton(positiveBtnText, positiveListener);
    }
    if (negativeListener != null) {
        builder.setNegativeButton(negativeBtnText, negativeListener);
    }
    if (dismissListener != null) {
        builder.setOnDismissListener(dismissListener);
    }
    if (keyListener != null) {
        builder.setOnKeyListener(keyListener);
    }
    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(cancelable);
    return dialog;
}
 
Example 13
Source File: DhikrFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
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: MenuHelper.java    From webTube with GNU General Public License v3.0 5 votes vote down vote up
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 15
Source File: MainActivity.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@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 16
Source File: MainActivity.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@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();
    }
    
}