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:org.cinedroid.util.CineworldAPIAssistant.java

/**
 * Create a dialog with the text "Problem connecting to the Cineworld API", with two buttons, "Retry", which will re run the task, and
 * "Back" which will close the owningActivity.
 * //from w  w  w  .  j a  va2 s  . c  o m
 * @param owningActivity
 * @param task
 */
public static void createCineworldAPIErrorDialog(final Activity owningActivity, final ResurrectableTask task) {
    AlertDialog.Builder builder = new AlertDialog.Builder(owningActivity);
    builder.setMessage("Problem connecting to the Cineworld API");
    builder.setCancelable(false);
    builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            task.resurrect();
        }
    });
    builder.setNegativeButton("Back", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            owningActivity.finish();

        }
    });
    builder.create().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.  j  a va  2 s .co m*/
    b.setPositiveButton(R.string.auth_logout, onLogoutHandler);
    b.setNegativeButton(android.R.string.cancel, null);

    return b.create();
}

From source file:com.otaupdater.utils.UserUtils.java

public static void showLoginDialog(final Context ctx, String defUsername, final DialogCallback dlgCallback,
        final LoginCallback loginCallback) {
    @SuppressLint("InflateParams")
    View view = LayoutInflater.from(ctx).inflate(R.layout.login_dialog, null);
    if (view == null)
        return;//w  ww  .j a  v a 2s.  com
    final EditText inputUsername = (EditText) view.findViewById(R.id.auth_username);
    final EditText inputPassword = (EditText) view.findViewById(R.id.auth_password);

    if (defUsername != null)
        inputUsername.setText(defUsername);

    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle(R.string.alert_login_title);
    builder.setView(view);
    builder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            /* set below */ }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (loginCallback != null)
                loginCallback.onCancel();
        }
    });

    final AlertDialog dlg = builder.create();
    dlg.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            if (dlgCallback != null)
                dlgCallback.onDialogShown(dlg);
            Button button = dlg.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button == null)
                return;
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String username = inputUsername.getText().toString();
                    final String password = inputPassword.getText().toString();

                    if (username.length() == 0 || password.length() == 0) {
                        Toast.makeText(ctx, R.string.toast_blank_userpass_error, Toast.LENGTH_LONG).show();
                        return;
                    }

                    dlg.dismiss();

                    APIUtils.userLogin(ctx, username, password, new APIUtils.ProgressDialogAPICallback(ctx,
                            ctx.getString(R.string.alert_logging_in), dlgCallback) {
                        @Override
                        public void onSuccess(String message, JSONObject respObj) {
                            try {
                                String realUsername = respObj.getString("username");
                                String hmacKey = respObj.getString("key");
                                Config.getInstance(ctx).storeLogin(realUsername, hmacKey);
                                if (loginCallback != null)
                                    loginCallback.onLoggedIn(realUsername);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onError(String message, JSONObject respObj) {
                            //TODO show some error
                        }
                    });
                }
            });
        }
    });
    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (dlgCallback != null)
                dlgCallback.onDialogClosed(dlg);
        }
    });
    dlg.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 www.  ja v a 2s  . com
 * @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:Main.java

/**
 * @param context : the context that the dialog interface will be binded to
 * @param title :  dialog title// ww  w.  j  a  v a 2 s. c o m
 * @param positiveButtonText
 * @param positiveListener
 * @param negativeButtonText
 * @param negativeListener
 * @param neutralButtonText
 * @param neutralListener
 * @param content : Custom View for the dialog
 */
public static void showDialog(Context context, String title, String positiveButtonText,
        OnClickListener positiveListener, String negativeButtonText, OnClickListener negativeListener,
        String neutralButtonText, OnClickListener neutralListener, View content) {
    if (alert != null)
        hideDialog();

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

    if (content != null)
        builder.setView(content);

    builder.setMessage(title).setCancelable(false);

    if (negativeButtonText != null && negativeListener != null)
        builder.setNegativeButton(negativeButtonText, negativeListener);
    else
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

            }
        });

    if (positiveButtonText != null && positiveListener != null) {

        builder.setPositiveButton(positiveButtonText, positiveListener);
    }
    if (neutralButtonText != null && neutralListener != null)
        builder.setNeutralButton(neutralButtonText, neutralListener);
    alert = builder.create();

    alert.show();

}

From source file:Main.java

