Example usage for android.app Dialog setCanceledOnTouchOutside

List of usage examples for android.app Dialog setCanceledOnTouchOutside

Introduction

In this page you can find the example usage for android.app Dialog setCanceledOnTouchOutside.

Prototype

public void setCanceledOnTouchOutside(boolean cancel) 

Source Link

Document

Sets whether this dialog is canceled when touched outside the window's bounds.

Usage

From source file:org.catrobat.catroid.ui.dialogs.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_about, null);

    TextView aboutUrlTextView = (TextView) view.findViewById(R.id.dialog_about_text_view_url);
    aboutUrlTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String aboutUrl = getString(R.string.about_link_template, Constants.ABOUT_POCKETCODE_LICENSE_URL,
            getString(R.string.dialog_about_pocketcode_license_link_text));

    aboutUrlTextView.setText(Html.fromHtml(aboutUrl));

    TextView aboutUrlCatrobatView = (TextView) view.findViewById(R.id.dialog_about_text_catrobat_url);
    aboutUrlCatrobatView.setMovementMethod(LinkMovementMethod.getInstance());

    String aboutCatrobatUrl = getString(R.string.about_link_template, Constants.CATROBAT_ABOUT_URL,
            getString(R.string.dialog_about_catrobat_link_text));

    aboutUrlCatrobatView.setText(Html.fromHtml(aboutCatrobatUrl));

    TextView aboutVersionNameTextView = (TextView) view.findViewById(R.id.dialog_about_text_view_version_name);
    String versionName = this.getString(R.string.android_version_prefix) + Utils.getVersionName(getActivity());
    aboutVersionNameTextView.setText(versionName);

    Dialog aboutDialog = new AlertDialog.Builder(getActivity()).setView(view)
            .setTitle(R.string.dialog_about_title)
            .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override//from www.j a  v a 2s . c  om
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).create();
    aboutDialog.setCanceledOnTouchOutside(true);

    return aboutDialog;
}

From source file:co.edu.uniajc.vtf.content.MapSitesFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_search:
        Dialog loDialog = this.createDialog();
        loDialog.setCanceledOnTouchOutside(false);
        loDialog.show();//from www .j a v a 2  s. c o m
        OptionsManager loOptions = new OptionsManager(this.getActivity());
        OptionsEntity loOptionsData = loOptions.getOptions();
        EditText loSearchControl = (EditText) loDialog.findViewById(R.id.txtSearch);
        loSearchControl.setText(loOptionsData.getSearch());
        break;
    case R.id.action_refresh:
        MapSitesFragment.this.cboForceUpdate = true;
        this.loadList(LoadActions.LOAD_DATA);
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:hku.fyp14017.blencode.ui.dialogs.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View view = LayoutInflater.from(getActivity()).inflate(hku.fyp14017.blencode.R.layout.dialog_about, null);

    TextView license = (TextView) view.findViewById(R.id.dialog_about_text_view_license_info);
    license.setMovementMethod(LinkMovementMethod.getInstance());
    String licenseHTML = getString(hku.fyp14017.blencode.R.string.about_link_template,
            "https://github.com/fyp14017/BLEnCode/blob/master/Acknowledgements.txt",
            "Pocket Code Acknowledgements");
    license.setText(Html.fromHtml(licenseHTML));

    TextView aboutUrlTextView = (TextView) view
            .findViewById(hku.fyp14017.blencode.R.id.dialog_about_text_view_url);
    aboutUrlTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String aboutUrl = getString(hku.fyp14017.blencode.R.string.about_link_template,
            Constants.ABOUT_POCKETCODE_LICENSE_URL,
            getString(hku.fyp14017.blencode.R.string.dialog_about_pocketcode_license_link_text));

    aboutUrlTextView.setText(Html.fromHtml(aboutUrl));

    TextView aboutUrlCatrobatView = (TextView) view
            .findViewById(hku.fyp14017.blencode.R.id.dialog_about_text_catrobat_url);
    aboutUrlCatrobatView.setMovementMethod(LinkMovementMethod.getInstance());

    String aboutCatrobatUrl = getString(hku.fyp14017.blencode.R.string.about_link_template,
            Constants.CATROBAT_ABOUT_URL,
            getString(hku.fyp14017.blencode.R.string.dialog_about_catrobat_link_text));

    aboutUrlCatrobatView.setText(Html.fromHtml(aboutCatrobatUrl));

    TextView aboutVersionNameTextView = (TextView) view
            .findViewById(hku.fyp14017.blencode.R.id.dialog_about_text_view_version_name);
    String versionName = this.getString(hku.fyp14017.blencode.R.string.android_version_prefix)
            + Utils.getVersionName(getActivity());
    aboutVersionNameTextView.setText(versionName);

    Dialog aboutDialog = new AlertDialog.Builder(getActivity()).setView(view).setTitle("About BLEnCode")
            .setNeutralButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override/*from w ww .  java  2 s . c  o m*/
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).create();
    aboutDialog.setCanceledOnTouchOutside(true);

    return aboutDialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.AcceptTermsOfUseDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View view = LayoutInflater.from(getActivity()).inflate(hku.fyp14017.blencode.R.layout.dialog_terms_of_use,
            null);//  w w  w  .  ja  v  a  2  s  . c  o m

    TextView termsOfUseUrlTextView = (TextView) view
            .findViewById(hku.fyp14017.blencode.R.id.dialog_terms_of_use_text_view_url);
    termsOfUseUrlTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String termsOfUseUrl = getString(hku.fyp14017.blencode.R.string.terms_of_use_link_template,
            Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(hku.fyp14017.blencode.R.string.dialog_terms_of_use_link_text));

    termsOfUseUrlTextView.setText(Html.fromHtml(termsOfUseUrl));

    Dialog termsOfUseDialog = new AlertDialog.Builder(getActivity()).setView(view)
            .setTitle(hku.fyp14017.blencode.R.string.dialog_terms_of_use_title)
            .setNeutralButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).create();
    termsOfUseDialog.setCanceledOnTouchOutside(true);

    return termsOfUseDialog;
}

