Example usage for android.app AlertDialog.Builder setIcon

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

Introduction

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

Prototype

public void setIcon(Drawable icon) 

Source Link

Usage

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 {/*from  ww w . j  av  a2 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   w w w.java2 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() {
        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:org.adaway.helper.ResultHelper.java

/**
 * Trying to create symlink and displays dialogs on fail
 *///w  w  w  .j av  a  2  s  .  c  om
private static void tryToCreateSymlink(final Context context) {
    boolean success = true;

    try {
        // symlink to /system/etc/hosts, based on target
        if (PreferenceHelper.getApplyMethod(context).equals("writeToDataData")) {
            ApplyUtils.createSymlink(Constants.ANDROID_DATA_DATA_HOSTS);
        } else if (PreferenceHelper.getApplyMethod(context).equals("writeToData")) {
            ApplyUtils.createSymlink(Constants.ANDROID_DATA_HOSTS);
        } else if (PreferenceHelper.getApplyMethod(context).equals("customTarget")) {
            ApplyUtils.createSymlink(PreferenceHelper.getCustomTarget(context));
        }
    } catch (CommandException e) {
        Log.e(Constants.TAG, "CommandException", e);

        success = false;
    } catch (RemountException e) {
        Log.e(Constants.TAG, "RemountException", e);

        success = false;
    }

    if (success) {
        if (ApplyUtils.isHostsFileCorrect(context, Constants.ANDROID_SYSTEM_ETC_HOSTS)) {
            success = true;
        } else {
            success = false;
        }
    }

    if (success) {
        BaseActivity.updateStatusEnabled(context);

        if (!PreferenceHelper.getNeverReboot(context)) {
            Utils.rebootQuestion(context, R.string.apply_symlink_successful_title,
                    R.string.apply_symlink_successful);
        }
    } else {
        BaseActivity.updateStatusDisabled(context);

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(R.string.apply_symlink_fail_title);
        builder.setMessage(context.getString(R.string.apply_symlink_fail) + "\n\n"
                + context.getString(R.string.apply_help));
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setPositiveButton(context.getString(R.string.button_close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
        builder.setNegativeButton(context.getString(R.string.button_help),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();

                        // go to help
                        context.startActivity(new Intent(context, HelpActivity.class));
                    }
                });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}

From source file:mp.paschalis.App.java

/**
 * Finds out if network connection is available
 *///  w  w w.j a  va 2s. 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:org.adaway.helper.ResultHelper.java

/**
 * Shows dialog and further information how to proceed after the applying process has ended and
 * the user clicked on the notification. This is based on the result from the apply process.
 *
 * @param result/*from  w ww .  ja  va  2s . c  o m*/
 */
public static void showDialogBasedOnResult(final Context context, int result,
        String numberOfSuccessfulDownloads) {
    if (result == StatusCodes.SUCCESS) {
        if (numberOfSuccessfulDownloads != null) {
            String title = context.getString(R.string.apply_success_title);
            String text = context.getString(R.string.apply_success_subtitle) + " "
                    + numberOfSuccessfulDownloads;

            BaseActivity.setStatusBroadcast(context, title, text, StatusCodes.ENABLED);
        } else {
            BaseActivity.updateStatusEnabled(context);
        }

        Utils.rebootQuestion(context, R.string.apply_success_title, R.string.apply_success_dialog);
    } else if (result == StatusCodes.REVERT_SUCCESS) {
        BaseActivity.updateStatusDisabled(context);

        Utils.rebootQuestion(context, R.string.revert_successful_title, R.string.revert_successful);
    } else if (result == StatusCodes.ENABLED) {
        BaseActivity.updateStatusEnabled(context);
    } else if (result == StatusCodes.DISABLED) {
        BaseActivity.updateStatusDisabled(context);
    } else if (result == StatusCodes.UPDATE_AVAILABLE) {
        String title = context.getString(R.string.status_update_available);
        String text = context.getString(R.string.status_update_available_subtitle);

        BaseActivity.setStatusBroadcast(context, title, text, StatusCodes.UPDATE_AVAILABLE);
    } else if (result == StatusCodes.SYMLINK_MISSING) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(R.string.apply_symlink_missing_title);
        builder.setMessage(context.getString(R.string.apply_symlink_missing));
        builder.setIcon(android.R.drawable.ic_dialog_info);
        builder.setPositiveButton(context.getString(R.string.button_yes),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        tryToCreateSymlink(context);
                    }
                });
        builder.setNegativeButton(context.getString(R.string.button_no), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();

                BaseActivity.updateStatusDisabled(context);
            }
        });
        AlertDialog question = builder.create();
        question.show();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setPositiveButton(context.getString(R.string.button_close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
        builder.setNegativeButton(context.getString(R.string.button_help),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();

                        // go to help
                        context.startActivity(new Intent(context, HelpActivity.class));
                    }
                });

        String title = "";
        String text = "";
        String statusText = "";
        switch (result) {
        case StatusCodes.NO_CONNECTION:
            title = context.getString(R.string.no_connection_title);
            text = context.getString(R.string.no_connection);
            statusText = context.getString(R.string.status_no_connection_subtitle);

            BaseActivity.setStatusBroadcast(context, title, statusText, StatusCodes.DOWNLOAD_FAIL);
            break;
        case StatusCodes.DOWNLOAD_FAIL:
            title = context.getString(R.string.download_fail_title);
            text = context.getString(R.string.download_fail_dialog);
            statusText = context.getString(R.string.status_download_fail_subtitle_new);

            BaseActivity.setStatusBroadcast(context, title, statusText, StatusCodes.DOWNLOAD_FAIL);
            break;
        case StatusCodes.APN_PROXY:
            title = context.getString(R.string.apply_apn_proxy_title);
            text = context.getString(R.string.apply_apn_proxy);

            BaseActivity.updateStatusEnabled(context);
            break;
        case StatusCodes.APPLY_FAIL:
            title = context.getString(R.string.apply_fail_title);
            text = context.getString(R.string.apply_fail);

            BaseActivity.updateStatusDisabled(context);
            break;
        case StatusCodes.PRIVATE_FILE_FAIL:
            title = context.getString(R.string.apply_private_file_fail_title);
            text = context.getString(R.string.apply_private_file_fail);

            BaseActivity.updateStatusDisabled(context);
            break;
        case StatusCodes.NOT_ENOUGH_SPACE:
            title = context.getString(R.string.apply_not_enough_space_title);
            text = context.getString(R.string.apply_not_enough_space);

            BaseActivity.updateStatusDisabled(context);
            break;
        case StatusCodes.REMOUNT_FAIL:
            title = context.getString(R.string.apply_remount_fail_title);
            text = context.getString(R.string.apply_remount_fail);

            BaseActivity.updateStatusDisabled(context);
            break;
        case StatusCodes.COPY_FAIL:
            title = context.getString(R.string.apply_copy_fail_title);
            text = context.getString(R.string.apply_copy_fail);

            BaseActivity.updateStatusDisabled(context);
            break;
        case StatusCodes.REVERT_FAIL:
            title = context.getString(R.string.revert_problem_title);
            text = context.getString(R.string.revert_problem);

            // back to old status
            if (ApplyUtils.isHostsFileCorrect(context, Constants.ANDROID_SYSTEM_ETC_HOSTS)) {
                BaseActivity.updateStatusEnabled(context);
            } else {
                BaseActivity.updateStatusDisabled(context);
            }
            break;
        }
        text += "\n\n" + context.getString(R.string.apply_help);
        builder.setTitle(title);
        builder.setMessage(text);

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

