List of usage examples for twitter4j Relationship isSourceBlockingTarget
boolean isSourceBlockingTarget();
From source file:MainActivity.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed try {/* w w w .ja v a 2s. c o m*/ Relationship r = twitter.showFriendship(uu1.getText(), uu2.getText()); String s = r.getSourceUserScreenName() + " is "; if (r.isSourceFollowingTarget()) { s = s + " following " + r.getTargetUserScreenName(); if (r.isSourceFollowedByTarget()) { s = s + " aslo " + r.getSourceUserScreenName() + " is followed by " + r.getTargetUserScreenName(); } else { s = s + " but " + r.getSourceUserScreenName() + " is not followed by " + r.getTargetUserScreenName(); } } else { s = s + " not following " + r.getTargetUserScreenName(); if (r.isSourceFollowedByTarget()) { s = s + " interestingly " + r.getSourceUserScreenName() + " is followed by " + r.getTargetUserScreenName(); } else { s = s + " neither " + r.getSourceUserScreenName() + " is followed by " + r.getTargetUserScreenName(); } } if (r.isSourceNotificationsEnabled()) { s = s + ", " + r.getSourceUserScreenName() + " has enabled notification for " + r.getTargetUserScreenName(); } else { s = s + ", " + r.getSourceUserScreenName() + " has no intention of enabling notification for " + r.getTargetUserScreenName(); } if (r.isSourceBlockingTarget()) { s = s + " its strange but " + r.getSourceUserScreenName() + " is blocking " + r.getTargetUserScreenName(); } else { s = s + " needless to say " + r.getSourceUserScreenName() + " is not blocking " + r.getTargetUserScreenName(); } u1.setText(s); // TODO add your handling code here: } catch (TwitterException ex) { Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.freshdigitable.udonroad.UserInfoView.java
License:Apache License
public void bindRelationship(Relationship relationship) { if (relationship.isSourceFollowingTarget()) { bindFollowingStatus(R.string.user_following, R.color.twitter_primary); } else if (relationship.isSourceBlockingTarget()) { bindFollowingStatus(R.string.user_blocking, R.color.twitter_muted); } else {/* w w w. ja v a 2s . co m*/ followingStatus.setVisibility(GONE); } mutedStatus.setVisibility(relationship.isSourceMutingTarget() ? VISIBLE : GONE); }
From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java
License:Open Source License
private void setMenu(final Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = mUser; final Relationship relationship = mRelationship; if (twitter == null || user == null) return;/*from w w w . j av a 2s.c o m*/ final int activatedColor = ThemeUtils.getUserThemeColor(getActivity()); final boolean isMyself = user.account_id == user.id; final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget(); final boolean isProtected = user.is_protected; final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id); final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id); setMenuItemAvailability(menu, MENU_EDIT, isMyself); final MenuItem followItem = menu.findItem(MENU_FOLLOW); followItem.setVisible(!isMyself); final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself && relationship != null; followItem.setEnabled(shouldShowFollowItem); if (shouldShowFollowItem) { followItem.setTitle( isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow); followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add); } else { followItem.setTitle(null); followItem.setIcon(null); } if (user.id != user.account_id && relationship != null) { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget()); setMenuItemAvailability(menu, MENU_BLOCK, true); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (blockItem != null) { final Drawable blockIcon = blockItem.getIcon(); if (relationship.isSourceBlockingTarget()) { blockItem.setTitle(R.string.unblock); blockIcon.mutate(); blockIcon.setColorFilter(activatedColor, PorterDuff.Mode.SRC_ATOP); } else { blockItem.setTitle(R.string.block); blockIcon.clearColorFilter(); } } } else { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); setMenuItemAvailability(menu, MENU_BLOCK, false); setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } }
From source file:org.getlantern.firetweet.fragment.support.UserFragment.java
License:Open Source License
@Override public void onPrepareOptionsMenu(final Menu menu) { if (!shouldUseNativeMenu() || !menu.hasVisibleItems()) return;//from w w w . j a va 2 s .c o m final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = getUser(); final Relationship relationship = mRelationship; if (twitter == null || user == null) return; final boolean isMyself = user.account_id == user.id; final MenuItem mentionItem = menu.findItem(MENU_MENTION); if (mentionItem != null) { mentionItem.setTitle( getString(R.string.mention_user_name, UserColorNameUtils.getDisplayName(getActivity(), user))); } Utils.setMenuItemAvailability(menu, MENU_MENTION, !isMyself); Utils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself); // final MenuItem followItem = menu.findItem(MENU_FOLLOW); // followItem.setVisible(!isMyself); // final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself // && relationship != null; // followItem.setEnabled(shouldShowFollowItem); // if (shouldShowFollowItem) { // followItem.setTitle(isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request // : R.string.follow); // followItem.setIcon(isFollowing ? R.drawable.ic_action_cancel : R.drawable.ic_action_add); // } else { // followItem.setTitle(null); // followItem.setIcon(null); // } if (!isMyself && relationship != null) { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget()); setMenuItemAvailability(menu, MENU_BLOCK, true); setMenuItemAvailability(menu, MENU_MUTE_USER, true); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (blockItem != null) { final boolean blocking = relationship.isSourceBlockingTarget(); ActionIconDrawable.setMenuHighlight(blockItem, new FiretweetMenuInfo(blocking)); blockItem.setTitle(blocking ? R.string.unblock : R.string.block); } final MenuItem muteItem = menu.findItem(MENU_MUTE_USER); if (muteItem != null) { final boolean muting = relationship.isSourceMutingTarget(); ActionIconDrawable.setMenuHighlight(muteItem, new FiretweetMenuInfo(muting)); muteItem.setTitle(muting ? R.string.unmute : R.string.mute); } final MenuItem filterItem = menu.findItem(MENU_ADD_TO_FILTER); if (filterItem != null) { final boolean filtering = Utils.isFilteringUser(getActivity(), user.id); ActionIconDrawable.setMenuHighlight(filterItem, new FiretweetMenuInfo(filtering)); filterItem.setTitle(filtering ? R.string.remove_from_filter : R.string.add_to_filter); } } else { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); setMenuItemAvailability(menu, MENU_BLOCK, false); setMenuItemAvailability(menu, MENU_MUTE_USER, false); setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } setMenuItemAvailability(menu, R.id.muted_users, isMyself); setMenuItemAvailability(menu, R.id.blocked_users, isMyself); final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER, user); intent.putExtras(extras); menu.removeGroup(MENU_GROUP_USER_EXTENSION); addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION); }
From source file:org.getlantern.firetweet.fragment.support.UserFragment.java
License:Open Source License
@Override public void onClick(final View view) { final FragmentActivity activity = getActivity(); final ParcelableUser user = getUser(); if (activity == null || user == null) return;/*ww w. j av a 2 s. c om*/ switch (view.getId()) { case R.id.retry: { getUserInfo(true); break; } case R.id.follow: { if (user.id == user.account_id) { final Bundle extras = new Bundle(); extras.putLong(EXTRA_ACCOUNT_ID, user.account_id); final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE); intent.setClass(getActivity(), UserProfileEditorActivity.class); intent.putExtras(extras); startActivity(intent); break; } final Relationship relationship = mRelationship; final AsyncTwitterWrapper twitter = getTwitterWrapper(); if (relationship == null || twitter == null) return; if (relationship.isSourceBlockingTarget()) { twitter.destroyBlockAsync(user.account_id, user.id); } else if (relationship.isSourceFollowingTarget()) { DestroyFriendshipDialogFragment.show(getFragmentManager(), user); } else { twitter.createFriendshipAsync(user.account_id, user.id); } break; } case R.id.profile_image: { final String url = getOriginalTwitterProfileImage(user.profile_image_url); final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) }; Utils.openMedia(activity, user.account_id, false, null, media); break; } case R.id.profile_banner: { if (user.profile_banner_url == null) return; final String url = user.profile_banner_url + "/ipad_retina"; final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) }; Utils.openMedia(activity, user.account_id, false, null, media); break; } case R.id.listed_container: { openUserLists(getActivity(), user.account_id, user.id, user.screen_name); break; } case R.id.followers_container: { openUserFollowers(getActivity(), user.account_id, user.id, user.screen_name); break; } case R.id.friends_container: { openUserFriends(getActivity(), user.account_id, user.id, user.screen_name); break; } case R.id.name_container: { if (user.account_id != user.id) return; startActivity(new Intent(getActivity(), UserProfileEditorActivity.class)); break; } } }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createCachedRelationship(final Relationship relationship, final long accountId) { final ContentValues values = new ContentValues(); values.put(CachedRelationships.ACCOUNT_ID, accountId); values.put(CachedRelationships.USER_ID, relationship.getTargetUserId()); values.put(CachedRelationships.FOLLOWING, relationship.isSourceFollowingTarget()); values.put(CachedRelationships.FOLLOWED_BY, relationship.isSourceFollowedByTarget()); values.put(CachedRelationships.BLOCKING, relationship.isSourceBlockingTarget()); values.put(CachedRelationships.BLOCKED_BY, relationship.isSourceBlockedByTarget()); values.put(CachedRelationships.MUTING, relationship.isSourceMutingTarget()); return values; }
From source file:org.mariotaku.twidere.fragment.support.UserFragment.java
License:Open Source License
@Override public void onPrepareOptionsMenu(final Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = getUser(); final Relationship relationship = mRelationship; if (twitter == null || user == null) return;/*from ww w . j a v a 2 s. co m*/ final boolean isMyself = user.account_id == user.id; final MenuItem mentionItem = menu.findItem(MENU_MENTION); if (mentionItem != null) { final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); mentionItem.setTitle(getString(R.string.mention_user_name, displayName)); } MenuUtils.setMenuItemAvailability(menu, MENU_MENTION, !isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.saved_searches, isMyself); // final MenuItem followItem = menu.findItem(MENU_FOLLOW); // followItem.setVisible(!isMyself); // final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself // && relationship != null; // followItem.setEnabled(shouldShowFollowItem); // if (shouldShowFollowItem) { // followItem.setTitle(isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request // : R.string.follow); // followItem.setIcon(isFollowing ? R.drawable.ic_action_cancel : R.drawable.ic_action_add); // } else { // followItem.setTitle(null); // followItem.setIcon(null); // } if (!isMyself && relationship != null) { MenuUtils.setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget()); MenuUtils.setMenuItemAvailability(menu, MENU_BLOCK, true); MenuUtils.setMenuItemAvailability(menu, MENU_MUTE_USER, true); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (blockItem != null) { final boolean blocking = relationship.isSourceBlockingTarget(); ActionIconDrawable.setMenuHighlight(blockItem, new TwidereMenuInfo(blocking)); blockItem.setTitle(blocking ? R.string.unblock : R.string.block); } final MenuItem muteItem = menu.findItem(MENU_MUTE_USER); if (muteItem != null) { final boolean muting = relationship.isSourceMutingTarget(); ActionIconDrawable.setMenuHighlight(muteItem, new TwidereMenuInfo(muting)); muteItem.setTitle(muting ? R.string.unmute : R.string.mute); } final MenuItem filterItem = menu.findItem(MENU_ADD_TO_FILTER); if (filterItem != null) { final boolean filtering = Utils.isFilteringUser(getActivity(), user.id); ActionIconDrawable.setMenuHighlight(filterItem, new TwidereMenuInfo(filtering)); filterItem.setTitle(filtering ? R.string.remove_from_filter : R.string.add_to_filter); } } else { MenuUtils.setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); MenuUtils.setMenuItemAvailability(menu, MENU_BLOCK, false); MenuUtils.setMenuItemAvailability(menu, MENU_MUTE_USER, false); MenuUtils.setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } MenuUtils.setMenuItemAvailability(menu, R.id.muted_users, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.blocked_users, isMyself); final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER, user); intent.putExtras(extras); menu.removeGroup(MENU_GROUP_USER_EXTENSION); Utils.addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION); }
From source file:org.mariotaku.twidere.fragment.support.UserFragment.java
License:Open Source License
@Override public void onClick(final View view) { final FragmentActivity activity = getActivity(); final ParcelableUser user = getUser(); if (activity == null || user == null) return;/*from w ww . j a v a 2 s. c o m*/ switch (view.getId()) { case R.id.error_container: { getUserInfo(true); break; } case R.id.follow: { if (user.id == user.account_id) { Utils.openProfileEditor(getActivity(), user.account_id); break; } final Relationship relationship = mRelationship; final AsyncTwitterWrapper twitter = getTwitterWrapper(); if (relationship == null || twitter == null) return; if (relationship.isSourceBlockingTarget()) { twitter.destroyBlockAsync(user.account_id, user.id); } else if (relationship.isSourceFollowingTarget()) { DestroyFriendshipDialogFragment.show(getFragmentManager(), user); } else { twitter.createFriendshipAsync(user.account_id, user.id); } break; } case R.id.profile_image: { final String url = Utils.getOriginalTwitterProfileImage(user.profile_image_url); final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) }; //TODO open media animation Bundle options = null; Utils.openMedia(activity, user.account_id, false, null, media, options); break; } case R.id.profile_banner: { if (user.profile_banner_url == null) return; final String url = user.profile_banner_url + "/ipad_retina"; final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) }; //TODO open media animation Bundle options = null; Utils.openMedia(activity, user.account_id, false, null, media, options); break; } case R.id.listed_container: { Utils.openUserLists(getActivity(), user.account_id, user.id, user.screen_name); break; } case R.id.followers_container: { Utils.openUserFollowers(getActivity(), user.account_id, user.id, user.screen_name); break; } case R.id.friends_container: { Utils.openUserFriends(getActivity(), user.account_id, user.id, user.screen_name); break; } case R.id.name_container: { if (user.account_id != user.id) return; Utils.openProfileEditor(getActivity(), user.account_id); break; } } }
From source file:twitter4j.examples.friendship.ShowFriendship.java
License:Apache License
/** * Usage: java twitter4j.examples.friendship.ShowFriendship [source screen name] [target screen name] * * @param args message//w w w. j av a2 s . co m */ public static void main(String[] args) { if (args.length < 2) { System.out.println( "Usage: java twitter4j.examples.friendship.ShowFriendship [source screen name] [target screen name]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); Relationship relationship = twitter.showFriendship(args[0], args[1]); System.out.println("isSourceBlockingTarget: " + relationship.isSourceBlockingTarget()); System.out.println("isSourceFollowedByTarget: " + relationship.isSourceFollowedByTarget()); System.out.println("isSourceFollowingByTarget: " + relationship.isSourceFollowingTarget()); System.out.println("isSourceNotificationsEnabled: " + relationship.isSourceNotificationsEnabled()); System.out.println("canSourceDm: " + relationship.canSourceDm()); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to show friendship: " + te.getMessage()); System.exit(-1); } }