Example usage for android.app AlertDialog.Builder setTitle

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

Introduction

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

Prototype

@Override
    public void setTitle(CharSequence title) 

Source Link

Usage

From source file:fr.cph.chicago.util.Util.java

/**
 * Function to show settings alert dialog
 *///w  ww  .  j  a v a  2 s  . c o m
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:nl.mpcjanssen.simpletask.util.Util.java

public static Dialog createSingleChoiceDialog(Context cxt, CharSequence[] keys, String[] values, int selected,
        Integer titleId, Integer iconId, final OnSingleChoiceDialogListener listener) {

    assert (values.length == keys.length);
    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
    if (iconId != null) {
        builder.setIcon(iconId);//w w w .  jav  a 2 s. c o  m
    }
    if (titleId != null) {
        builder.setTitle(titleId);
    }

    final String[] res = values;
    final int checkedItem = selected;

    builder.setSingleChoiceItems(keys, checkedItem, null);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
            listener.onClick(res[index]);
        }
    });
    builder.setNegativeButton(R.string.cancel, null);
    return builder.create();
}

From source file:nl.mpcjanssen.simpletask.util.Util.java

public static Dialog createMultiChoiceDialog(Context cxt, CharSequence[] keys, boolean[] values,
        Integer titleId, Integer iconId, final OnMultiChoiceDialogListener listener) {
    final boolean[] res;
    if (values == null) {
        res = new boolean[keys.length];
    } else {//w  w w  .  j  a  v a  2  s .c o m
        res = values;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
    if (iconId != null) {
        builder.setIcon(iconId);
    }
    if (titleId != null) {
        builder.setTitle(titleId);
    }
    builder.setMultiChoiceItems(keys, values, new DialogInterface.OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            res[whichButton] = isChecked;
        }
    });
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            listener.onClick(res);
        }
    });
    builder.setNegativeButton(R.string.cancel, null);
    return builder.create();
}

From source file:com.todotxt.todotxttouch.util.Util.java

public static Dialog createMultiChoiceDialog(Context cxt, CharSequence[] keys, boolean[] values,
        Integer titleId, Integer iconId, final OnMultiChoiceDialogListener listener) {
    final boolean[] res;

    if (values == null) {
        res = new boolean[keys.length];
    } else {//from  www.  j a v a2s .  c  o m
        res = values;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);

    if (iconId != null) {
        builder.setIcon(iconId);
    }

    if (titleId != null) {
        builder.setTitle(titleId);
    }

    builder.setMultiChoiceItems(keys, values, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            res[whichButton] = isChecked;
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            listener.onClick(res);
        }
    });

    builder.setNegativeButton(R.string.cancel, null);

    return builder.create();
}

From source file:mp.paschalis.App.java

/**
 * Finds out if network connection is available
 *//*from   w  w w. j  a va 2  s .c  o m*/
public static void isNetworkAvailable(final Context ctx) {
    ConnectivityManager connectivityManager = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

    if (activeNetworkInfo == null) {
        {
            AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
            alert.setTitle(R.string.msgNoInternetConnectionTitle);
            alert.setMessage(R.string.msgNoInternetConnection);
            alert.setIcon(android.R.drawable.ic_dialog_alert);

            alert.setNeutralButton(R.string.no, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                }
            });

            alert.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    ctx.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
                }
            });

            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);//from w w w .  jav a 2s  .  c  o  m
    b.setPositiveButton(R.string.auth_logout, onLogoutHandler);
    b.setNegativeButton(android.R.string.cancel, null);

    return b.create();
}

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   ww  w  . j a  v  a  2  s . c o  m*/
 * @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:com.ibuildapp.romanblack.CataloguePlugin.utils.Utils.java

/**
 * Show alert dialog with passed params//from w  w  w  .j av  a2s  . co  m
 *
 * @param context                     context
 * @param title                       title of dialog
 * @param message                     message of dialog
 * @param positiveButtonText          text of positive button (OK, for example)
 * @param negativeButtonText          text of positive button (CANCEL, for example)
 * @param onDialogButtonClickListener listener of clicks dialog's buttons
 */
public static void showDialog(final Context context, final int title, final String message,
        final int positiveButtonText, final int negativeButtonText,
        final OnDialogButtonClickListener onDialogButtonClickListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message);
    builder.setTitle(title);
    builder.setCancelable(false);
    builder.setPositiveButton(positiveButtonText,
            onDialogButtonClickListener != null ? new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onDialogButtonClickListener.onPositiveClick(dialog);
                }
            } : null);
    builder.setNegativeButton(negativeButtonText,
            onDialogButtonClickListener != null ? new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onDialogButtonClickListener.onNegativeClick(dialog);
                }
            } : null);
    builder.create().show();
}

From source file:org.ubicompforall.cityexplorer.CityExplorer.java

/**
  * Display a dialog that user has no Internet connection
  * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html
 * @return //from w  ww .  j a  va  2 s  .  co m
  */
public static AlertDialog showNoConnectionDialog(final Context myContext, final String msg,
        final String cancelButtonStr, final Intent cancelIntent) {
    AlertDialog.Builder builder = new AlertDialog.Builder(myContext);
    builder.setCancelable(true);
    if (msg == "") {
        builder.setMessage(R.string.no_connection);
    } else {
        builder.setMessage(msg);
    }
    builder.setTitle(R.string.no_connection_title);
    builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            myContext.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
        }
    });

    String cancelText = cancelButtonStr;
    if (cancelText == "") {
        cancelText = myContext.getResources().getString(R.string.cancel);
    }
    builder.setNegativeButton(cancelText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (cancelIntent != null) {
                if (myContext instanceof Activity) {
                    ((Activity) myContext).startActivityForResult(cancelIntent, CityExplorer.REQUEST_LOCATION);
                } else {
                    debug(-1, "This is not an Activity!!");
                }
                dialog.dismiss();
            }
            return;
        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            if (myContext == null) {
                debug(0, "OOOPS!");
            } else {
                Toast.makeText(myContext, "CANCELLED!", Toast.LENGTH_LONG).show();
                if (cancelIntent != null) {
                    myContext.startActivity(cancelIntent);
                }
            }
            return;
        }
    });

    DATACONNECTION_NOTIFIED = true;
    return builder.show();
}

From source file:palamarchuk.smartlife.app.RegisterActivity.java

public static void alert(Context context, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message);//from   ww  w.  ja  va 2  s  .  c  om
    builder.setTitle("");

    builder.setPositiveButton("Ok", null);
    builder.show();
}