From source file:net.naonedbus.utils.InfoDialogUtils.java

/**
 * Afficher une dialog avec un contenu au format HTML
 * /*w  ww  .  j a v  a  2  s .  c o m*/
 * @param context
 * @param html
 */
public static void showHtml(final Context context, final String html) {
    AlertDialog.Builder moreDetailsDialog = null;
    final WebView webView = new WebView(context);
    final ScrollView scrollView = new ScrollView(context);

    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(Color.WHITE);
    webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "UTF-8", null); // Encoding
    // fix
    // for
    // Android
    // 3.x
    // /
    // 4.x
    scrollView.addView(webView);

    moreDetailsDialog = new AlertDialog.Builder(context);
    moreDetailsDialog.setIcon(android.R.drawable.ic_dialog_info);
    moreDetailsDialog.setTitle("Informations");
    moreDetailsDialog.setView(scrollView);
    moreDetailsDialog.setPositiveButton(android.R.string.ok, null);
    moreDetailsDialog.show();
}

From source file:org.geek.utils.ApplicationUtils.java

/**
 * Display a continue / cancel dialog./* www  .j  av a 2 s  . c om*/
 * @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:org.geek.utils.ApplicationUtils.java

/**
 * Display a standard Ok dialog.//from  w  w  w  .  j  av a 2s.  c om
 * @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.//  ww  w  .  ja v  a  2s  . 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./*  ww w .  j a v a 2 s .  co  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();
}