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:es.uniovi.imovil.fcrtrainer.HexadecimalExerciseFragment.java

/**
 * Shows a dialog with the game stats when the game is over
 * /*from  w w  w . j a  va2 s  . c om*/
 * @param remainingTime
 */
public void showEndGameDialog(int remainingTime) {
    AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
    abuilder.setTitle(getString(R.string.game_over));

    if (remainingTime > 0)
        abuilder.setMessage(String.format(getString(R.string.gameisoverexp), remainingTime, pointsCounter));
    else
        abuilder.setMessage(String.format(getString(R.string.lost_time_over), pointsCounter));

    abuilder.create().show();
}

From source file:edu.cwru.apo.Directory.java

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnCall:
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + lastPhone));
        startActivity(intent);/*w w w . jav a 2s.c om*/
        break;

    case R.id.btnText:
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", lastPhone, null)));
        break;

    default:
        String text = ((TextView) v).getText().toString();
        int start = text.lastIndexOf('[');
        int end = text.lastIndexOf(']');
        String caseID = text.substring(start + 1, end);
        Cursor results = database.query("phoneDB", new String[] { "first", "last", "_id", "phone" }, "_id = ?",
                new String[] { caseID }, null, null, null);
        if (results.getCount() != 1) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Error Loading Phone Number").setCancelable(false).setNeutralButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            results.moveToFirst();

            phoneDialog = new Dialog(this);
            phoneDialog.setContentView(R.layout.phone_dialog);
            phoneDialog.setTitle(results.getString(0) + " " + results.getString(1));

            TextView phoneText = (TextView) phoneDialog.findViewById((R.id.phoneText));
            String phoneNumber = removeNonDigits(results.getString(3));
            if (phoneNumber == null || phoneNumber.trim().equals("") || phoneNumber.trim().equals("null")) {
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setEnabled(false);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setEnabled(false);
                phoneNumber = "not available";
            } else {
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setEnabled(true);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setEnabled(true);
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setOnClickListener(this);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setOnClickListener(this);
            }
            lastPhone = phoneNumber;
            phoneText.setText("Phone Number: " + lastPhone);
            phoneDialog.show();
        }
        break;
    }
}

From source file:it.sasabz.android.sasabus.InfoActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {

        @Override/*from   w w  w . j  a va  2s. c om*/
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    Information information = (Information) list.get(position);
    builder.setTitle(Html.fromHtml(information.getTitel()));
    builder.setMessage(Html.fromHtml("<pre>" + information.getNachricht() + "</pre>"));
    builder.create().show();
}

From source file:it.sasabz.android.sasabus.InfoActivity.java

/**
 * Called when the activity is about to start interacting with the user.
 *///from   w  w  w . j  a  v a2  s . c o  m
@Override
protected void onResume() {
    super.onResume();
    if (haveNetworkConnection())
        fillData();
    else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setMessage(R.string.no_network_connection);
        builder.setTitle(R.string.error_title);
        builder.setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                dialog.dismiss();
            }
        });
        builder.create().show();
    }
}

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

/**
 * Shows a dialog that informs the user of the result of a pairing action,
 * and saves the newly paired outbound device if the operation was
 * successful./* w w w. j  a v a 2s.  c  o m*/
 * 
 * <p>
 * Once the user taps on the OK button,
 * {@link Activity#startActivity(Intent)} is called to get back to the
 * {@link MainActivity}.
 * 
 * @param device
 *            the outbound device to be paired
 * @param activity
 *            the caller activity
 */
public static void onPairingOutbound(final PairedDevice device, final FragmentActivity activity) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            try {
                builder.setMessage(getString(R.string.failed_pairing));
                if (device != null) {
                    PairOutboundActivity.savePairing(device, activity);
                    builder.setMessage(getResources().getString(R.string.successful_pairing, device.type));
                }
            } catch (IOException e) {
                // TODO let user know
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // back to main screen
                    startActivity(new Intent(activity, MainActivity.class));
                }
            });
            return builder.create();
        }
    }.show(activity.getSupportFragmentManager(), "code");
}

From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java

