List of usage examples for android.app AlertDialog show
public void show()
From source file:Main.java
public static void displayAlert4SingleChoice(Context context, String title, boolean cancelable, String[] selectNames, final OnClickListener onClickListener) { AlertDialog accountDlg = new AlertDialog.Builder(context).setTitle(title).setCancelable(cancelable) .setSingleChoiceItems(selectNames, -1, new OnClickListener() { @Override//from w w w.jav a 2s .com public void onClick(DialogInterface dialog, int which) { if (null != onClickListener) { onClickListener.onClick(dialog, which); } dialog.dismiss(); } }).create(); accountDlg.show(); }
From source file:Main.java
public static void displayAlert4SingleChoice(Context context, String title, boolean cancelable, String[] selectNames, final DialogInterface.OnClickListener onClickListener) { AlertDialog accountDlg = new AlertDialog.Builder(context).setTitle(title).setCancelable(cancelable) .setSingleChoiceItems(selectNames, -1, new OnClickListener() { @Override//w w w. jav a 2s . c om public void onClick(DialogInterface dialog, int which) { if (null != onClickListener) { onClickListener.onClick(dialog, which); } dialog.dismiss(); } }).create(); accountDlg.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 . jav 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(); }
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)); }/* ww w.j av a2s . c o 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:Main.java
public static void displayAlert4SingleChoice2(final Context context, String title, boolean cancelable, String[] selectNames, final DialogInterface.OnClickListener onClickListener) { if (null == context || !(context instanceof Activity)) { return;// ww w. j a v a 2 s . co m } final Activity activity = (Activity) context; AlertDialog accountDlg = new AlertDialog.Builder(activity).setTitle(title).setCancelable(cancelable) .setItems(selectNames, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (null != onClickListener) { onClickListener.onClick(dialog, which); } if (!activity.isFinishing()) { dialog.dismiss(); } } }).create(); if (!activity.isFinishing()) { accountDlg.show(); } }
From source file:Main.java
public static void displayAlert4SingleChoice(final Context context, String title, boolean cancelable, String[] selectNames, final DialogInterface.OnClickListener onClickListener) { if (null == context || !(context instanceof Activity)) { return;/*w w w. ja v a 2s . com*/ } final Activity activity = (Activity) context; AlertDialog accountDlg = new AlertDialog.Builder(activity).setTitle(title).setCancelable(cancelable) .setSingleChoiceItems(selectNames, -1, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (null != onClickListener) { onClickListener.onClick(dialog, which); } if (!activity.isFinishing()) { dialog.dismiss(); } } }).create(); if (!activity.isFinishing()) { accountDlg.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 ww w . ja v a 2 s . c o 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.cranberrygame.cordova.plugin.ad.adbuddiz.Util.java
public static void alert(Activity activity, String message) { AlertDialog ad = new AlertDialog.Builder(activity).create(); ad.setCancelable(false); // This blocks the 'BACK' button ad.setMessage(message);//from w ww . java2s . c o m ad.setButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ad.show(); }
From source file:org.geek.utils.ApplicationUtils.java
/** * Display a continue / cancel dialog./*from www .j av a2 s.com*/ * @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.// ww w. j a v a2s .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(); }