List of usage examples for android.app AlertDialog.Builder setCancelable
public void setCancelable(boolean flag)
From source file:com.company.millenium.iwannask.MainActivity.java
public static void showNoConnectionDialog(Context ctx1) { final Context ctx = ctx1; AlertDialog.Builder builder = new AlertDialog.Builder(ctx, R.style.AlertDialog); builder.setCancelable(true); builder.setMessage(R.string.no_connection); builder.setTitle(R.string.no_connection_title); builder.setPositiveButton(R.string.settings_button_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); }//from w ww. j a v a 2 s . co m }); builder.setNegativeButton(R.string.cancel_button_text, 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:org.geek.utils.ApplicationUtils.java
/** * Display a continue / cancel dialog./*from w w w. ja v a2 s. c o m*/ * @param context The current context. * @param icon The dialog icon. * @param title The dialog title. * @param message The dialog message. * @param onContinue The dialog listener for the continue button. * @param onCancel The dialog listener for the cancel button. */ public static void showContinueCancelDialog(Context context, int icon, String title, String message, DialogInterface.OnClickListener onContinue, DialogInterface.OnClickListener onCancel) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(true); builder.setIcon(icon); builder.setTitle(title); builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton(context.getResources().getString(R.string.Commons_Continue), onContinue); builder.setNegativeButton(context.getResources().getString(R.string.Commons_Cancel), onCancel); AlertDialog alert = builder.create(); alert.show(); }
From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java
public static Dialog createLogoutDialog(Context context, LogoutHandler onLogoutHandler) { final AlertDialog.Builder b = new AlertDialog.Builder(context); final String appName = context.getString(R.string.app_name); b.setTitle(context.getString(R.string.auth_logout_title, appName)); b.setMessage(context.getString(R.string.auth_logout_message, appName)); b.setCancelable(true); b.setPositiveButton(R.string.auth_logout, onLogoutHandler); b.setNegativeButton(android.R.string.cancel, null); return b.create(); }
From source file:fr.cph.chicago.util.Util.java
/** * Function to show settings alert dialog *///from www. j a v a 2 s . c om static void showSettingsAlert(@NonNull final Activity activity) { new Thread() { public void run() { activity.runOnUiThread(() -> { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); alertDialogBuilder.setTitle("GPS settings"); alertDialogBuilder.setMessage( "GPS is not enabled. Do you want to go to settings main.java.fr.cph.chicago.res.menu?"); alertDialogBuilder.setCancelable(false).setPositiveButton("Yes", (dialog, id) -> { final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); activity.startActivity(intent); }).setNegativeButton("No", (dialog, id) -> dialog.cancel()); final AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }); } }.start(); }
From source file:org.geek.utils.ApplicationUtils.java
/** * Display a standard Ok dialog.// ww w. jav a 2 s .c o m * @param context The current context. * @param icon The dialog icon. * @param title The dialog title. * @param message The dialog message. */ public static void showOkDialog(Context context, int icon, String title, String message) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(false); builder.setIcon(icon); builder.setTitle(title); builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton(context.getResources().getString(R.string.Commons_Ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.geek.utils.ApplicationUtils.java
/** * Display a standard yes / no dialog.//from w w w. j a va 2 s . c o m * @param context The current context. * @param icon The dialog icon. * @param title The dialog title. * @param message The dialog message. * @param onYes The dialog listener for the yes button. */ public static void showYesNoDialog(Context context, int icon, int title, int message, DialogInterface.OnClickListener onYes) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(true); builder.setIcon(icon); builder.setTitle(context.getResources().getString(title)); builder.setMessage(context.getResources().getString(message)); builder.setInverseBackgroundForced(true); builder.setPositiveButton(context.getResources().getString(R.string.Commons_Yes), onYes); builder.setNegativeButton(context.getResources().getString(R.string.Commons_No), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.geek.utils.ApplicationUtils.java
/** * Display a standard Ok / Cancel dialog. * @param context The current context.//from www . j a v a 2 s . c o m * @param icon The dialog icon. * @param title The dialog title. * @param message The dialog message. * @param onYes The dialog listener for the yes button. */ public static void showOkCancelDialog(Context context, int icon, String title, String message, DialogInterface.OnClickListener onYes) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(true); builder.setIcon(icon); builder.setTitle(title); builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton(context.getResources().getString(R.string.Commons_Ok), onYes); builder.setNegativeButton(context.getResources().getString(R.string.Commons_Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.java
/** * Given a logout handler and information about the app, create a standard logout dialog box * that prompts the user if they want to logout. * * @param context//from w w w. j av a 2 s . c om * @param appName * the name of your app. This is integrated into the text using the * {@code auth_logout_title} and {@code auth_logout_message} string resources. * @param onLogoutHandler * @return */ public static Dialog createLogoutDialog(Context context, CharSequence appName, LogoutHandler onLogoutHandler) { final AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(context.getString(R.string.auth_logout_title, appName)); b.setMessage(context.getString(R.string.auth_logout_message, appName)); b.setCancelable(true); b.setPositiveButton(R.string.auth_logout, onLogoutHandler); b.setNegativeButton(android.R.string.cancel, null); return b.create(); }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
/** * This method checks a single permission at runtime. Required for Android versions Marshmallow (API version 23) and higher. * The request code must be handled in the onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) method * which has to be overridden in each activity that needs to request runtime permission. * * @param context the context// w w w .j av a 2 s .c o m * @param requestCode the request code to be handled in the onRequestPermissionsResult method of the calling activity * @param permission the requested permission * @param dialogTitle the dialog title for the rationale * @param dialogMessage the dialog message for the rationale * @return true if permission is granted, false otherwise */ public static boolean checkSinglePermission(@NonNull final Context context, final int requestCode, @NonNull final String permission, final String dialogTitle, final String dialogMessage, final boolean showRequestPermissionRationale) { int currentAPIVersion = Build.VERSION.SDK_INT; if (currentAPIVersion >= android.os.Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { if (showRequestPermissionRationale && ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context); alertBuilder.setCancelable(true); alertBuilder.setTitle(dialogTitle); alertBuilder.setMessage(dialogMessage); alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode); } }); AlertDialog alert = alertBuilder.create(); alert.show(); } else { ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode); } return false; } else { return true; } } else { return true; } }
From source file:it.evilsocket.dsploit.core.System.java
public static boolean checkNetworking(final Activity current) { if (Network.isWifiConnected(mContext) == false) { AlertDialog.Builder builder = new AlertDialog.Builder(current); builder.setCancelable(false); builder.setTitle("Error"); builder.setMessage("WiFi connectivity went down."); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override//from ww w.j av a 2 s . c om public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Bundle bundle = new Bundle(); bundle.putBoolean(WifiScannerActivity.CONNECTED, false); Intent intent = new Intent(); intent.putExtras(bundle); current.setResult(Activity.RESULT_OK, intent); current.finish(); } }); AlertDialog alert = builder.create(); alert.show(); return false; } return true; }