Example usage for android.app AlertDialog.Builder create

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

Introduction

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

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:net.phamngochai.beefnoodle.ui.DownloadDictionaryActivity.java

public void showAlertDialog(String str) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(str).setCancelable(false).setNeutralButton("OK", null);
    AlertDialog alert = builder.create();
    alert.show();// www  .  j a  v  a2s  .  com
}

From source file:com.fanfou.app.opensource.service.DownloadService.java

public static void showUpdateConfirmDialog(final Context context, final AppVersionInfo info) {
    final DialogInterface.OnClickListener downListener = new DialogInterface.OnClickListener() {

        @Override//from ww w.  jav  a2  s . co m
        public void onClick(final DialogInterface dialog, final int which) {
            DownloadService.startDownload(context, info);
        }
    };
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("???").setCancelable(true).setNegativeButton("??",
            null);
    builder.setPositiveButton("??", downListener);
    final StringBuffer sb = new StringBuffer();
    sb.append("").append(AppContext.appVersionName).append("(Build")
            .append(AppContext.appVersionCode).append(")");
    sb.append("\n").append(info.versionName).append("(Build").append(info.versionCode)
            .append(")");
    sb.append("\n").append(info.releaseDate);
    sb.append("\n").append(info.forceUpdate ? "???" : "?");
    sb.append("\n\n").append(info.changelog);
    builder.setMessage(sb.toString());
    final AlertDialog dialog = builder.create();
    dialog.show();

}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Asks the user for confirmation of a delete all inbound devices operation.
 * /*from w ww .j  av  a 2 s .  com*/
 * <p>
 * If the user confirms the operation, all devices are removed from the list
 * of inbound paired devices.
 * 
 * @param activity
 *            the caller activity
 */
public static void confirmUnpairAllInbound(final MainActivity activity) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // @formatter:off
            AlertDialog.Builder builder = getBuilder(activity)
                    .setMessage(getResources().getString(R.string.delete_all_inbound_confirm))
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            activity.deleteAllInbound();
                        }
                    }).setNegativeButton(android.R.string.cancel, null);
            // @formatter:on
            return builder.create();
        }
    }.show(activity.getSupportFragmentManager(), "removeAllInbound");
}

From source file:com.pdftron.pdf.utils.Utils.java

public static void showAlertDialogWithLink(Context context, String message, String title) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setMessage(Html.fromHtml(message)).setCancelable(true).setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {

                @Override/*  ww w  .  ja  va 2  s  .c o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    if (title.length() > 0) {
        builder.setTitle(title);
    }
    final AlertDialog d = builder.create();
    d.show();

    // Make the textview clickable. Must be called after show()
    ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Asks the user for confirmation of a delete outbound device operation.
 * /*  w ww.  j av a2 s . com*/
 * <p>
 * If the user confirms the operation, the current outbound device is
 * deleted.
 * 
 * @param outboundDevice
 *            the device being removed
 * @param activity
 *            the caller activity
 */
public static void confirmRemoveOutbound(final PairedDevice outboundDevice, final MainActivity activity) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // @formatter:off
            AlertDialog.Builder builder = getBuilder(activity).setMessage(
                    getResources().getString(R.string.remove_outbound_paired_message, outboundDevice.type))
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            activity.deleteOutboundDevice();
                        }
                    }).setNegativeButton(android.R.string.cancel, null);
            // @formatter:on
            return builder.create();
        }
    }.show(activity.getSupportFragmentManager(), "removeInbound");
}

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

