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:csic.ceab.movelab.beepath.MainActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = null;
    switch (id) {
    case EXIT_DIALOG:
        builder = new AlertDialog.Builder(this);
        builder.setMessage("Do you want to exit?").setCancelable(true).setPositiveButton("Yes",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        stop();//from w  w w . j  a va  2  s  .co m
                    }
                });
        alert = builder.create();
        break;
    }
    return alert;
}

From source file:com.linkbubble.util.YouTubeEmbedHelper.java

private AlertDialog getMultipleEmbedsDialog() {
    if (embedInfoMatchesIds()) {
        return getEmbedResultsDialog();
    } else {/* w  ww.  j  a v a2 s  .  co  m*/
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.view_loading, null);

        TextView textView = (TextView) view.findViewById(R.id.loading_text);
        textView.setText(R.string.loading_youtube_embed_info);

        builder.setView(view);
        builder.setIcon(0);

        AlertDialog alertDialog = builder.create();
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        if (mCurrentDownloadTask != null) {
            synchronized (mCurrentDownloadTask) {
                if (mCurrentDownloadTask != null) {
                    mCurrentDownloadTask.cancel(true);
                }
                mCurrentDownloadTask = new DownloadYouTubeEmbedInfoTask(true, alertDialog);
                mCurrentDownloadTask.execute(null, null, null);
            }
        } else {
            mCurrentDownloadTask = new DownloadYouTubeEmbedInfoTask(true, alertDialog);
            mCurrentDownloadTask.execute(null, null, null);
        }

        return alertDialog;
    }
}

From source file:com.lepin.activity.MyLoveCarActivity.java

/**
 * //from w w  w . j  ava  2  s  . c o m
 */
protected void choiceDriveYear() {
    AlertDialog.Builder builder = new AlertDialog.Builder(MyLoveCarActivity.this);
    builder.setTitle(R.string.my_car_choice_dryear).setItems(drYearsArry,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    mlDrivYear.setText(drYearsArry[which]);
                }
            });
    builder.create().show();
}

From source file:com.lepin.activity.MyLoveCarActivity.java

/**
 * ?/*from   w  ww .jav  a 2  s  .  co  m*/
 */
protected void choicePeoPleNumber() {
    AlertDialog.Builder builder = new AlertDialog.Builder(MyLoveCarActivity.this);
    builder.setTitle(R.string.pick_details_total_people).setItems(pepNumArry,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    mlPeoNum.setText(pepNumArry[which]);
                }
            });
    builder.create().show();
}

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
 * @see android.app.Activity#onCreateDialog(int)
 *//*from   ww  w . jav a 2s.c o m*/
@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
    case JSON_ERROR_DIALOG:
        builder.setTitle(R.string.cache_corrupt);
        builder.setMessage(R.string.cache_corrupt_message);
        builder.setNeutralButton(R.string.ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        return builder.create();
    case NO_SERVER_DIALOG:
        builder.setTitle(R.string.no_servers);
        builder.setMessage(R.string.no_server_message);
        builder.setPositiveButton(R.string.yes, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent addServer = new Intent(MCServerTrackerActivity.this, AddServerActivity.class);
                startActivityForResult(addServer, AddServerActivity.ADD_SERVER_ACTIVITY_ID);
            }
        });
        builder.setNegativeButton(R.string.no, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        return builder.create();
    case IO_ERROR_DIALOG:
        break;
    }
    return super.onCreateDialog(id);
}

From source file:com.jonbanjo.cupsprint.CertificateActivity.java

private void displayCert(final String alias) {

    X509Certificate cert;/*from  ww  w  . j ava 2 s  .c  o m*/
    try {
        cert = (X509Certificate) trustStore.getCertificate(alias);
    } catch (KeyStoreException e) {
        showToast(e.toString());
        return;
    }
    String certString = cert.toString();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Certificate").setMessage(certString)
            .setPositiveButton("Remove", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    removeCert(alias);
                }
            }).setNegativeButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog dialog = builder.create();
    dialog.show();

}

