Example usage for twitter4j Relationship isSourceFollowingTarget

List of usage examples for twitter4j Relationship isSourceFollowingTarget

Introduction

In this page you can find the example usage for twitter4j Relationship isSourceFollowingTarget.

Prototype

boolean isSourceFollowingTarget();

Source Link

Document

Checks if source user is following target user

Usage

From source file:MainActivity.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    try {/*  ww  w.  j a va 2  s. 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:au.com.tyo.services.sn.twitter.SNTwitter.java

License:Apache License

@Override
public void addPeopleInNetwork() throws Exception {
    try {/*from ww  w . j a v a 2s  . c o  m*/
        String name = user.getName();
        Relationship rel = twitter.showFriendship(name, getAppId());
        if (!rel.isSourceFollowingTarget())
            twitter.createFriendship(getAppId());
    } catch (Exception e) {
        twitter.createFriendship(getAppId());
    }
}

From source file:com.freshdigitable.udonroad.TimelineInstTestBase.java

License:Apache License

protected int setupDefaultUserInfoTimeline() throws TwitterException {
    final User loginUser = getLoginUser();
    final ResponseList<Status> responseList = createDefaultResponseList(loginUser);
    this.responseList = responseList;
    final ResponseList<Status> emptyStatusResponseList = createResponseList();

    final int size = responseList.size();
    when(loginUser.getStatusesCount()).thenReturn(size);
    when(twitter.getUserTimeline(loginUser.getId())).thenReturn(responseList);
    when(twitter.getUserTimeline(anyLong(), any(Paging.class))).thenReturn(emptyStatusResponseList);
    when(twitter.getFavorites(anyLong())).thenReturn(emptyStatusResponseList);
    final PagableResponseList<User> emptyUserPagableResponseList = mock(PagableResponseList.class);
    when(twitter.getFollowersList(anyLong(), anyLong())).thenReturn(emptyUserPagableResponseList);
    when(twitter.getFriendsList(anyLong(), anyLong())).thenReturn(emptyUserPagableResponseList);

    final Relationship relationship = mock(Relationship.class);
    when(relationship.isSourceFollowingTarget()).thenReturn(true);
    when(relationship.isSourceMutingTarget()).thenReturn(false);
    when(twitter.showFriendship(anyLong(), anyLong())).thenReturn(relationship);
    return responseList.size();
}

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 {/*from   w  ww  . j a  v  a  2 s. c  o m*/
        followingStatus.setVisibility(GONE);
    }
    mutedStatus.setVisibility(relationship.isSourceMutingTarget() ? VISIBLE : GONE);
}

From source file:com.javielinux.infos.InfoUsers.java

License:Apache License

public void checkFriend(Context context, String name) {
    if (!hasFriendly(name)) {
        addFriendly(name);//from   w  ww  .j ava  2 s  . c o m
    }
    if (!isCheckFriendly(name)) {
        Friend friend = friendly.get(name);
        try {
            //Entity ent = DataFramework.getInstance().getTopEntity("users", "name = '"+getName()+"'", "");
            ConnectionManager.getInstance().open(context);
            Twitter twitter = ConnectionManager.getInstance().getUserForSearchesTwitter();
            Relationship relationship = twitter.showFriendship(getName(), name);
            friend.friend = relationship.isSourceFollowingTarget();
            friend.follower = relationship.isSourceFollowedByTarget();
            friend.checked = true;
            friendly.remove(name);
            friendly.put(name, friend);
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.michaelfitzmaurice.clocktwerk.apps.FollowChecker.java

License:Apache License

public static void main(String[] args) throws Exception {

    String source = args[0];//from   w  ww.ja va2 s.  co m
    String target = args[1];

    LOG.info("Setting up Twitter client...");
    Twitter twitter = new TwitterFactory().getInstance();
    LOG.info("Twitter client connected");

    LOG.info("Inspecting Twitter relationship between {} and {} ", source, target);
    Relationship relationship = twitter.showFriendship(source, target);
    boolean targetFollowsSource = relationship.isSourceFollowedByTarget();
    boolean sourceFollowsTarget = relationship.isSourceFollowingTarget();

    LOG.info("{} follows {}: {}", new Object[] { target, source, targetFollowsSource });
    LOG.info("{} follows {}: {}", new Object[] { source, target, sourceFollowsTarget });
}

From source file:com.SocialAccess.TwitterSearch.java

public static String[] FriendshipStatus(String[] args) {

    if (args.length < 2) {
        System.out.println("Usage: [source screen name] [target screen name]");
        System.exit(-1);//  w  w  w .  ja v  a  2  s  .c  o m
    }

    String[] lineConnection = new String[2];
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Relationship relationship = twitter.showFriendship(args[0], args[1]);

        lineConnection[0] = args[0] + " is followed by " + args[1] + " "
                + relationship.isSourceFollowedByTarget();
        lineConnection[1] = args[0] + " is following " + args[1] + " " + relationship.isSourceFollowingTarget();

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to show friendship: " + te.getMessage());
        System.exit(-1);
    }
    return lineConnection;
}

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

License:Open Source License

private boolean handleMenuItemClick(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }/*from  ww  w .ja  v a  2 s  .c  o  m*/
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final ContentResolver resolver = getContentResolver();
        resolver.delete(Filters.Users.CONTENT_URI, Where.equals(Filters.Users.USER_ID, user.id).getSQL(), null);
        resolver.insert(Filters.Users.CONTENT_URI, makeFilterdUserContentValues(user));
        showInfoMessage(getActivity(), R.string.message_user_muted, false);
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWITTNUKER);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_RECIPIENT_ID, String.valueOf(user.id));
        startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, getUserColor(getActivity(), user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(getActivity(), user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(getActivity(), user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    case MENU_OPEN_WITH_ACCOUNT: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(getActivity(), AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    case MENU_EDIT: {
        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);
        return true;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                if (Utils.isDebugBuild())
                    Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

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;//  w  w w.  j  a v 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:net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment.java

License:Open Source License

private void updateRelationship(Activity activity, final long userId) {
    MainActivity mainActivity = (MainActivity) activity;
    Account account = mainActivity.getCurrentAccount();
    Twitter twitter = new TwitterApi(account).getTwitter();
    if (userId == account.userID) {
        textViewFollowed.setText(R.string.user_detail_followed_is_me);
        buttonFollow.setVisibility(View.GONE);
    } else {/*from www.  j  a v  a 2s .  c om*/
        int theme = mainActivity.getThemeIndex();
        lockFollowButton(activity);
        textViewFollowed.setText(R.string.user_detail_loading);
        final Drawable red = Themes.getStyledDrawable(activity, theme, R.attr.button_round_red);
        final Drawable blue = Themes.getStyledDrawable(activity, theme, R.attr.button_round_blue);
        new ShowFriendshipTask(twitter, userId) {
            @Override
            protected void onPostExecute(Relationship relationship) {
                if (relationship != null) {
                    boolean isFollowing = relationship.isSourceFollowingTarget();
                    boolean isFollowed = relationship.isSourceFollowedByTarget();
                    setFollowButtonState(isFollowing, red, blue);
                    textViewFollowed.setText(
                            isFollowed ? R.string.user_detail_followed : R.string.user_detail_not_followed);
                }
            }
        }.execute();
    }
}