Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:it.feio.android.omninotes.async.UpdaterTask.java

private void promptUpdate() {

    // Confirm dialog creation
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivityReference.get());
    alertDialogBuilder.setCancelable(false).setMessage(R.string.new_update_available)
            .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {

                @Override/*from  w w w  .  j a va  2s.c om*/
                public void onClick(DialogInterface dialog, int id) {
                    if (isGooglePlayAvailable()) {
                        mActivityReference.get().startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + packageName)));
                    } else {

                        // MapBuilder.createEvent().build() returns a Map of event fields and values
                        // that are set and sent with the hit.
                        OmniNotes.getGaTracker().send(MapBuilder.createEvent("ui_action", // Event category (required)
                                "button_press", // Event action (required)
                                "Google Drive Update", // Event label
                                null) // Event value
                                .build());

                        mActivityReference.get().startActivity(
                                new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DRIVE_FOLDER_LAST_BUILD)));
                    }

                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.not_now, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.springsource.greenhouse.WebOAuthActivity.java

private void displayAppAuthorizationError(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(message);/*from w w w  .  j a v a  2  s . c om*/
    builder.setCancelable(false);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            signOut();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.intel.xdk.notification.Notification.java

public void confirm(String message, final String iden, String title, String ok, String cancel) {
    if (bConfirmBusy) {
        final String js = "javascript:var e = document.createEvent('Events');e.initEvent('intel.xdk.notification.confirm.busy',true,true);e.success=false;e.message='busy';e.id='"
                + iden + "';document.dispatchEvent(e);";
        activity.runOnUiThread(new Runnable() {

            public void run() {
                webView.loadUrl(js);//from   w ww.j a  v a  2 s  . com
            }

        });
        return;
    }
    bConfirmBusy = true;

    if (title == null || title.length() == 0)
        title = "Please confirm";
    if (ok == null || ok.length() == 0)
        ok = "OK";
    if (cancel == null || cancel.length() == 0)
        cancel = "Cancel";

    AlertDialog.Builder alertBldr = new AlertDialog.Builder(activity);
    alertBldr.setCancelable(false);
    alertBldr.setMessage(message);
    alertBldr.setTitle(title);
    alertBldr.setPositiveButton(ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            processConfirm(true, iden);
        }
    });
    alertBldr.setNegativeButton(cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            processConfirm(false, iden);
        }
    });
    alertBldr.show();
}

From source file:com.bradenmacdonald.OverlayedMapFragment.java

@Override
public void onStart() {
    super.onStart();
    mMap = mMapFragment.getMap();// w w w.j a  v  a 2s.c  o  m
    if (mMap == null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "Unable to create a Google Map. Please make sure the Google Maps app is installed on your device.");
        builder.setCancelable(true);
        builder.setPositiveButton("OK", null);
        builder.create().show();
        // Throwing an exception here ensures that s3eMapViewCreate() will
        // return null, so that the Marmalade app knows that the map failed
        // to load.
        throw new RuntimeException(
                "s3eMapActivity: onStart: Could not get a GoogleMap from mMapFragment.getMap()");
    }
    // Map is supposed to be hidden at first:
    getSupportFragmentManager().beginTransaction().hide(mMapFragment).commit();
}

From source file:de.thecamper.android.androidtools.UpdateChecker.java

/**
 * show a AlertDialog to inform the user of the update and let him download
 * the new version of the app/* w  ww . j a v  a2s  .  c  o m*/
 */
