Example usage for android.app AlertDialog setCanceledOnTouchOutside

List of usage examples for android.app AlertDialog setCanceledOnTouchOutside

Introduction

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

Prototype

public void setCanceledOnTouchOutside(boolean cancel) 

Source Link

Document

Sets whether this dialog is canceled when touched outside the window's bounds.

Usage

From source file:Main.java

/**
 * create dialog//ww w.j  a v  a  2s  . c  o m
 */

public static void callDialog(Context ctx, String msg, String title) {

    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setMessage(msg).setTitle(title).setPositiveButton(android.R.string.ok, null);
    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:Main.java

public static void showMessage(Context context, String title, String message, OnDismissListener listener) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

    // set title//from w w  w  . j  av  a 2 s .c om
    alertDialogBuilder.setTitle(title);

    // set dialog message
    alertDialogBuilder.setMessage(message).setCancelable(true);

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    alertDialog.setCanceledOnTouchOutside(true);
    if (listener != null)
        alertDialog.setOnDismissListener(listener);
    // show it
    alertDialog.show();
}

From source file:Main.java

public static void showAlert(Context context, String title, String text) {
    AlertDialog alertDialog = new Builder(context).create();
    alertDialog.setTitle(title);/*ww  w .ja  v  a  2 s . co  m*/
    alertDialog.setMessage(text);
    alertDialog.setCanceledOnTouchOutside(true);
    alertDialog.show();
}

From source file:com.landenlabs.allperfimages.ui.Ui.java

public static AlertDialog ShowMessage(Activity activity, String message) {
    AlertDialog dialog = new AlertDialog.Builder(activity).setMessage(message).setPositiveButton("More", null)
            .setNegativeButton("Close", null).show();
    dialog.setCanceledOnTouchOutside(true);
    TextView textView = (TextView) dialog.findViewById(android.R.id.message);
    textView.setSingleLine(false);//from w w  w.  j a  va2 s .  com
    textView.setTextSize(20);
    return dialog;
}

From source file:org.rm3l.ddwrt.utils.Utils.java

@NotNull
public static AlertDialog buildAlertDialog(@NotNull final Context context, @Nullable final String title,
        @NotNull final String msg, final boolean cancelable, final boolean cancelableOnTouchOutside) {
    @NotNull
    final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    if (!Strings.isNullOrEmpty(title)) {
        alertDialog.setTitle(title);//from   ww  w  .  ja  va  2s  .  co m
    }
    alertDialog.setMessage(msg);
    alertDialog.setCancelable(cancelable);
    alertDialog.setCanceledOnTouchOutside(cancelableOnTouchOutside);

    return alertDialog;
}

From source file:br.unicamp.busfinder.ServerOperations.java

