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:nf.frex.android.FrexActivity.java

public static void showYesNoDialog(Context context, int titleId, String message,
        DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener,
        DialogInterface.OnCancelListener cancelListener) {

    TextView textView = new TextView(context);
    textView.setSingleLine(false);//w w  w .  j ava  2s  .  com
    textView.setPadding(10, 10, 10, 10);
    textView.setText(message);

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(titleId);
    b.setView(textView);
    b.setCancelable(true);
    if (yesListener != null) {
        b.setPositiveButton(android.R.string.yes, yesListener);
    }
    if (noListener != null) {
        b.setNegativeButton(android.R.string.no, noListener);
    }
    if (cancelListener != null) {
        b.setOnCancelListener(cancelListener);
    }
    b.show();
}

From source file:au.id.micolous.frogjump.Util.java

private static void newVersionAlert(final Activity activity) {
    // We have a new version available.  Prompt.
    AlertDialog.Builder updateDialog = new AlertDialog.Builder(activity);
    updateDialog.setTitle(R.string.update_available_title);
    updateDialog.setMessage(R.string.update_available_message);
    updateDialog.setPositiveButton(R.string.update_positive, new DialogInterface.OnClickListener() {
        @Override//from  w ww .ja  va 2  s  .  co m
        public void onClick(DialogInterface dialogInterface, int i) {
            try {
                activity.startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
            } catch (ActivityNotFoundException anfe) {
                // Hmm, market is not installed
                Log.w(TAG, "Google Play is not installed; cannot install update");
            }
        }
    });
    updateDialog.setNegativeButton(R.string.update_negative, null);
    updateDialog.setCancelable(true);
    updateDialog.show();

}

From source file:com.nikhilnayak.games.octoshootar.ui.dialogfragments.SimpleDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle arguments = getArguments();
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setCancelable(true);
    builder.setPositiveButton(android.R.string.ok, null);

    // Set the title
    if (arguments.containsKey(ARGS_TITLE)) {
        builder.setTitle(arguments.getInt(ARGS_TITLE));
    }//ww  w. j a  va2s.c  om

    // Set the message
    if (arguments.containsKey(ARGS_MESSAGE)) {
        builder.setMessage(arguments.getInt(ARGS_MESSAGE));
    }

    return builder.create();
}

From source file:com.ivan.autosms.MainActivity.java

public void openErrorDialog(String errorMessage) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setMessage(errorMessage);
    dialogBuilder.setCancelable(true);

    dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();/*from  ww  w.  j a va 2 s  .  co m*/
        }
    });

    AlertDialog errorDialog = dialogBuilder.create();
    errorDialog.show();
}

From source file:com.ivan.autosms.MainActivity.java

public void openSendDialog(int nMessages, String licensePlate, String endTimeText) {
    String sendDialogMessage = "This will send %d SMS for license plate %s. Your ticket will be valid until %s.";
    String messageText = String.format(Locale.getDefault(), sendDialogMessage, nMessages, licensePlate,
            endTimeText);//from w w  w . java 2 s.c o  m
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setMessage(messageText);
    dialogBuilder.setCancelable(true);

    dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            s.send();
        }
    });

    dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    AlertDialog sendDialog = dialogBuilder.create();
    sendDialog.show();
}

From source file:ca.ualberta.slevinsk.gameshow.NumberPickerFragment.java

@NonNull
@Override// w ww .j  a  va  2  s . com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("How many players?");

    builder.setCancelable(false);
    numberPicker = new NumberPicker(getContext());
    numberPicker.setMinValue(2);
    numberPicker.setMaxValue(4);
    numberPicker.setOnValueChangedListener(onPlayerCountChangeListener);

    builder.setView(numberPicker);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    return builder.create();
}

From source file:com.example.sergey.currentweather.dialog.MaterialSimpleDialog.java

@NonNull
@Override/*from   w  ww.j av a2s. c  o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);

    if (savedInstanceState != null) {
        mPositive = savedInstanceState.getString("yes");
        mNegative = savedInstanceState.getString("no");
        mTitle = savedInstanceState.getString("title");
    }
    Context dialogViewContext = getActivity();
    View dialogView = LayoutInflater.from(dialogViewContext).inflate(R.layout.simple_dialog, null);
    final TextInputEditText editText = (TextInputEditText) dialogView.findViewById(R.id.add_city_edit);
    editText.addTextChangedListener(new AddListenerOnTextChange(editText));
    AlertDialog.Builder adb = new AlertDialog.Builder(getActivity(), R.style.StyledDialog);
    adb.setView(dialogView);
    adb.setCancelable(false);
    adb.setTitle(mTitle);
    adb.setPositiveButton(mPositive, mDialogInterfaceListener);
    adb.setNegativeButton(mNegative, mDialogInterfaceListener);
    return adb.create();
}

From source file:com.thingsee.tracker.MainActivity.java

public static void showError(String errorMessage) {
    final AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(mContext);
    errorDialogBuilder.setCancelable(false).setTitle(R.string.title_error)
            .setNeutralButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                }//from w  w  w . j a  va 2  s. c  o  m
            }).setMessage(errorMessage);
    AlertDialog alertDialog = errorDialogBuilder.create();
    alertDialog.show();
}

From source file:com.gmail.at.faint545.activities.DetailsActivity.java

private AlertDialog buildAlertDialog(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(message);//from www. j a v  a 2  s .  c  o  m
    builder.setCancelable(false);
    builder.setNegativeButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    return builder.create();
}

From source file:com.robomorphine.fragment.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View view = inflater.inflate(R.layout.fragment_about, null);

    TextView version = (TextView) view.findViewById(R.id.version);
    TextView author = (TextView) view.findViewById(R.id.author);
    TextView project = (TextView) view.findViewById(R.id.project);
    TextView license = (TextView) view.findViewById(R.id.license);
    TextView repo = (TextView) view.findViewById(R.id.repo);

    author.setMovementMethod(LinkMovementMethod.getInstance());
    project.setMovementMethod(LinkMovementMethod.getInstance());
    license.setMovementMethod(LinkMovementMethod.getInstance());
    repo.setMovementMethod(LinkMovementMethod.getInstance());

    version.setText(getVersion());/*from  w ww .j a  v  a2 s  .  c  o  m*/
    author.setText(linkify(R.string.author, R.string.author_link));
    project.setText(linkify(R.string.project, R.string.project_link));
    license.setText(linkify(R.string.license, R.string.license_link));
    repo.setText(linkify(R.string.repo, R.string.repo_link));

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.about);
    builder.setView(view);
    builder.setCancelable(true);
    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });

    return builder.create();
}