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.gplvote.signdoc.MainActivity.java

public static void alert(String text, final Activity activity, final boolean parent_exit) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.title_warning).setIcon(R.drawable.notification_icon).setMessage(text)
            .setCancelable(false).setNegativeButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();//  www . j a v  a2s  .co m
                    if (parent_exit) {
                        activity.finish();
                    }
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:Main.java

public static void displayError(String message, final Class<?> activity, final Context context) {
    // no deals found so display a popup and return to search options
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    // set title/*from ww w  .j a  v  a 2  s . com*/
    builder.setTitle("No Results");

    // set dialog message
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    Intent i = new Intent(context, activity);
                    ((Activity) (context)).finish();
                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
                    context.startActivity(i);
                }
            });
    // create alert dialog
    AlertDialog alertDialog = builder.create();

    // show it
    alertDialog.show();
}

From source file:air.com.snagfilms.utils.Utils.java

public static AlertDialog showConfirmationDialog(String title, Context mContext) {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            new ContextThemeWrapper(mContext, R.style.AlertDialogCustom));
    if (title != null) {
        alertDialogBuilder.setMessage(title);
    } else {/* w  ww  .j  av a2 s . c o  m*/
        alertDialogBuilder.setMessage("INFO:");
    }

    alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    return alertDialogBuilder.create();

}

From source file:com.evozi.droidsniff.helper.DialogHelper.java

public static void clearBlacklist(Activity context) {
    DialogHelper.context = context;/* w w  w .j  a va 2 s  . c o m*/
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(R.string.clear_blacklist).setCancelable(false)
            .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    DBHelper.clearBlacklist(DialogHelper.context);
                    AuthHelper.clearBlacklist();
                }
            }).setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.frostwire.android.gui.util.UIUtils.java

/**
 * @param context                         -  containing Context.
 * @param showInstallationCompleteSection - true if you want to display "Your installation is now complete. Thank You" section
 * @param dismissListener                 - what happens when the dialog is dismissed.
 * @param referrerContextSuffix           - string appended at the end of social pages click urls's ?ref=_android_ parameter.
 *///from   w w  w  . j  a  v a2 s  . c  o  m
public static void showSocialLinksDialog(final Context context, boolean showInstallationCompleteSection,
        DialogInterface.OnDismissListener dismissListener, String referrerContextSuffix) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View customView = View.inflate(context, R.layout.view_social_buttons, null);
    builder.setView(customView);
    builder.setPositiveButton(context.getString(android.R.string.ok), (dialog, which) -> dialog.dismiss());
    final AlertDialog socialLinksDialog = builder.create();
    socialLinksDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    socialLinksDialog.setOnDismissListener(dismissListener);
    ImageButton fbButton = customView.findViewById(R.id.view_social_buttons_facebook_button);
    ImageButton twitterButton = customView.findViewById(R.id.view_social_buttons_twitter_button);
    ImageButton redditButton = customView.findViewById(R.id.view_social_buttons_reddit_button);
    final String referrerParam = "?ref=android_"
            + ((referrerContextSuffix != null) ? referrerContextSuffix.trim() : "");
    fbButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_FACEBOOK_PAGE + referrerParam));
    twitterButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_TWITTER_PAGE + referrerParam));
    redditButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_REDDIT_PAGE + referrerParam));
    if (showInstallationCompleteSection) {
        LinearLayout installationCompleteLayout = customView
                .findViewById(R.id.view_social_buttons_installation_complete_layout);
        installationCompleteLayout.setVisibility(View.VISIBLE);
        ImageButton dismissCheckButton = customView.findViewById(R.id.view_social_buttons_dismiss_check);
        dismissCheckButton.setOnClickListener(v -> socialLinksDialog.dismiss());
    }
    socialLinksDialog.show();
}

From source file:Main.java