public static void showActionMenu(final AppCompatActivity activity, final RedditPreparedPost post) {

    final EnumSet<Action> itemPref = PrefsUtility.pref_menus_post_context_items(activity,
            PreferenceManager.getDefaultSharedPreferences(activity));

    if (itemPref.isEmpty())
        return;//  w w w .  j a  v a  2 s  .com

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

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

    if (!RedditAccountManager.getInstance(activity).getDefaultAccount().isAnonymous()) {

        if (itemPref.contains(Action.UPVOTE)) {
            if (!post.isUpvoted()) {
                menu.add(new RPVMenuItem(activity, R.string.action_upvote, Action.UPVOTE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_upvote_remove, Action.UNVOTE));
            }
        }

        if (itemPref.contains(Action.DOWNVOTE)) {
            if (!post.isDownvoted()) {
                menu.add(new RPVMenuItem(activity, R.string.action_downvote, Action.DOWNVOTE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_downvote_remove, Action.UNVOTE));
            }
        }

        if (itemPref.contains(Action.SAVE)) {
            if (!post.isSaved()) {
                menu.add(new RPVMenuItem(activity, R.string.action_save, Action.SAVE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_unsave, Action.UNSAVE));
            }
        }

        if (itemPref.contains(Action.HIDE)) {
            if (!post.isHidden()) {
                menu.add(new RPVMenuItem(activity, R.string.action_hide, Action.HIDE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_unhide, Action.UNHIDE));
            }
        }

        if (itemPref.contains(Action.EDIT) && post.isSelf()
                && user.username.equalsIgnoreCase(post.src.getAuthor())) {
            menu.add(new RPVMenuItem(activity, R.string.action_edit, Action.EDIT));
        }

        if (itemPref.contains(Action.DELETE) && user.username.equalsIgnoreCase(post.src.getAuthor())) {
            menu.add(new RPVMenuItem(activity, R.string.action_delete, Action.DELETE));
        }

        if (itemPref.contains(Action.REPORT))
            menu.add(new RPVMenuItem(activity, R.string.action_report, Action.REPORT));
    }

    if (itemPref.contains(Action.EXTERNAL))
        menu.add(new RPVMenuItem(activity, R.string.action_external, Action.EXTERNAL));
    if (itemPref.contains(Action.SELFTEXT_LINKS) && post.src.getRawSelfText() != null
            && post.src.getRawSelfText().length() > 1)
        menu.add(new RPVMenuItem(activity, R.string.action_selftext_links, Action.SELFTEXT_LINKS));
    if (itemPref.contains(Action.SAVE_IMAGE) && post.mIsProbablyAnImage)
        menu.add(new RPVMenuItem(activity, R.string.action_save_image, Action.SAVE_IMAGE));
    if (itemPref.contains(Action.GOTO_SUBREDDIT))
        menu.add(new RPVMenuItem(activity, R.string.action_gotosubreddit, Action.GOTO_SUBREDDIT));
    if (post.showSubreddit) {
        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());

            if (itemPref.contains(Action.BLOCK) && post.showSubreddit) {
                final List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity));

                if (blockedSubreddits.contains(subredditCanonicalName)) {
                    menu.add(new RPVMenuItem(activity, R.string.action_unblock_subreddit, Action.UNBLOCK));
                } else {
                    menu.add(new RPVMenuItem(activity, R.string.action_block_subreddit, Action.BLOCK));
                }
            }

            if (itemPref.contains(Action.PIN) && post.showSubreddit) {
                List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity));
                if (pinnedSubreddits.contains(subredditCanonicalName)) {
                    menu.add(new RPVMenuItem(activity, R.string.action_unpin_subreddit, Action.UNPIN));
                } else {
                    menu.add(new RPVMenuItem(activity, R.string.action_pin_subreddit, Action.PIN));
                }
            }

            if (!RedditAccountManager.getInstance(activity).getDefaultAccount().isAnonymous()) {
                if (itemPref.contains(Action.SUBSCRIBE)) {
                    if (RedditSubredditSubscriptionManager
                            .getSingleton(activity,
                                    RedditAccountManager.getInstance(activity).getDefaultAccount())
                            .getSubscriptionState(
                                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) {
                        menu.add(new RPVMenuItem(activity, R.string.action_unsubscribe_subreddit,
                                Action.UNSUBSCRIBE));
                    } else {
                        menu.add(new RPVMenuItem(activity, R.string.action_subscribe_subreddit,
                                Action.SUBSCRIBE));
                    }
                }
            }

        } catch (RedditSubreddit.InvalidSubredditNameException ex) {
            throw new RuntimeException(ex);
        }
    }

    if (itemPref.contains(Action.SHARE))
        menu.add(new RPVMenuItem(activity, R.string.action_share, Action.SHARE));
    if (itemPref.contains(Action.SHARE_COMMENTS))
        menu.add(new RPVMenuItem(activity, R.string.action_share_comments, Action.SHARE_COMMENTS));
    if (itemPref.contains(Action.SHARE_IMAGE) && post.mIsProbablyAnImage)
        menu.add(new RPVMenuItem(activity, R.string.action_share_image, Action.SHARE_IMAGE));
    if (itemPref.contains(Action.COPY))
        menu.add(new RPVMenuItem(activity, R.string.action_copy, Action.COPY));
    if (itemPref.contains(Action.USER_PROFILE))
        menu.add(new RPVMenuItem(activity, R.string.action_user_profile, Action.USER_PROFILE));
    if (itemPref.contains(Action.PROPERTIES))
        menu.add(new RPVMenuItem(activity, R.string.action_properties, Action.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(post, activity, menu.get(which).action);
        }
    });

    //builder.setNeutralButton(R.string.dialog_cancel, null);

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

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