public static void nextBuses(final String title, final Context c) {

    int stopid = Integer.parseInt(title.split("_")[0]);

    String req = BusFinderActivity.SERVER + "getNextBus?stopid=";
    JSONArray jar = getJSON(req + stopid);
    String display = "";
    try {//w  ww . j a  v  a  2  s . co  m

        for (int i = 0; i < jar.length(); i++) {
            JSONObject jos = jar.getJSONObject(i);
            String circular = jos.getString("circular");
            String time = jos.getString("time");

            display += "--" + circular + "------" + time + "\n";

        }

        final String display_ = display;

        AlertDialog dialog = new AlertDialog.Builder(c).create();

        dialog.setTitle(title);
        dialog.setMessage(display_);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        return;

    } catch (JSONException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Toast.makeText(c, "Error or no Connection ..", Toast.LENGTH_SHORT).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 .j av  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: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  .  j a  va 2s . c  om
        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:nya.miku.wishmaster.http.cloudflare.CloudflareUIHandler.java

/**
 *  ?-?  Cloudflare./*from   w w w.ja  v a2  s .  c  o m*/
 *    
 * @param e ? {@link CloudflareException}
 * @param chan  
 * @param activity ?,    ?  ( ?  ? ),
 *   ?   ? WebView ? Anti DDOS  ? javascript.
 * ???  ?  UI  ({@link Activity#runOnUiThread(Runnable)})
 * @param cfTask ?? 
 * @param callback ? {@link Callback}
 */
static void handleCloudflare(final CloudflareException e, final HttpChanModule chan, final Activity activity,
        final CancellableTask cfTask, final InteractiveException.Callback callback) {
    if (cfTask.isCancelled())
        return;

    if (!e.isRecaptcha()) { // ? anti DDOS 
        if (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) {
            //?  ?   ??  ,   ?  ? ?
            // ?, ?      ChanModule,    
            //  ?  ?  () cloudflare  ? ?
            //  ?  ? ? ?   ? CloudflareChecker
            while (!CloudflareChecker.getInstance().isAvaibleAntiDDOS())
                Thread.yield();
            if (!cfTask.isCancelled())
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                });
            return;
        }

        Cookie cfCookie = CloudflareChecker.getInstance().checkAntiDDOS(e, chan.getHttpClient(), cfTask,
                activity);
        if (cfCookie != null) {
            chan.saveCookie(cfCookie);
            if (!cfTask.isCancelled()) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                });
            }
        } else if (!cfTask.isCancelled()) {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callback.onError(activity.getString(R.string.error_cloudflare_antiddos));
                }
            });
        }
    } else { //  ? 
        final Recaptcha recaptcha;
        try {
            recaptcha = CloudflareChecker.getInstance().getRecaptcha(e, chan.getHttpClient(), cfTask);
        } catch (RecaptchaException recaptchaException) {
            if (!cfTask.isCancelled())
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onError(activity.getString(R.string.error_cloudflare_get_captcha));
                    }
                });
            return;
        }

        if (!cfTask.isCancelled())
            activity.runOnUiThread(new Runnable() {
                @SuppressLint("InflateParams")
                @Override
                public void run() {
                    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                            ? new ContextThemeWrapper(activity, R.style.Neutron_Medium)
                            : activity;
                    View view = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_cloudflare_captcha,
                            null);
                    ImageView captchaView = (ImageView) view.findViewById(R.id.dialog_captcha_view);
                    final EditText captchaField = (EditText) view.findViewById(R.id.dialog_captcha_field);
                    captchaView.setImageBitmap(recaptcha.bitmap);

                    DialogInterface.OnClickListener process = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (cfTask.isCancelled())
                                return;
                            PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() {
                                @Override
                                public void run() {
                                    String answer = captchaField.getText().toString();
                                    Cookie cfCookie = CloudflareChecker.getInstance().checkRecaptcha(e,
                                            (ExtendedHttpClient) chan.getHttpClient(), cfTask,
                                            recaptcha.challenge, answer);
                                    if (cfCookie != null) {
                                        chan.saveCookie(cfCookie);
                                        if (!cfTask.isCancelled()) {
                                            activity.runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    callback.onSuccess();
                                                }
                                            });
                                        }
                                    } else {
                                        //   (?,  ,    )
                                        handleCloudflare(e, chan, activity, cfTask, callback);
                                    }
                                }
                            }).start();
                        }
                    };

                    DialogInterface.OnCancelListener onCancel = new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            callback.onError(activity.getString(R.string.error_cloudflare_cancelled));
                        }
                    };

                    if (cfTask.isCancelled())
                        return;

                    final AlertDialog recaptchaDialog = new AlertDialog.Builder(dialogContext).setView(view)
                            .setPositiveButton(R.string.dialog_cloudflare_captcha_check, process)
                            .setOnCancelListener(onCancel).create();
                    recaptchaDialog.getWindow()
                            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    recaptchaDialog.setCanceledOnTouchOutside(false);
                    recaptchaDialog.show();

                    captchaView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            recaptchaDialog.dismiss();
                            if (cfTask.isCancelled())
                                return;
                            PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() {
                                @Override
                                public void run() {
                                    handleCloudflare(e, chan, activity, cfTask, callback);
                                }
                            }).start();
                        }
                    });
                }
            });
    }
}

From source file:com.onesignal.GenerateNotification.java

private static int showNotificationAsAlert(final JSONObject gcmJson, final Activity activity) {
    final int aNotificationId = new Random().nextInt();

    activity.runOnUiThread(new Runnable() {
        @Override//from w  ww  .  j  a v  a  2 s. c om
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle(getTitle(gcmJson));
            try {
                builder.setMessage(gcmJson.getString("alert"));
            } catch (Throwable t) {
            }

            List<String> buttonsLabels = new ArrayList<String>();
            List<String> buttonIds = new ArrayList<String>();

            addAlertButtons(gcmJson, buttonsLabels, buttonIds);

            final List<String> finalButtonIds = buttonIds;

            Intent buttonIntent = getNewBaseIntent(aNotificationId);
            buttonIntent.putExtra("action_button", true);
            buttonIntent.putExtra("from_alert", true);
            buttonIntent.putExtra("onesignal_data", gcmJson.toString());
            try {
                if (gcmJson.has("grp"))
                    buttonIntent.putExtra("grp", gcmJson.getString("grp"));
            } catch (JSONException e) {
            }

            final Intent finalButtonIntent = buttonIntent;

            DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int index = which + 3;

                    if (finalButtonIds.size() > 1) {
                        try {
                            JSONObject customJson = new JSONObject(gcmJson.getString("custom"));
                            JSONObject additionalDataJSON = customJson.getJSONObject("a");
                            additionalDataJSON.put("actionSelected", finalButtonIds.get(index));

                            JSONObject newJsonData = new JSONObject(gcmJson.toString());
                            newJsonData.put("custom", customJson.toString());

                            finalButtonIntent.putExtra("onesignal_data", newJsonData.toString());

                            NotificationOpenedProcessor.processIntent(activity, finalButtonIntent);
                        } catch (Throwable t) {
                        }
                    } else // No action buttons, close button simply pressed.
                        NotificationOpenedProcessor.processIntent(activity, finalButtonIntent);
                }
            };

            // Back button pressed
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    NotificationOpenedProcessor.processIntent(activity, finalButtonIntent);
                }
            });

            for (int i = 0; i < buttonsLabels.size(); i++) {
                if (i == 0)
                    builder.setNeutralButton(buttonsLabels.get(i), buttonListener);
                else if (i == 1)
                    builder.setNegativeButton(buttonsLabels.get(i), buttonListener);
                else if (i == 2)
                    builder.setPositiveButton(buttonsLabels.get(i), buttonListener);
            }

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

    return aNotificationId;
}