public static void yesNoMessage(final Activity activity, final String title, final String body,
        final String yesButtonLabel, final String noButtonLabel, final Runnable yesRunnable,
        final Runnable noRunnable) {
    activity.runOnUiThread(new Runnable() {
        @Override/*w ww  .  j a  v a2s . c o m*/
        public void run() {

            AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

            dialog.setTitle(title);
            dialog.setMessage(body);

            dialog.setPositiveButton(yesButtonLabel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (yesRunnable != null)
                        yesRunnable.run();
                }
            });

            dialog.setNegativeButton(noButtonLabel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (noRunnable != null)
                        noRunnable.run();
                }
            });

            dialog.create();
            dialog.show();
        }
    });
}

From source file:com.wellsandwhistles.android.redditsp.reddit.api.RedditAPICommentAction.java

public static void onActionMenuItemSelected(final RedditRenderableComment renderableComment,
        final RedditCommentView commentView, final AppCompatActivity activity,
        final CommentListingFragment commentListingFragment, final RedditCommentAction action,
        final RedditChangeDataManager changeDataManager) {

    final RedditComment comment = renderableComment.getParsedComment().getRawComment();

    switch (action) {

    case UPVOTE://from  w  w  w  .  ja va2s.  co m
        action(activity, comment, RedditAPI.ACTION_UPVOTE, changeDataManager);
        break;

    case DOWNVOTE:
        action(activity, comment, RedditAPI.ACTION_DOWNVOTE, changeDataManager);
        break;

    case UNVOTE:
        action(activity, comment, RedditAPI.ACTION_UNVOTE, changeDataManager);
        break;

    case SAVE:
        action(activity, comment, RedditAPI.ACTION_SAVE, changeDataManager);
        break;

    case UNSAVE:
        action(activity, comment, RedditAPI.ACTION_UNSAVE, changeDataManager);
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_REPORT, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, comment.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY,
                StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(activity, CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.getIdAndType());
        intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case DELETE: {
        new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm)
                .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_DELETE, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        break;
    }

    case COMMENT_LINKS:
        final HashSet<String> linksInComment = comment.computeAllLinks();

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_comment);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_comment_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;

    case SHARE:

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.body) + "\r\n\r\n"
                + comment.getContextUrl().generateNonJsonUri().toString());

        activity.startActivityForResult(Intent.createChooser(mailer, activity.getString(R.string.action_share)),
                1);

        break;

    case COPY_TEXT: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.body));
        break;
    }

    case COPY_URL: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(comment.getContextUrl().context(null).generateNonJsonUri().toString());
        break;
    }

    case COLLAPSE: {
        commentListingFragment.handleCommentVisibilityToggle(commentView);
        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(comment.author).toString());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment).show(activity.getSupportFragmentManager(), null);
        break;

    case GO_TO_COMMENT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().context(null).toString());
        break;
    }

    case CONTEXT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().toString());
        break;
    }
    case ACTION_MENU:
        showActionMenu(activity, commentListingFragment, renderableComment, commentView, changeDataManager,
                comment.isArchived());
        break;

    case BACK:
        activity.onBackPressed();
        break;
    }
}

From source file:com.nadmm.airports.utils.NetworkUtils.java

public static void checkNetworkAndDownload(Context context, final Runnable runnable) {
    if (!NetworkUtils.isNetworkAvailable(context)) {
        UiUtils.showToast(context, "Please check your internet connection");
    }//from   w w  w  . ja  v a2s  .c  o m

    if (NetworkUtils.isConnectedToMeteredNetwork(context)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage("You are conneteced to a metered network such as mobile data"
                + " or tethered to mobile data.\nContinue download?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        runnable.run();
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    } else {
        runnable.run();
    }
}

From source file:ee.ioc.phon.android.speak.Utils.java

public static AlertDialog getYesNoDialog(Context context, String confirmationMessage, final Executable ex) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(confirmationMessage).setCancelable(false)
            .setPositiveButton(context.getString(R.string.buttonYes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ex.execute();/*from   w w w  .j a v a  2  s  .  c o m*/
                }
            }).setNegativeButton(context.getString(R.string.buttonNo), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    return builder.create();
}

From source file:com.theelix.libreexplorer.FileManager.java

/**
 * This Method use the file set by prepareCopy or PrepareCut and then paste the files
 */// w  w  w  . j  a  v a  2s  .co  m
public static void preparePaste() {
    //If we are running KK or later, show the "Choose Folder" dialog
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && getCurrentDirectory().getPath().contains(System.getenv("SECONDARY_STORAGE"))) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(
                "As Android 5.0, a new system is used for writing files to External Storage. Please press OK and Select THE EXACT FOLDER you pasted the files");
        builder.setPositiveButton(mContext.getString(R.string.dialog_ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                        ((Activity) mContext).startActivityForResult(intent, REQUEST_GET_DOCUMENT);
                    }
                });
        builder.create().show();
    } else {
        createDestFiles();
    }
}