/**
 * Shows the about screen./*from  w  ww.  j a  v a  2 s.  c om*/
 * 
 * @param activity
 *            the caller activity
 */
public static void showAbout(final FragmentActivity activity) {
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            View layout = View.inflate(getContext(), R.layout.about, null);
            String version = "alpha";
            try {
                version = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
            ((TextView) layout.findViewById(R.id.title))
                    .setText(activity.getResources().getString(R.string.title_about_dialog, version));
            ((TextView) layout.findViewById(R.id.build_date)).setText(
                    activity.getResources().getString(R.string.build_date_about, getBuildDate(activity)));
            // make links clickable
            ((TextView) layout.findViewById(R.id.description))
                    .setMovementMethod(LinkMovementMethod.getInstance());
            builder.setView(layout);
            return builder.create();
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "about");
}

From source file:com.sakisds.icymonitor.activities.AddNotificationActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button_cancel:
        finish();//  ww  w .  j a  v a 2s  .c  om
        break;
    case R.id.button_add:
        addNotification();
        break;
    case R.id.button_notification_help:
        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);

        dlgAlert.setMessage(getString(R.string.notif_ring_once_help));
        dlgAlert.setPositiveButton("OK", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.LockActivity.java

public void notififyGuestUsedKey(final String guestUser, final String guestService) {
    AlertDialog.Builder builder = new AlertDialog.Builder(LockActivity.this);
    builder.setInverseBackgroundForced(true);
    builder.setMessage("Remote key used by " + guestUser + "!").setCancelable(true).setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();//w w  w . j a  va 2  s  . c om
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:io.github.protino.codewatch.ui.LeaderboardFragment.java

@SuppressLint("InflateParams")
@Nullable/*from   w  w  w  .j  a  v a 2 s . c  o  m*/
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_leaderboard, container, false);
    unbinder = ButterKnife.bind(this, rootView);

    context = getActivity();
    filterState = new FilterState();
    userId = CacheUtils.getWakatimeUserId(context);

    leadersAdapter = new LeadersAdapter(context, new ArrayList<>());
    leadersAdapter.setOnItemSelectedListener(this);

    //recyclerView setup
    recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    recyclerView.setAdapter(leadersAdapter);

    //Dialog related
    dialogView = inflater.inflate(R.layout.dialog_leaders_filter, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(dialogView).setPositiveButton(R.string.ok, null).setNegativeButton(R.string.cancel, null);
    dialog = builder.create();
    dialog.setOnShowListener(this);

    getLoaderManager().initLoader(LOADER_ID, null, this);

    swipeRefreshLayout.setOnRefreshListener(this);
    return rootView;
}