From source file:com.scoreloop.android.coreui.BaseActivity.java

private Dialog createErrorDialog(final int resId) {
    final Dialog dialog = new Dialog(this);
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    final View view = getLayoutInflater().inflate(R.layout.sl_dialog_custom, null);
    dialog.setContentView(view);//from ww w .j  ava  2 s.  c o  m
    dialog.setCanceledOnTouchOutside(true);
    ((TextView) view.findViewById(R.id.message)).setText(getString(resId));
    return dialog;
}

From source file:pulseanddecibels.jp.yamatenki.activity.SplashActivity.java

private void displayUserLicenseAgreement() {
    final Dialog dialog = new Dialog(SplashActivity.this);
    //        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_license_agreement);
    dialog.setTitle(getString(R.string.text_license_agreement_title));
    dialog.setCanceledOnTouchOutside(false);
    Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.yama_brown));
    dialog.getWindow().setBackgroundDrawable(d);
    dialog.show();// www  .  jav  a2  s.  c  o m
    licenseAgreementDialogOpen = true;
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (!agreeButtonPressed) {
                licenseAgreementDialogOpen = false;
                settings.setAgreedToLicense(false);
                if (!databaseTaskRunning) {
                    finish();
                }
            }
        }
    });
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            licenseAgreementDialogOpen = false;
            settings.setAgreedToLicense(false);
            if (!databaseTaskRunning) {
                finish();
            }
        }
    });

    final Button agreeButton = (Button) dialog.findViewById(R.id.agree_button);
    agreeButton.setEnabled(false);
    agreeButton.setAlpha(.5f);
    agreeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            settings.setAgreedToLicense(true);
            agreeButtonPressed = true;
            dialog.dismiss();
            if (!databaseTaskRunning) {
                startMainActivity();
            }
        }
    });

    final CheckBox agreementCheckbox = (CheckBox) dialog.findViewById(R.id.agreement_checkbox);
    agreementCheckbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CheckBox checkbox = (CheckBox) v;
            if (checkbox.isChecked()) {
                agreeButton.setAlpha(1.0f);
                agreeButton.setEnabled(true);
            } else {
                agreeButton.setAlpha(.5f);
                agreeButton.setEnabled(false);
            }
        }
    });

    TextView agreementLabel = (TextView) dialog.findViewById(R.id.agreement_label);
    agreementLabel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            agreementCheckbox.setChecked(!agreementCheckbox.isChecked());
            if (agreementCheckbox.isChecked()) {
                agreeButton.setAlpha(1.0f);
                agreeButton.setEnabled(true);
            } else {
                agreeButton.setAlpha(.5f);
                agreeButton.setEnabled(false);
            }
        }
    });
}

From source file:com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment.java

