android.app.AlertDialog#setCancelable ( )源码实例Demo

下面列出了android.app.AlertDialog#setCancelable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SoftwarePilot   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码2 项目: FaceT   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
private void onEnterStartedState() {
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
private void onEnterStartedState() {
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码5 项目: justaline-android   文件: PermissionHelper.java
/**
 * Show dialog with rationale for required permissions
 *
 * @param activity calling activity which the AlertDialog is shown on (PermissionsActivity)
 * @return the dialog that is shown
 */
private static AlertDialog showRequiredPermissionRationale(final Activity activity) {
    final AlertDialog
            alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle(activity.getString(R.string.title_activity_permissions));
    alertDialog.setMessage(activity.getString(R.string.initial_permissions_required));

    alertDialog.setButton(android.support.v7.app.AlertDialog.BUTTON_NEUTRAL,
            activity.getString(R.string.ask_me_again),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    requestRequiredPermissions(activity, true);
                }
            });

    alertDialog.setCancelable(false);
    alertDialog.show();

    return alertDialog;
}
 
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码7 项目: MOAAP   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码8 项目: MOAAP   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码9 项目: OpenCvFaceDetect   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码10 项目: marvel   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码12 项目: ScreenShift   文件: DialogFragments.java
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    final AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setMessage(R.string.keep_settings_question)
            .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    ((DialogListener) getActivity()).onNegativeButton(KeepSettingsDialog.this);
                }
            })
            .setPositiveButton(R.string.yes, null)
            .setCancelable(false)
            .create();
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);
    final Handler handler = new Handler();
    final Runnable revertRunnable = new Runnable(){
        @Override
        public void run() {
            if(dialog.isShowing()) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                ((DialogListener) getActivity()).onNegativeButton(KeepSettingsDialog.this);
            }
        }
    };
    handler.postDelayed(revertRunnable, 1000*13);
    return dialog;
}
 
源代码13 项目: aptoide-client-v8   文件: PromotionsFragment.java
@Override public void showPromotionOverDialog() {
  loading.setVisibility(View.GONE);
  LayoutInflater inflater = LayoutInflater.from(getContext());
  View dialogLayout = inflater.inflate(R.layout.promotions_promotion_over_dialog, null);
  AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(dialogLayout)
      .create();
  dialog.setCancelable(false);

  dialogLayout.findViewById(R.id.dismiss_button)
      .setOnClickListener(view -> {
        promotionOverDialogClick.onNext(null);
        dialog.dismiss();
      });
  dialog.show();
}
 
源代码14 项目: LokiBoard-Android-Keylogger   文件: LatinIME.java
private void showSubtypeSelectorAndSettings() {
    final CharSequence title = getString(R.string.english_ime_input_options);
    // TODO: Should use new string "Select active input modes".
    final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
    final CharSequence[] items = new CharSequence[] {
            languageSelectionTitle,
            getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
    };
    final String imeId = mRichImm.getInputMethodIdOfThisIme();
    final OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(DialogInterface di, int position) {
            di.dismiss();
            switch (position) {
            case 0:
                final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
                        imeId,
                        Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
                startActivity(intent);
                break;
            case 1:
                launchSettings();
                break;
            }
        }
    };
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(this));
    builder.setItems(items, listener).setTitle(title);
    final AlertDialog dialog = builder.create();
    dialog.setCancelable(true /* cancelable */);
    dialog.setCanceledOnTouchOutside(true /* cancelable */);
    showOptionDialog(dialog);
}
 
源代码15 项目: RelaxFinger   文件: SettingActivity.java
public void showUpdateInfo() {

        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("悬浮助手-3.0.4.3版本更新内容");
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setMessage("" +
                "1.全新的切换上一应用模式,速度更快,不再需要“使用情况访问权限”。\r\n"+
                "2.修复屏幕旋转权限问题。\r\n"+
                "3.优化快捷菜单半透明背景,覆盖状态栏和导航栏。\r\n"+
                "4.修复选择切换上一应用手势不能立即生效的问题。"+
                "");
        dialog.show();

    }
 