public static void showMessageDialogWithNewIntent(final Activity curentActivity, Context context,
        String message, final Class newActivity, final String extras) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {

                    Intent i = new Intent(curentActivity, newActivity);
                    if (extras != null) {
                        Log.i("LOGINSIGNUP", "=extras!=null in showMessageDialog");
                        i.putExtra("OAuthError", true);
                    }// w  ww.  ja va2  s .  co m
                    Log.i("LOGINSIGNUP", "==after if in showMessageDialog");

                    curentActivity.startActivity(i);
                    //                  curentActivity.finish();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

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

public static void showActionMenu(final AppCompatActivity activity,
        final CommentListingFragment commentListingFragment, final RedditRenderableComment comment,
        final RedditCommentView commentView, final RedditChangeDataManager changeDataManager,
        final boolean isArchived) {

    final RedditAccount user = RedditAccountManager.getInstance(activity).getDefaultAccount();

    final ArrayList<RCVMenuItem> menu = new ArrayList<>();

    if (!user.isAnonymous()) {

        if (!isArchived) {
            if (!changeDataManager.isUpvoted(comment)) {
                menu.add(new RCVMenuItem(activity, R.string.action_upvote, RedditCommentAction.UPVOTE));
            } else {
                menu.add(new RCVMenuItem(activity, R.string.action_upvote_remove, RedditCommentAction.UNVOTE));
            }/*from  www.  jav  a 2  s .  co m*/

            if (!changeDataManager.isDownvoted(comment)) {
                menu.add(new RCVMenuItem(activity, R.string.action_downvote, RedditCommentAction.DOWNVOTE));
            } else {
                menu.add(
                        new RCVMenuItem(activity, R.string.action_downvote_remove, RedditCommentAction.UNVOTE));
            }
        }

        if (changeDataManager.isSaved(comment)) {
            menu.add(new RCVMenuItem(activity, R.string.action_unsave, RedditCommentAction.UNSAVE));
        } else {
            menu.add(new RCVMenuItem(activity, R.string.action_save, RedditCommentAction.SAVE));
        }

        menu.add(new RCVMenuItem(activity, R.string.action_report, RedditCommentAction.REPORT));

        if (!isArchived)
            menu.add(new RCVMenuItem(activity, R.string.action_reply, RedditCommentAction.REPLY));

        if (user.username.equalsIgnoreCase(comment.getParsedComment().getRawComment().author)) {
            if (!isArchived)
                menu.add(new RCVMenuItem(activity, R.string.action_edit, RedditCommentAction.EDIT));
            menu.add(new RCVMenuItem(activity, R.string.action_delete, RedditCommentAction.DELETE));
        }
    }

    menu.add(new RCVMenuItem(activity, R.string.action_comment_context, RedditCommentAction.CONTEXT));
    menu.add(new RCVMenuItem(activity, R.string.action_comment_go_to, RedditCommentAction.GO_TO_COMMENT));

    menu.add(new RCVMenuItem(activity, R.string.action_comment_links, RedditCommentAction.COMMENT_LINKS));

    if (commentListingFragment != null) {
        menu.add(new RCVMenuItem(activity, R.string.action_collapse, RedditCommentAction.COLLAPSE));
    }

    menu.add(new RCVMenuItem(activity, R.string.action_share, RedditCommentAction.SHARE));
    menu.add(new RCVMenuItem(activity, R.string.action_copy_text, RedditCommentAction.COPY_TEXT));
    menu.add(new RCVMenuItem(activity, R.string.action_copy_link, RedditCommentAction.COPY_URL));
    menu.add(new RCVMenuItem(activity, R.string.action_user_profile, RedditCommentAction.USER_PROFILE));
    menu.add(new RCVMenuItem(activity, R.string.action_properties, RedditCommentAction.PROPERTIES));

    final String[] menuText = new String[menu.size()];

    for (int i = 0; i < menuText.length; i++) {
        menuText[i] = menu.get(i).title;
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    builder.setItems(menuText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            onActionMenuItemSelected(comment, commentView, activity, commentListingFragment,
                    menu.get(which).action, changeDataManager);
        }
    });

    final AlertDialog alert = builder.create();
    alert.setCanceledOnTouchOutside(true);
    alert.show();
}

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

public static AlertDialog createDeferDialog(final Activity act, int dateType, final boolean showNone,
        final InputDialogListener listener) {
    String[] keys = act.getResources().getStringArray(R.array.deferOptions);
    String today = "0d";
    String tomorrow = "1d";
    String oneWeek = "1w";
    String twoWeeks = "2w";
    String oneMonth = "1m";
    final String[] values = { "", today, tomorrow, oneWeek, twoWeeks, oneMonth, "pick" };
    if (!showNone) {
        keys = Arrays.copyOfRange(keys, 1, keys.length);
    }//from   www .ja v a 2 s . co m
    int titleId;
    if (dateType == Task.DUE_DATE) {
        titleId = R.string.defer_due;
    } else {
        titleId = R.string.defer_threshold;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(act);
    builder.setTitle(titleId);
    builder.setItems(keys, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            if (!showNone) {
                whichButton++;
            }
            String selected = values[whichButton];
            listener.onClick(selected);
        }
    });
    return builder.create();
}

From source file:com.wellsandwhistles.android.redditsp.common.DialogUtils.java

public static void showSearchDialog(Context context, int titleRes, final OnSearchListener listener) {
    final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
    final EditText editText = (EditText) LayoutInflater.from(context).inflate(R.layout.dialog_editbox, null);

    alertBuilder.setView(editText);/*  w  w w .  j  ava2 s.c o  m*/
    alertBuilder.setTitle(titleRes);

    alertBuilder.setPositiveButton(R.string.action_search, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String query = General.asciiLowercase(editText.getText().toString()).trim();
            if (StringUtils.isEmpty(query)) {
                listener.onSearch(null);
            } else {
                listener.onSearch(query);
            }
        }
    });

    alertBuilder.setNegativeButton(R.string.dialog_cancel, null);

    final AlertDialog alertDialog = alertBuilder.create();
    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    alertDialog.show();
}

From source file:Main.java

public static void createNonCancellableAcceptOrCancelDialog(Context context, String title, String message,
        String acceptButtonText, String cancelButtonText, final Runnable onAccept, final Runnable onCancel) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);//from  w w  w  . ja v  a  2  s  . c o m
    builder.setTitle(title);
    builder.setMessage(message);
    builder.setInverseBackgroundForced(true);
    builder.setPositiveButton(acceptButtonText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (onAccept != null)
                onAccept.run();
        }
    });

    builder.setNegativeButton(cancelButtonText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (onCancel != null)
                onCancel.run();
        }
    });
    AlertDialog alert = builder.create();
    alert.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
                return true; // Pretend we processed it
            }
            return false; // Any other keys are still processed as normal
        }
    });
    alert.show();
}