From source file:edu.stanford.mobisocial.dungbeetle.ui.wizard.ChangePictureActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;/* w  ww  .ja va2 s .com*/
    }

    findViewById(R.id.btn_broadcast).setVisibility(View.GONE);
    mContactId = getIntent().getLongExtra("contact_id", -1);
    if (mContactId == -1) {
        Uri data = getIntent().getData();
        if (data != null) {
            try {
                mContactId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
            }
        }
    }

    Bundle args = new Bundle();
    args.putLong("contact_id", mContactId);
    Fragment profileFragment = new ViewProfileFragment();
    profileFragment.setArguments(args);

    doTitleBar(this, "My Profile");
    mLabels.add("View");
    mLabels.add("Edit");
    mFragments.add(profileFragment);
    mFragments.add(new EditProfileFragment());

    Uri privateUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/private");
    mLabels.add("Notes");
    Fragment feedView = new FeedViewFragment();
    args = new Bundle(args);
    args.putParcelable(FeedViewFragment.ARG_FEED_URI, privateUri);
    feedView.setArguments(args);
    //mFragments.add(feedView);

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(this);

    ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame);
    int i = 0;
    for (String s : mLabels) {
        Button button = new Button(this);
        button.setText(s);
        button.setTextSize(18f);

        button.setLayoutParams(CommonLayouts.FULL_HEIGHT);
        button.setTag(i++);
        button.setOnClickListener(mViewSelected);

        group.addView(button);
        mButtons.add(button);
    }

    // Listen for future changes
    Uri feedUri;
    if (mContactId == Contact.MY_ID) {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    } else {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    }
    mProfileContentObserver = new ProfileContentObserver(mHandler);
    getContentResolver().registerContentObserver(feedUri, true, mProfileContentObserver);

    onPageSelected(0);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Click on the avatar to take a profile picture of yourself.").setCancelable(false)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.schtief.partybolle.event.EventManager.java

public void getEvents(String type) {
    GeoPoint center = mapView.getMapCenter();

    //check for Events in Berlin
    if (center.getLatitudeE6() < 52000000 || center.getLatitudeE6() > 53000000
            || center.getLongitudeE6() < 13000000 || center.getLongitudeE6() > 14000000) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this.app);
        builder.setMessage("Alder ick komm aus Berlin, keene Ahnung wat in deinem Kaff los ist!")
                .setCancelable(false)/*w w  w . j  av a  2s. co m*/
                .setPositiveButton("Ich helf dir mit Events fr hier", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        //TODO twidroid ansprechen
                    }
                }).setNegativeButton("Ok OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    int lat1 = center.getLatitudeE6() - mapView.getLatitudeSpan() / 2;
    int lat2 = center.getLatitudeE6() + mapView.getLatitudeSpan() / 2;

    int lon1 = center.getLongitudeE6() - mapView.getLongitudeSpan() / 2;
    int lon2 = center.getLongitudeE6() + mapView.getLongitudeSpan() / 2;

    new GetEventsThread(lat1, lon1, lat2, lon2, type).start();
}

From source file:dtu.ds.warnme.app.dialog.WarningDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Event event = (Event) getArguments().get(MainActivity.KEY_EVENT);

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    dialogBuilder.setTitle(R.string.warning);
    dialogBuilder.setMessage(getMessage(event));
    dialogBuilder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

        @Override/*  w ww. j  a  va2  s . c  o m*/
        public void onClick(DialogInterface dialog, int which) {
            // Nothing to do here...
        }
    });
    dialogBuilder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Nothing to do here...

        }
    });

    dialog = dialogBuilder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);

            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    RestClientHolder.getRestClient().upVoteEvent(dialog.getContext(), event,
                            new AsyncHttpResponseHandler() {

                                @Override
                                public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
                                        Throwable error) {
                                    Log.i(TAG, "Failed to upvote event " + event.getId() + " cause: " + error);
                                }

                                @Override
                                public void onFinish() {
                                    dialog.dismiss();
                                }

                                @Override
                                public void onStart() {
                                    positiveButton.setEnabled(false);
                                    negativeButton.setEnabled(false);
                                }

                                @Override
                                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                                    Log.i(TAG, "Event " + event.getId() + " upvoted with success");
                                }

                            });
                }
            });

            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    RestClientHolder.getRestClient().downVoteEvent(dialog.getContext(), event,
                            new AsyncHttpResponseHandler() {

                                @Override
                                public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
                                        Throwable error) {
                                    Log.i(TAG,
                                            "Failed to downvote event " + event.getId() + " cause: " + error);
                                }

                                @Override
                                public void onFinish() {
                                    dialog.dismiss();
                                }

                                @Override
                                public void onStart() {
                                    positiveButton.setEnabled(false);
                                    negativeButton.setEnabled(false);
                                }

                                @Override
                                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                                    Log.i(TAG, "Event " + event.getId() + " downvoted with success");
                                }

                            });
                }
            });

        }
    });

    return dialog;
}

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