源代码16 项目: Reader   文件: PdfActivity.java
@Override
public void showOpenErrorDialog(String reason) {
    Resources res = getResources();
    mAlertBuilder = new AlertDialog.Builder(this);
    AlertDialog alert = mAlertBuilder.create();
    alert.setCancelable(false);
    alert.setTitle(String.format(res.getString(R.string.cannot_open_document_Reason), reason));
    alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
    alert.show();
}
 
源代码17 项目: commcare-android   文件: QuestionWidget.java
/**
 * Display extra help, triggered by user request.
 */
private void fireHelpText(final Runnable r) {
    if (!mPrompt.hasHelp()) {
        return;
    }

    // Depending on ODK setting, help may be displayed either as
    // a dialog or inline, underneath the question text

    if (showHelpWithDialog()) {
        AlertDialog mAlertDialog = new AlertDialog.Builder(this.getContext()).create();
        ScrollView scrollView = new ScrollView(this.getContext());
        scrollView.addView(createHelpLayout());
        mAlertDialog.setView(scrollView);

        DialogInterface.OnClickListener errorListener = (dialog, i) -> {
            switch (i) {
                case DialogInterface.BUTTON1:
                    dialog.cancel();
                    if (r != null) r.run();
                    break;
            }
        };
        mAlertDialog.setCancelable(true);
        mAlertDialog.setButton(StringUtils.getStringSpannableRobust(this.getContext(), R.string.ok), errorListener);
        mAlertDialog.show();
    } else {

        if (helpPlaceholder.getVisibility() == View.GONE) {
            expand(helpPlaceholder);
        } else {
            collapse(helpPlaceholder);
        }
    }
}
 
源代码18 项目: xDrip   文件: ImportDatabaseActivity.java
private void importDB(File the_file, Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle("Importing, please wait");
    builder.setMessage("Importing, please wait");
    AlertDialog dialog = builder.create();
    dialog.show();
    dialog.setMessage("Step 1: checking prerequisites");
    dialog.setCancelable(false);
    LoadTask lt = new LoadTask(dialog, the_file);
    lt.execute();
}
 
源代码19 项目: TowerCollector   文件: MainActivity.java
private void displayNotCompatibleDialog() {
    // check if displayed in this app run
    if (showNotCompatibleDialog) {
        // check if not disabled in preferences
        boolean showCompatibilityWarningEnabled = MyApplication.getPreferencesProvider().getShowCompatibilityWarning();
        if (showCompatibilityWarningEnabled) {
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            // check if device contains telephony hardware (some tablets doesn't report even if have)
            // NOTE: in the future this may need to be expanded when new specific features appear
            PackageManager packageManager = getPackageManager();
            boolean noRadioDetected = !(packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_GSM) || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)));
            // show dialog if something is not supported
            if (noRadioDetected) {
                Timber.d("displayNotCompatibleDialog(): Not compatible because of radio: %s, phone type: %s", noRadioDetected, telephonyManager.getPhoneType());
                //use custom layout to show "don't show this again" checkbox
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
                LayoutInflater inflater = LayoutInflater.from(this);
                View dialogLayout = inflater.inflate(R.layout.dont_show_again_dialog, null);
                final CheckBox dontShowAgainCheckbox = (CheckBox) dialogLayout.findViewById(R.id.dont_show_again_dialog_checkbox);
                dialogBuilder.setView(dialogLayout);
                AlertDialog alertDialog = dialogBuilder.create();
                alertDialog.setCanceledOnTouchOutside(true);
                alertDialog.setCancelable(true);
                alertDialog.setTitle(R.string.main_dialog_not_compatible_title);
                StringBuilder stringBuilder = new StringBuilder(getString(R.string.main_dialog_not_compatible_begin));
                if (noRadioDetected) {
                    stringBuilder.append(getString(R.string.main_dialog_no_compatible_mobile_radio_message));
                }
                // text set this way to prevent checkbox from disappearing when text is too long
                TextView messageTextView = (TextView) dialogLayout.findViewById(R.id.dont_show_again_dialog_textview);
                messageTextView.setText(stringBuilder.toString());
                alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        boolean dontShowAgainCheckboxChecked = dontShowAgainCheckbox.isChecked();
                        Timber.d("displayNotCompatibleDialog(): Don't show again checkbox checked = %s", dontShowAgainCheckboxChecked);
                        if (dontShowAgainCheckboxChecked) {
                            MyApplication.getPreferencesProvider().setShowCompatibilityWarning(false);
                        }
                    }
                });
                alertDialog.show();
            }
        }
        showNotCompatibleDialog = false;
    }
}
 
