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:com.marinamalynkina.android.nearbyplaces.PermissionUtils.java

public static void showNoConnectionDialog(Context ctx1) {
    final Context ctx = ctx1;
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setCancelable(true);
    builder.setMessage("Internet not available, Cross check your internet connectivity and try again");
    builder.setTitle("Network problem");
    builder.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            ctx.startActivity(new Intent(Settings.ACTION_SETTINGS));
        }/*w w w. java2  s.c  om*/
    });
    //        builder.setNegativeButton("Continue", new DialogInterface.OnClickListener() {
    //            public void onClick(DialogInterface dialog, int which) {
    //                return;
    //            }
    //        });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            return;
        }
    });

    builder.show();
}

From source file:br.fucapi.fapeam.monitori.eula.Eula.java

public static void show(final FragmentActivity activity, int title, int closeLabel) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(title);/*from   w w  w  .jav a2 s  . c om*/
    builder.setCancelable(true);
    builder.setNeutralButton(closeLabel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.setMessage(readEula(activity));
    builder.create().show();
}

From source file:Main.java

public static void showChangelog(final Context context, final String title, final String appname,
        final int resChanges, final int resNotes) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;/*from www .  j  a v a  2 s  .  c om*/
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    p.edit().putString(PREFS_LAST_RUN, v1).commit();
    if (v0.length() == 0) {
        Log.d(TAG, "first boot, skip changelog");
        // return;
    }
    if (v0.equals(v1)) {
        Log.d(TAG, "no changes");
        return;
    }

    String[] changes = context.getResources().getStringArray(resChanges);
    String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null;

    final SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String s : notes) {
        SpannableString ss = new SpannableString(s + "\n");
        int j = s.indexOf(":");
        if (j > 0) {
            if (!TextUtils.isEmpty(s)) {
                ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        sb.append(ss);
        sb.append("\n");
    }
    if (notes != null && notes.length > 0) {
        sb.append("\n");
    }
    for (String s : changes) {
        s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n";
        SpannableString ss = new SpannableString(s);
        int j = s.indexOf(":");
        if (j > 0) {
            ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        sb.append(ss);
        sb.append("\n");
    }
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    changes = null;
    notes = null;

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}

From source file:org.ptlug.ptwifiauth.Utilities.java

public static void showSimpleAlertDialog(Activity act, String title, String text, String button) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(act);
    alertDialog.setTitle(title);//  w  w  w .j  a v a2  s.com
    alertDialog.setMessage(text);
    alertDialog.setCancelable(false);
    alertDialog.setPositiveButton(button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialog.show();
}

From source file:Main.java

public static void showYesNoPrompt(Context _context, String title, String message,
        OnClickListener onYesListener, OnClickListener onNoListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(_context);
    builder.setTitle(title);//  w ww  . j  a v a 2s. c om
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setMessage(message);
    builder.setCancelable(false);
    builder.setPositiveButton("Yes", onYesListener);
    builder.setNegativeButton("No", onNoListener);
    boolean show = true;
    if (_context instanceof Activity) {
        Activity activity = (Activity) _context;
        if (activity.isFinishing()) {
            show = false;
        }
    }
    if (show)
        builder.show();
}

From source file:br.fucapi.fapeam.monitori.eula.Eula.java

/**
 * Displays the EULA if necessary. This method should be called from the
 * onCreate() method of your main Activity.
 * /*ww  w.  ja  va2  s. c om*/
 * @param activity
 *            The Activity to finish if the user rejects the EULA.
 * @return Whether the user has agreed already.
 */
public static boolean show(final Activity activity, int title, int acceptLabel, int refuseLabel) {
    final SharedPreferences preferences = activity.getSharedPreferences(PREFERENCES_EULA,
            Activity.MODE_PRIVATE);
    if (!preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(title);
        builder.setCancelable(true);
        builder.setPositiveButton(acceptLabel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                accept(preferences);
                if (activity instanceof OnEulaAgreedTo) {
                    ((OnEulaAgreedTo) activity).onEulaAgreedTo();
                }
            }
        });
        builder.setNegativeButton(refuseLabel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                refuse(activity);
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                refuse(activity);
            }
        });
        builder.setMessage(readEula(activity));
        builder.create().show();
        return false;
    }
    return true;
}

From source file:com.readingcards.util.ActivityUtils.java

public static AlertDialog.Builder showCalltoActionDialog(final Activity context, String title, String message,
        String negativeMessage) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AppCompatAlertDialogStyle);
    builder.setTitle(title);/*  w w w . j  a v a 2s  .com*/
    builder.setMessage(message);
    builder.setNegativeButton(negativeMessage, null);
    builder.setCancelable(false);

    return builder;
}

From source file:Main.java

public static AlertDialog createAlert(String title, String message, Context context) {
    // Make an AlertDialog builder
    AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
    //TODO: extract string
    // Set title//from   ww  w.  j  a v a2s.co m
    builder1.setTitle(title);
    // Set message
    builder1.setMessage(message);
    // Set cancelable
    builder1.setCancelable(true);
    // Build a new neutral button dialog
    builder1.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        // On click of the neutral button
        public void onClick(DialogInterface dialog, int id) {
            // Cancel the dialog
            dialog.cancel();
        }
    });
    // Create the AlertDialog
    AlertDialog alert11 = builder1.create();
    return alert11;

}

From source file:com.ecml.ChooseSongActivity.java

/** Show an error dialog with the given message */
public static void showErrorDialog(String message, Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(message);//from  w ww .j  a  v  a 2 s  .co m
    builder.setCancelable(false);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.example.atos.myapplication.global.PermissionUtils.java

public static boolean checkPermission(final Context context) {
    int currentAPIVersion = Build.VERSION.SDK_INT;
    if (currentAPIVersion >= android.os.Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(context,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
                alertBuilder.setCancelable(true);
                alertBuilder.setTitle("Permission necessary");
                alertBuilder.setMessage("External storage permission is necessary");
                alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        ActivityCompat.requestPermissions((Activity) context,
                                new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                                MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
                    }/*from w w w  . j  a v a2 s.  c om*/
                });
                AlertDialog alert = alertBuilder.create();
                alert.show();
            } else {
                ActivityCompat.requestPermissions((Activity) context,
                        new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                        MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
            }
            return false;
        } else {
            return true;
        }
    } else {
        return true;
    }
}