public static void onActionMenuItemSelected(final RedditPreparedPost post, final AppCompatActivity activity,
        final Action action) {

    switch (action) {

    case UPVOTE://  ww  w  .  j  a va2  s  .  c  o m
        post.action(activity, RedditAPI.ACTION_UPVOTE);
        break;

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

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

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

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

    case HIDE:
        post.action(activity, RedditAPI.ACTION_HIDE);
        break;

    case UNHIDE:
        post.action(activity, RedditAPI.ACTION_UNHIDE);
        break;
    case EDIT:
        final Intent editIntent = new Intent(activity, CommentEditActivity.class);
        editIntent.putExtra("commentIdAndType", post.src.getIdAndType());
        editIntent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText()));
        editIntent.putExtra("isSelfPost", true);
        activity.startActivity(editIntent);
        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) {
                        post.action(activity, RedditAPI.ACTION_DELETE);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        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) {
                        post.action(activity, RedditAPI.ACTION_REPORT);
                        // TODO update the view to show the result
                        // TODO don't forget, this also hides
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case EXTERNAL: {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl()
                : post.src.getUrl();
        intent.setData(Uri.parse(url));
        activity.startActivity(intent);
        break;
    }

    case SELFTEXT_LINKS: {

        final HashSet<String> linksInComment = LinkHandler
                .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText()));

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

        } 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, post.src.getSrc());
                    dialog.dismiss();
                }
            });

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

        break;
    }

    case SAVE_IMAGE: {

        ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                new SaveImageCallback(activity, post.src.getUrl()));
        break;
    }

    case SHARE: {

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, post.src.getTitle());
        mailer.putExtra(Intent.EXTRA_TEXT, post.src.getUrl());
        activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share)));
        break;
    }

    case SHARE_COMMENTS: {

        final boolean shareAsPermalink = PrefsUtility.pref_behaviour_share_permalink(activity,
                PreferenceManager.getDefaultSharedPreferences(activity));

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.src.getTitle());
        if (shareAsPermalink) {
            mailer.putExtra(Intent.EXTRA_TEXT,
                    Constants.Reddit.getNonAPIUri(post.src.getPermalink()).toString());
        } else {
            mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit
                    .getNonAPIUri(Constants.Reddit.PATH_COMMENTS + post.src.getIdAlone()).toString());
        }
        activity.startActivity(
                Intent.createChooser(mailer, activity.getString(R.string.action_share_comments)));
        break;
    }

    case SHARE_IMAGE: {

        ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                new ShareImageCallback(activity, post.src.getUrl()));

        break;
    }

    case COPY: {

        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        manager.setText(post.src.getUrl());
        break;
    }

    case GOTO_SUBREDDIT: {

        try {
            final Intent intent = new Intent(activity, PostListingActivity.class);
            intent.setData(SubredditPostListURL.getSubreddit(post.src.getSubreddit()).generateJsonUri());
            activity.startActivityForResult(intent, 1);

        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show();
        }

        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.getAuthor()).toString());
        break;

    case PROPERTIES:
        PostPropertiesDialog.newInstance(post.src.getSrc()).show(activity.getSupportFragmentManager(), null);
        break;

    case COMMENTS:
        ((PostSelectionListener) activity).onPostCommentsSelected(post);

        new Thread() {
            @Override
            public void run() {
                post.markAsRead(activity);
            }
        }.start();

        break;

    case LINK:
        ((PostSelectionListener) activity).onPostSelected(post);
        break;

    case COMMENTS_SWITCH:
        if (!(activity instanceof MainActivity))
            activity.finish();
        ((PostSelectionListener) activity).onPostCommentsSelected(post);
        break;

    case LINK_SWITCH:
        if (!(activity instanceof MainActivity))
            activity.finish();
        ((PostSelectionListener) activity).onPostSelected(post);
        break;

    case ACTION_MENU:
        showActionMenu(activity, post);
        break;

    case REPLY:
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, post.src.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, post.src.getUnescapedSelfText());
        activity.startActivity(intent);
        break;

    case BACK:
        activity.onBackPressed();
        break;

    case PIN:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (!pinnedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_pinned_subreddits_add(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_pinned, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }

        break;

    case UNPIN:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (pinnedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_pinned_subreddits_remove(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case BLOCK:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (!blockedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_blocked_subreddits_add(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case UNBLOCK:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (blockedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_blocked_subreddits_remove(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case SUBSCRIBE:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager
                    .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount());

            if (subMan.getSubscriptionState(
                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) {
                subMan.subscribe(subredditCanonicalName, activity);
                Toast.makeText(activity, R.string.options_subscribing, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case UNSUBSCRIBE:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager
                    .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount());
            if (subMan.getSubscriptionState(
                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) {
                subMan.unsubscribe(subredditCanonicalName, activity);
                Toast.makeText(activity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;
    }
}