@NonNull
private Dialog createDialog(int accentColor, View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(v).setPositiveButton(R.string.common_ok, null)
            .setNegativeButton(R.string.common_cancel, null)
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.end_to_end_encryption_title), accentColor));

    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override/*  w ww . j  a v  a  2  s.co m*/
        public void onShow(final DialogInterface dialog) {

            Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    switch (keyResult) {
                    case KEY_CREATED:
                        Log_OC.d(TAG, "New keys generated and stored.");

                        dialog.dismiss();

                        Intent intentCreated = new Intent();
                        intentCreated.putExtra(SUCCESS, true);
                        intentCreated.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
                        getTargetFragment().onActivityResult(getTargetRequestCode(),
                                SETUP_ENCRYPTION_RESULT_CODE, intentCreated);
                        break;

                    case KEY_EXISTING_USED:
                        Log_OC.d(TAG, "Decrypt private key");

                        textView.setText(R.string.end_to_end_encryption_decrypting);

                        try {
                            String privateKey = task.get();
                            String mnemonic = passwordField.getText().toString().replaceAll("\\s", "")
                                    .toLowerCase(Locale.ROOT);
                            String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey,
                                    mnemonic);

                            arbitraryDataProvider.storeOrUpdateKeyValue(account.name,
                                    EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);

                            dialog.dismiss();
                            Log_OC.d(TAG, "Private key successfully decrypted and stored");

                            arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.MNEMONIC,
                                    mnemonic);

                            Intent intentExisting = new Intent();
                            intentExisting.putExtra(SUCCESS, true);
                            intentExisting.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
                            getTargetFragment().onActivityResult(getTargetRequestCode(),
                                    SETUP_ENCRYPTION_RESULT_CODE, intentExisting);

                        } catch (Exception e) {
                            textView.setText(R.string.end_to_end_encryption_wrong_password);
                            Log_OC.d(TAG, "Error while decrypting private key: " + e.getMessage());
                        }
                        break;

                    case KEY_GENERATE:
                        passphraseTextView.setVisibility(View.GONE);
                        positiveButton.setVisibility(View.GONE);
                        negativeButton.setVisibility(View.GONE);
                        getDialog().setTitle(ThemeUtils.getColoredTitle(
                                getString(R.string.end_to_end_encryption_storing_keys),
                                ThemeUtils.primaryColor(getContext())));

                        GenerateNewKeysAsyncTask newKeysTask = new GenerateNewKeysAsyncTask();
                        newKeysTask.execute();
                        break;

                    default:
                        dialog.dismiss();
                        break;
                    }
                }
            });
        }
    });
    return dialog;
}

From source file:ca.frozen.curlingtv.activities.ScannerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // get the controls
    View view = inflater.inflate(R.layout.fragment_scanner, container, false);
    message = (TextView) view.findViewById(R.id.scanner_message);
    status = (TextView) view.findViewById(R.id.scanner_status);
    progress = (ProgressBar) view.findViewById(R.id.scanner_progress);
    cancelButton = (Button) view.findViewById(R.id.scanner_cancel);

    // configure the dialog
    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);//from  w  w  w .j av a  2  s.  com
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(android.content.DialogInterface dialog, int keyCode,
                    android.view.KeyEvent event) {
                if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
                    cancel();
                }
                return false;
            }
        });
    }

    // handle the cancel button
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            cancel();
            dismiss();
        }
    });

    // create the dismiss handler and runnable
    dismissHandler = new Handler();
    dismissRunner = new Runnable() {
        @Override
        public void run() {
            dismiss();
        }
    };

    // configure the view if we've already done the scan
    if (savedInstanceState != null) {
        DeviceScanner scanner = (scannerWeakRef != null) ? scannerWeakRef.get() : null;
        if (scanner != null) {
            boolean complete = scanner.isComplete();
            scanner.setStatus(complete);
            if (complete) {
                cancelButton.setText(App.getStr(R.string.done));
            }
        }
    }

    return view;
}

From source file:ml.puredark.hviewer.ui.fragments.SettingFragment.java

public void DownloadedImport() {
    // /*from   ww  w. ja  v a 2  s  .  c  o  m*/
    activity.setSwipeBackEnable(false);
    // 
    activity.setAllowExit(false);
    View view = LayoutInflater.from(activity).inflate(R.layout.dialog_loading, null);
    TextView tvLoadingText = (TextView) view.findViewById(R.id.tv_loading_text);
    tvLoadingText.setText("");
    final Dialog dialog = new AlertDialog.Builder(activity).setView(view).create();
    dialog.setCanceledOnTouchOutside(false);
    //??
    WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
    lp.width = DensityUtil.getScreenWidth(activity) - DensityUtil.dp2px(activity, 64);
    dialog.getWindow().setAttributes(lp);
    dialog.show();
    new Thread(() -> {
        DownloadTaskHolder holder = new DownloadTaskHolder(activity);
        final int count = holder.scanPathForDownloadTask(DownloadManager.getDownloadPath());
        holder.onDestroy();
        activity.runOnUiThread(() -> {
            if (count > 0)
                Toast.makeText(mContext, "?" + count + "", Toast.LENGTH_SHORT)
                        .show();
            else if (count == 0)
                Toast.makeText(mContext, "???", Toast.LENGTH_SHORT)
                        .show();
            else
                Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
        });
        activity.setSwipeBackEnable(true);
        activity.setAllowExit(true);
        dialog.dismiss();
    }).start();
}

From source file:cn.reflect.dialogs.core.BaseDialogFragment.java

@NonNull
@Override//from  w  w w.  j  a v  a  2 s. c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int theme = R.style.SDL_Dialog;
    Dialog dialog = new Dialog(getActivity(), theme);

    Bundle args = getArguments();
    if (args != null) {
        dialog.setCanceledOnTouchOutside(args.getBoolean(BaseDialogBuilder.ARG_CANCELABLE_ON_TOUCH_OUTSIDE));
    }
    dialog.setOnShowListener(this);
    return dialog;
}