源代码20 项目: TowerCollector   文件: MainActivity.java
@NeedsPermission({Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE})
void startExportAsyncTask() {
    String runningTaskClassName = MyApplication.getBackgroundTaskName();
    if (runningTaskClassName != null) {
        Timber.d("startExportAsyncTask(): Another task is running in background: %s", runningTaskClassName);
        backgroundTaskHelper.showTaskRunningMessage(runningTaskClassName);
        return;
    }
    if (StorageUtils.isExternalMemoryWritable()) {
        final PreferencesProvider preferencesProvider = MyApplication.getPreferencesProvider();
        List<FileType> recentFileTypes = preferencesProvider.getEnabledExportFileTypes();
        LayoutInflater inflater = LayoutInflater.from(this);
        View dialogLayout = inflater.inflate(R.layout.configure_exporter_dialog, null);
        final CheckBox csvExportCheckbox = dialogLayout.findViewById(R.id.csv_export_dialog_checkbox);
        csvExportCheckbox.setChecked(recentFileTypes.contains(FileType.Csv));
        final CheckBox gpxExportCheckbox = dialogLayout.findViewById(R.id.gpx_export_dialog_checkbox);
        gpxExportCheckbox.setChecked(recentFileTypes.contains(FileType.Gpx));
        final CheckBox csvOcidExportCheckbox = dialogLayout.findViewById(R.id.csv_ocid_export_dialog_checkbox);
        csvOcidExportCheckbox.setChecked(recentFileTypes.contains(FileType.CsvOcid));
        final CheckBox jsonMlsExportCheckbox = dialogLayout.findViewById(R.id.json_mls_export_dialog_checkbox);
        jsonMlsExportCheckbox.setChecked(recentFileTypes.contains(FileType.JsonMls));
        final CheckBox compressExportCheckbox = dialogLayout.findViewById(R.id.compress_export_dialog_checkbox);
        compressExportCheckbox.setChecked(recentFileTypes.contains(FileType.Compress));
        AlertDialog alertDialog = new AlertDialog.Builder(this).setView(dialogLayout).create();
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.setCancelable(true);
        alertDialog.setTitle(R.string.export_dialog_format_selection_title);
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_export), (dialog, which) -> {
            List<FileType> selectedFileTypes = new ArrayList<>();
            if (csvExportCheckbox.isChecked())
                selectedFileTypes.add(FileType.Csv);
            if (gpxExportCheckbox.isChecked())
                selectedFileTypes.add(FileType.Gpx);
            if (csvOcidExportCheckbox.isChecked())
                selectedFileTypes.add(FileType.CsvOcid);
            if (jsonMlsExportCheckbox.isChecked())
                selectedFileTypes.add(FileType.JsonMls);
            if (compressExportCheckbox.isChecked())
                selectedFileTypes.add(FileType.Compress);
            preferencesProvider.setEnabledExportFileTypes(selectedFileTypes);
            Timber.d("startExportAsyncTask(): User selected positions: %s", TextUtils.join(",", selectedFileTypes));
            if (selectedFileTypes.isEmpty()) {
                Toast.makeText(getApplication(), R.string.export_toast_no_file_types_selected, Toast.LENGTH_LONG).show();
            } else {
                ExportFileAsyncTask task = new ExportFileAsyncTask(MainActivity.this, new InternalMessageHandler(MainActivity.this), selectedFileTypes);
                task.execute();
            }
        });
        alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel), (dialog, which) -> {
            // empty
        });
        alertDialog.show();
    } else if (StorageUtils.isExternalMemoryPresent()) {
        Toast.makeText(getApplication(), R.string.export_toast_storage_read_only, Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getApplication(), R.string.export_toast_no_storage, Toast.LENGTH_LONG).show();
    }
}