/**
 * Display a standard Ok 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.
 */
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:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog informing the user about what went wrong while trying to
 * registrate her device with GCM./*  w w w .  j a  va  2 s .com*/
 * 
 * @param errorCode
 *            the error message's resource ID within <tt>strings.xml</tt>
 * @param activity
 *            the caller activity
 * @param finishActivityOnOk
 *            whether the call comes from an activity with no UI that
 *            requires clicks on ok (or back) to call
 *            {@link Activity#finish()} on the caller activity
 */
public static void onRegistrationError(final int errorCode, final FragmentActivity activity,
        final boolean finishActivityOnOk) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder;
            if (finishActivityOnOk) {
                builder = getNoUiBuilder(activity);
            } else {
                builder = getBuilder(activity);
            }
            builder.setMessage(getString(R.string.gcm_registration_error, getString(errorCode)));
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // just hide dialog
                }
            });
            Dialog dialog = builder.create();
            dialog.setCanceledOnTouchOutside(!finishActivityOnOk);
            return dialog;
        }
    }.show(activity.getSupportFragmentManager(), "gcm_error");
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Asks the user for confirmation of a delete inbound device operation.
 * //  www .ja va  2 s  .c om
 * <p>
 * If the user confirms the operation, the device is removed from the list
 * of paired devices.
 * 
 * @param deviceToBeUnpaired
 *            the device to be removed from the list of paired devices
 * @param activity
 *            the caller activity
 */
public static void confirmUnpairInbound(final PairedDevice deviceToBeUnpaired, final MainActivity activity) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // @formatter:off
            AlertDialog.Builder builder = getBuilder(activity)
                    .setMessage(getResources().getString(R.string.remove_inbound_paired_message,
                            deviceToBeUnpaired.name))
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            activity.removePaired();
                        }
                    }).setNegativeButton(android.R.string.cancel, null);
            // @formatter:on
            return builder.create();
        }
    }.show(activity.getSupportFragmentManager(), "removeInbound");
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java

/**
 * Creates a dialog for given message.//ww  w.  java 2  s  . co m
 *
 * @param activity
 *            Parent activity.
 * @param message
 *            Message contents
 * @param dismissListener
 *            Listener that will be called when dialog is closed or
 *            cancelled.
 * @return Created dialog.
 */
public static Dialog createMessageDialog(Activity activity, Message message,
        OnDismissListener dismissListener) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    final String title = message.description == null ? null
            : message.description.get(MessageDescription.KEY_TITLE);
    if (!Utilities.isNullOrEmpty(title)) {
        builder.setTitle(title);
    }

    final View dialogContentsView = createMessageDialogContentsView(activity, message.description);
    builder.setView(dialogContentsView);

    initializeMessageDialogButtons(activity, builder, message);
    builder.setCancelable(true);

    final AlertDialog dialog = builder.create();

    if (Utilities.isNullOrEmpty(title)) {
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }

    dialog.setOnDismissListener(dismissListener);
    return dialog;
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog to get a name for the inbound device being paired and
 * starts a new {@link CallGooGlInbound} action if the chosen name is valid.
 * /*ww  w.java  2  s.  co m*/
 * @param deviceType
 *            the model of the device being paired as suggested by the
 *            device itself
 * @param sharedSecret
 *            the keys used when encrypting the message between devices
 * @param activity
 *            the caller activity
 */
public static void promptForInboundName(final String deviceType, final int[] sharedSecret,
        final MainActivity activity) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        @Override
        public void run() {
            DialogFragment prompt = new PatchedDialogFragment() {
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                    AlertDialog.Builder builder = getBuilder(activity);
                    final EditText input = new EditText(getContext());
                    input.setInputType(InputType.TYPE_CLASS_TEXT);
                    input.setText(deviceType);
                    input.setSelection(deviceType.length());
                    // @formatter:off
                    builder.setTitle(R.string.device_name_chooser_title).setView(input)
                            .setPositiveButton(android.R.string.ok, null);
                    // @formatter:on
                    final AlertDialog alertDialog = builder.create();
                    alertDialog.setOnShowListener(
                            new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() {

                                @Override
                                public void run() {
                                    // @formatter:off
                                    new CallGooGlInbound(activity, getParam(), deviceType)
                                            .execute(sharedSecret);

                                    ((InputMethodManager) activity
                                            .getSystemService(Context.INPUT_METHOD_SERVICE))
                                                    .hideSoftInputFromWindow(input.getWindowToken(), 0);
                                    // @formatter:on
                                }
                            }));
                    return alertDialog;
                }
            };
            prompt.show(activity.getSupportFragmentManager(), "chooseName");
        }
    });
}