public void showUpdateAlert() {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.updateTitle));
    builder.setMessage(context.getString(R.string.updateAvailable));
    builder.setCancelable(false);
    builder.setPositiveButton(context.getString(R.string.yes), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(appURL));
            context.startActivity(intent);
            ((Activity) context).finish();
        }
    });
    builder.setNegativeButton(context.getString(R.string.later), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.example.linhdq.test.documents.creation.visualisation.LayoutQuestionDialog.java

@NonNull
@Override//from   w w w . j  a  v a2  s  .com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getContext();
    mLayout = null;
    Pair<String, String> language = PreferencesUtils.getOCRLanguage(context);

    final InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first, context);

    if (!installStatus.isInstalled()) {
        final String defaultLanguage = context.getString(R.string.default_ocr_language);
        final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language);
        language = Pair.create(defaultLanguage, defaultLanguageDisplay);
    }
    mLanguage = language.first;

    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    View layout = View.inflate(context, R.layout.dialog_layout_question, null);
    builder.setView(layout);

    final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title);
    final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout);
    final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout);
    final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout);
    fairy.setFactory(new ViewSwitcher.ViewFactory() {
        public View makeView() {
            return new ImageView(context);
        }
    });
    fairy.setImageResource(R.drawable.fairy_looks_center);
    fairy.setInAnimation(context, android.R.anim.fade_in);
    fairy.setOutAnimation(context, android.R.anim.fade_out);

    final int color = context.getResources().getColor(R.color.progress_color);

    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN);

    columnLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.COMPLEX) {
                fairy.setImageResource(R.drawable.fairy_looks_left);
                titleViewFlipper.setDisplayedChild(2);
                columnLayout.setColorFilter(colorFilter);
                pageLayout.clearColorFilter();
                mLayout = LayoutKind.COMPLEX;
            }

        }
    });
    pageLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.SIMPLE) {
                mLayout = LayoutKind.SIMPLE;
                titleViewFlipper.setDisplayedChild(1);
                fairy.setImageResource(R.drawable.fairy_looks_right);
                pageLayout.setColorFilter(colorFilter);
                columnLayout.clearColorFilter();
            }
        }
    });

    final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language);
    List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context);

    // actual values uses by tesseract
    final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.item_spinner_language,
            installedLanguages);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    langButton.setAdapter(adapter);
    for (int i = 0; i < installedLanguages.size(); i++) {
        OcrLanguage lang = installedLanguages.get(i);
        if (lang.getValue().equals(language.first)) {
            langButton.setSelection(i, false);
            break;
        }
    }
    langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final OcrLanguage item = adapter.getItem(position);
            mLanguage = item.getValue();
            PreferencesUtils.saveOCRLanguage(context, item);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (mLayout == null) {
                mLayout = LayoutKind.SIMPLE;
            }
            LayoutChoseListener listener = (LayoutChoseListener) getActivity();
            listener.onLayoutChosen(mLayout, mLanguage);
            dialog.dismiss();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            getActivity().finish();
            dialog.dismiss();
        }
    });

    return builder.create();

}

From source file:com.example.amapapplicationtest.MainActivity.java

public void onProviderDisabled(String provider) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Phone is in airplane mode");
    builder.setCancelable(false);
    builder.setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            Intent startGps = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(startGps);/*www.  j ava 2s .c  o  m*/
        }
    });
    builder.setNegativeButton("Leave GPS off", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.xbmc.android.remote.presentation.controller.AbstractController.java

protected void showDialog(final AlertDialog.Builder builder) {
    builder.setCancelable(true);
    builder.setNegativeButton("Close", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();//w ww .ja  va  2s .c  o m
            mDialogShowing = false;
            //            ConnectionManager.resetClient();
        }
    });

    mActivity.runOnUiThread(new Runnable() {
        public void run() {
            final AlertDialog alert = builder.create();
            try {
                if (!mDialogShowing) {
                    alert.show();
                    mDialogShowing = true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.gmail.at.faint545.fragments.HistoryFragment.java

private AlertDialog buildAlertDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage(R.string.connect_error);
    builder.setCancelable(false);
    builder.setNegativeButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override// w  w  w .j  av a  2  s  . com
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    return builder.create();
}

From source file:com.owncloud.android.CrashlogSendActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_SUBMIT) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.crashlog_message);
        builder.setNegativeButton(R.string.crashlog_dont_send_report, this);
        builder.setPositiveButton(R.string.crashlog_send_report, this);
        builder.setCancelable(true);
        builder.setOnCancelListener(this);
        return builder.create();
    }/*  w  w w  .j a va  2s .  c o  m*/
    return super.onCreateDialog(id);
}