Example usage for twitter4j User getOriginalProfileImageURL

List of usage examples for twitter4j User getOriginalProfileImageURL

Introduction

In this page you can find the example usage for twitter4j User getOriginalProfileImageURL.

Prototype

String getOriginalProfileImageURL();

Source Link

Usage

From source file:au.net.moon.tUtils.TUser.java

License:Open Source License

/**
 * Create a user object from a twitter4j user.
 * /*  ww  w.  ja  va  2 s .  c  o  m*/
 * @param twitterUser
 *            a twitter4j user object
 */
public TUser(twitter4j.User twitterUser) {
    id = twitterUser.getId();
    name = twitterUser.getName();
    screenName = twitterUser.getScreenName();
    location = twitterUser.getLocation();
    description = twitterUser.getDescription();
    if (twitterUser.getProfileImageURL() != null) {
        profileImageUrl = twitterUser.getProfileImageURL().toString();
    } else {
        profileImageUrl = "";
    }
    if (twitterUser.getURL() != null) {
        url = twitterUser.getURL().toString();
    } else {
        url = "";
    }
    createdAt = twitterUser.getCreatedAt();
    isProtected = twitterUser.isProtected();
    followersCount = twitterUser.getFollowersCount();
    // Not interested in users latest tweet, so just leave blank
    status = "";
    profileBackgroundColor = twitterUser.getProfileBackgroundColor();
    profileTextColor = twitterUser.getProfileTextColor();
    profileLinkColor = twitterUser.getProfileLinkColor();
    profileSidebarFillColor = twitterUser.getProfileSidebarFillColor();
    profileSidebarBorderColor = twitterUser.getProfileSidebarBorderColor();
    friendsCount = twitterUser.getFriendsCount();
    favouritesCount = twitterUser.getFavouritesCount();
    utcOffset = twitterUser.getUtcOffset();
    timeZone = twitterUser.getTimeZone();
    if (twitterUser.getOriginalProfileImageURL() != null) {
        profileBackgroundImageUrl = twitterUser.getOriginalProfileImageURL().toString();
    } else {
        profileBackgroundImageUrl = "";
    }
    isProfileBackgroundTiled = twitterUser.isProfileBackgroundTiled();
    statusesCount = twitterUser.getStatusesCount();
    isGeoEnabled = twitterUser.isGeoEnabled();
    isVerified = twitterUser.isVerified();
    // isFollowing = twitterUser.isFollowing();

    isContributorsEnabled = twitterUser.isContributorsEnabled();
    isProfileUseBackgroundImage = twitterUser.isProfileUseBackgroundImage();
    isShowAllInLineMedia = twitterUser.isShowAllInlineMedia();
    lang = twitterUser.getLang();
    isTranslator = twitterUser.isTranslator();
    listedCount = twitterUser.getListedCount();
    isFollowRequestSent = twitterUser.isFollowRequestSent();

    // TODO: Need to pass in the searchAPI id if I have it.
    searchAPI_userID = "";
}

From source file:com.daiv.android.twitter.adapters.TimelineArrayAdapter.java

License:Apache License

public void bindView(final View view, Status status, int position) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    if (holder.expandArea.getVisibility() == View.VISIBLE) {
        removeExpansionNoAnimation(holder);
    }/*from   w w  w . j  ava  2s .c  om*/

    Status thisStatus;

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    holder.tweetId = thisStatus.getId();
    final long id = holder.tweetId;
    final String profilePic = user.getOriginalProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);

    final String tweetText = html[0];
    final String picUrl = html[1];
    holder.picUrl = picUrl;
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    final boolean inAConversation = thisStatus.getInReplyToStatusId() != -1;

    holder.gifUrl = TweetLinkUtils.getGIFUrl(status, otherUrl);

    if (holder.isAConversation != null) {
        if (inAConversation) {
            if (holder.isAConversation.getVisibility() != View.VISIBLE) {
                holder.isAConversation.setVisibility(View.VISIBLE);
            }
        } else {
            if (holder.isAConversation.getVisibility() != View.GONE) {
                holder.isAConversation.setVisibility(View.GONE);
            }
        }
    }

    if (!settings.reverseClickActions) {
        final String fRetweeter = retweeter;
        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                String link;

                boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                        && !(hasGif);
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");

                return true;
            }
        });

        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }
            }
        });

    } else {
        final String fRetweeter = retweeter;
        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }

                String link;

                boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                        && !(hasGif);
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");
            }
        });

        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }

                return true;
            }
        });
    }

    if (!screenname.equals(username)) {

    } else {
        // need to clear the click listener so it isn't left over from another profile
        holder.profilePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                return true;
            }
        });
    }

    if (TestLayout == AppSettings.LAYOUT_FULL_SCREEN
            || (settings.nameAndHandleOnTweet && settings.addonTheme)) {
        if (holder.screenTV.getVisibility() == View.GONE) {
            holder.screenTV.setVisibility(View.VISIBLE);
        }
        holder.screenTV.setText("@" + screenname);
        holder.name.setText(name);
    } else {
        if (!settings.showBoth) {
            holder.name.setText(settings.displayScreenName ? "@" + screenname : name);
        } else {
            if (holder.screenTV.getVisibility() == View.GONE) {
                holder.screenTV.setVisibility(View.VISIBLE);
            }
            holder.name.setText(name);
            holder.screenTV.setText("@" + screenname);
        }
    }

    if (!settings.absoluteDate) {
        holder.time.setText(Utils.getTimeAgo(time, context));
    } else {
        Date date = new Date(time);
        holder.time
                .setText(timeFormatter.format(date).replace("24:", "00:") + ", " + dateFormatter.format(date));
    }

    holder.tweet.setText(tweetText);

    boolean picture = false;

    if (settings.inlinePics) {
        if (holder.picUrl.equals("")) {
            if (holder.image.getVisibility() != View.GONE) {
                holder.image.setVisibility(View.GONE);
            }

            if (holder.playButton.getVisibility() == View.VISIBLE) {
                holder.playButton.setVisibility(View.GONE);
            }
        } else {
            if (holder.picUrl.contains("youtube")
                    || (holder.gifUrl != null && !android.text.TextUtils.isEmpty(holder.gifUrl))) {

                if (holder.playButton.getVisibility() == View.GONE) {
                    holder.playButton.setVisibility(View.VISIBLE);
                }

                final String fRetweeter = retweeter;

                holder.image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String link;

                        boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                        boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                                && !(hasGif);
                        if (displayPic) {
                            link = holder.picUrl;
                        } else {
                            link = otherUrl.split("  ")[0];
                        }
                    }
                });

                holder.image.setImageDrawable(transparent);

                picture = true;

            } else {
                holder.image.setImageDrawable(transparent);

                picture = true;

                if (holder.playButton.getVisibility() == View.VISIBLE) {
                    holder.playButton.setVisibility(View.GONE);
                }
            }

            if (holder.image.getVisibility() == View.GONE) {
                holder.image.setVisibility(View.VISIBLE);
            }
        }
    }

    if (type == NORMAL) {
        if (retweeter.length() > 0) {
            holder.retweeter.setText(context.getResources().getString(R.string.retweeter) + retweeter);
            holder.retweeterName = retweeter;
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (holder.retweeter.getVisibility() == View.VISIBLE) {
            holder.retweeter.setVisibility(View.GONE);
        }
    } else if (type == RETWEET) {

        int count = status.getRetweetCount();

        if (count > 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweets_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (count == 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweet_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        }
    }

    if (picture) {
        CacheableBitmapDrawable wrapper = mCache.getFromMemoryCache(holder.picUrl);
        if (wrapper != null) {
            holder.image.setImageDrawable(wrapper);
            picture = false;
        }
    }

    final boolean hasPicture = picture;
    mHandler[currHandler].removeCallbacksAndMessages(null);
    mHandler[currHandler].postDelayed(new Runnable() {
        @Override
        public void run() {
            if (holder.tweetId == id) {
                if (hasPicture) {
                    loadImage(context, holder, holder.picUrl, mCache, id);
                }

                if (settings.useEmoji
                        && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
                    String text = holder.tweet.getText().toString();
                    if (EmojiUtils.emojiPattern.matcher(text).find()) {
                        final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText));
                        holder.tweet.setText(span);
                    }
                }

                holder.tweet.setSoundEffectsEnabled(false);
                holder.tweet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            // we need to manually set the background for click feedback because the spannable
                            // absorbs the click on the background
                            if (!holder.preventNextClick) {
                                holder.background.getBackground()
                                        .setState(new int[] { android.R.attr.state_pressed });
                                new Handler().postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        holder.background.getBackground()
                                                .setState(new int[] { android.R.attr.state_empty });
                                    }
                                }, 25);
                            }

                            holder.background.performClick();
                        }
                    }
                });

                holder.tweet.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            holder.background.performLongClick();
                            holder.preventNextClick = true;
                        }
                        return false;
                    }
                });

                if (holder.retweeter.getVisibility() == View.VISIBLE) {
                    holder.retweeter.setSoundEffectsEnabled(false);
                    holder.retweeter.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                if (!holder.preventNextClick) {
                                    holder.background.getBackground()
                                            .setState(new int[] { android.R.attr.state_pressed });
                                    new Handler().postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            holder.background.getBackground()
                                                    .setState(new int[] { android.R.attr.state_empty });
                                        }
                                    }, 25);
                                }

                                holder.background.performClick();
                            }
                        }
                    });

                    holder.retweeter.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                holder.background.performLongClick();
                                holder.preventNextClick = true;
                            }
                            return false;
                        }
                    });
                }

                TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false);
                TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false);
            }
        }
    }, 400);
    currHandler++;

    if (currHandler == 10) {
        currHandler = 0;
    }

    if (openFirst && position == 0) {
        holder.background.performClick();
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.FavoriteUsersDataSource.java

License:Apache License

public synchronized void createUser(User user, int account) {
    ContentValues values = new ContentValues();

    long id = user.getId();
    String screenName = user.getScreenName();
    String name = user.getName();
    String proPicUrl = user.getOriginalProfileImageURL();

    values.put(FavoriteUsersSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(FavoriteUsersSQLiteHelper.COLUMN_ID, id);
    values.put(FavoriteUsersSQLiteHelper.COLUMN_NAME, name);
    values.put(FavoriteUsersSQLiteHelper.COLUMN_PRO_PIC, proPicUrl);
    values.put(FavoriteUsersSQLiteHelper.COLUMN_SCREEN_NAME, screenName);

    try {/*from   ww w.j  a v a 2 s .c  o  m*/
        database.insert(FavoriteUsersSQLiteHelper.TABLE_HOME, null, values);
    } catch (Exception e) {
        open();
        database.insert(FavoriteUsersSQLiteHelper.TABLE_HOME, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.FollowersDataSource.java

License:Apache License

public synchronized void createUser(User user, int account) {
    ContentValues values = new ContentValues();

    long id = user.getId();
    String screenName = user.getScreenName();
    String name = user.getName();
    String proPicUrl = user.getOriginalProfileImageURL();

    values.put(FollowersSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(FollowersSQLiteHelper.COLUMN_ID, id);
    values.put(FollowersSQLiteHelper.COLUMN_NAME, name);
    values.put(FollowersSQLiteHelper.COLUMN_PRO_PIC, proPicUrl);
    values.put(FollowersSQLiteHelper.COLUMN_SCREEN_NAME, screenName);

    if (database == null || !database.isOpen()) {
        open();//from  w w  w . j  av  a2 s.c  om
    }

    try {
        database.insert(FollowersSQLiteHelper.TABLE_HOME, null, values);
    } catch (Exception e) {
        // already exist. primary key must be unique
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createMention(Context context, Status status, int account) {
    ContentValues values = new ContentValues();
    long id = status.getId();
    long time = new GregorianCalendar().getTime().getTime(); // current time
    int type = TYPE_MENTION;

    User user = status.getUser();
    String users = "@" + user.getScreenName() + " ";
    String text = status.getText();
    String title = context.getResources().getString(R.string.mentioned_by) + " <b>@" + user.getScreenName()
            + "</b>";

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, user.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {// w  ww .j a  v a 2 s  .c o m
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createFavoriteUserInter(Context context, Status status, int account) {
    ContentValues values = new ContentValues();
    long id = status.getId();
    long time = new GregorianCalendar().getTime().getTime(); // current time
    int type = TYPE_FAV_USER;

    User user = status.getUser();
    String users = "@" + user.getScreenName() + " ";
    String text = status.getText();
    String title = "<b>@" + user.getScreenName() + "</b> " + context.getResources().getString(R.string.tweeted);

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, user.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {//from ww w  . j a v a  2  s  . co m
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createInteraction(Context context, User source, Status status, int account, int type) {
    ContentValues values = new ContentValues();
    long id;/*from  w ww.  j  av  a 2 s . com*/
    if (status != null) {
        id = status.getId();
    } else {
        id = 0; // 0 will be used for whenever it is just a follow
    }
    long time = new GregorianCalendar().getTime().getTime(); // current time

    String users = "@" + source.getScreenName() + " ";

    String text = "";

    String title = "";

    switch (type) {
    case TYPE_FAVORITE:
        title = "<b>@" + source.getScreenName() + "</b> "
                + context.getResources().getString(R.string.favorited);
        text = status.getText();
        break;
    case TYPE_RETWEET:
        title = "<b>@" + source.getScreenName() + "</b> "
                + context.getResources().getString(R.string.retweeted);
        text = status.getRetweetedStatus().getText();
        break;
    case TYPE_FOLLOWER:
        title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.followed);
        break;
    case TYPE_QUOTED_TWEET:
        title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.quoted);
        text = status.getText();
        break;
    }

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void updateInteraction(Context context, User source, Status status, int account, int type) {
    if (type == TYPE_RETWEET) {
        status = status.getRetweetedStatus();
    }/*from   ww  w .j  a v a  2 s .c  o  m*/
    Cursor cursor = interactionExists(status.getId(), account);

    if (cursor.getCount() > 0) { // it does exist
        // i want to do the updating stuff

        if (cursor.moveToFirst()) {
            String users = cursor.getString(cursor.getColumnIndex(InteractionsSQLiteHelper.COLUMN_USERS));
            String title = "";

            users += "@" + source.getScreenName() + " ";

            String[] x = users.split(" ");

            if (type == TYPE_RETWEET) { // retweet
                title = x.length + " " + context.getResources().getString(R.string.new_retweets);
            } else if (type == TYPE_FAVORITE) { // favorite
                title = x.length + " " + context.getResources().getString(R.string.new_favorites);
            } else {
                title = x.length + " " + context.getResources().getString(R.string.new_quotes);
            }

            ContentValues cv = new ContentValues();
            cv.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
            cv.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
            cv.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);
            cv.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL());
            cv.put(InteractionsSQLiteHelper.COLUMN_TIME, new GregorianCalendar().getTimeInMillis());

            try {
                database.update(InteractionsSQLiteHelper.TABLE_INTERACTIONS, cv,
                        InteractionsSQLiteHelper.COLUMN_TWEET_ID + " = ?",
                        new String[] { status.getId() + "" });
            } catch (Exception e) {
                open();
                database.update(InteractionsSQLiteHelper.TABLE_INTERACTIONS, cv,
                        InteractionsSQLiteHelper.COLUMN_TWEET_ID + " = ?",
                        new String[] { status.getId() + "" });
            }
        }
    } else {
        // this creates the entry
        createInteraction(context, source, status, account, type);
    }
}

From source file:com.daiv.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java

License:Apache License

public void getFollowers(final User user, final AsyncListView listView) {
    spinner.setVisibility(View.VISIBLE);
    canRefresh = false;//from  ww w .  ja v  a 2s.c  o  m

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                try {
                    if (followingIds == null && user.getId() == settings.myId) {
                        long currCursor = -1;
                        IDs idObject;
                        int rep = 0;

                        do {
                            // gets 5000 ids at a time
                            idObject = twitter.getFriendsIDs(settings.myId, currCursor);

                            long[] lIds = idObject.getIDs();
                            followingIds = new ArrayList<Long>();
                            for (int i = 0; i < lIds.length; i++) {
                                followingIds.add(lIds[i]);
                            }

                            rep++;
                        } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3);
                    }
                } catch (Throwable t) {
                    followingIds = null;
                }

                PagableResponseList<User> friendsPaging = twitter.getFollowersList(user.getId(),
                        currentFollowers, 100);

                for (int i = 0; i < friendsPaging.size(); i++) {
                    followers.add(friendsPaging.get(i));
                }

                if (friendsPaging.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                currentFollowers = friendsPaging.getNextCursor();

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (followersAdapter == null) {
                            if (followingIds == null) {
                                // we will do a normal array adapter
                                followersAdapter = new PeopleArrayAdapter(context, followers);
                            } else {
                                followersAdapter = new FollowersArrayAdapter(context, followers, followingIds);
                            }
                            listView.setAdapter(followersAdapter);
                        } else {
                            followersAdapter.notifyDataSetChanged();
                        }

                        if (settings.roundContactImages) {
                            ImageUtils.loadSizedCircleImage(context, profilePicture,
                                    thisUser.getOriginalProfileImageURL(), mCache, 96);
                        } else {
                            ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(),
                                    mCache);
                        }

                        String url = user.getProfileBannerURL();
                        ImageUtils.loadImage(context, background, url, mCache);

                        canRefresh = true;
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (user != null && user.isProtected()) {
                            Toast.makeText(context, getResources().getString(R.string.protected_account),
                                    Toast.LENGTH_SHORT).show();
                            if (settings.roundContactImages) {
                                ImageUtils.loadSizedCircleImage(context, profilePicture,
                                        thisUser.getOriginalProfileImageURL(), mCache, 96);
                            } else {
                                ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(),
                                        mCache);
                            }

                            String url = user.getProfileBannerURL();
                            ImageUtils.loadImage(context, background, url, mCache);
                        } else {
                            Toast.makeText(context, getResources().getString(R.string.error_loading_timeline),
                                    Toast.LENGTH_SHORT).show();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                        hasMore = false;
                    }
                });
            }
        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java

License:Apache License

public void getFollowing(final User user, final AsyncListView listView) {
    spinner.setVisibility(View.VISIBLE);
    canRefresh = false;// www  . jav a2  s  .  c  o m

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                PagableResponseList<User> friendsPaging;
                try {
                    friendsPaging = twitter.getFriendsList(user.getId(), currentFollowing, 100);
                } catch (OutOfMemoryError e) {
                    return;
                }

                for (int i = 0; i < friendsPaging.size(); i++) {
                    following.add(friendsPaging.get(i));
                    Log.v("friends_list", friendsPaging.get(i).getName());
                }

                if (friendsPaging.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                currentFollowing = friendsPaging.getNextCursor();

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (followingAdapter == null) {
                            followingAdapter = new PeopleArrayAdapter(context, following);
                            listView.setAdapter(followingAdapter);
                        } else {
                            followingAdapter.notifyDataSetChanged();
                        }

                        if (settings.roundContactImages) {
                            ImageUtils.loadSizedCircleImage(context, profilePicture,
                                    thisUser.getOriginalProfileImageURL(), mCache, 96);
                        } else {
                            ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(),
                                    mCache);
                        }

                        String url = user.getProfileBannerURL();
                        ImageUtils.loadImage(context, background, url, mCache);

                        canRefresh = true;
                        spinner.setVisibility(View.GONE);
                    }
                });

            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (user != null && user.isProtected()) {
                                Toast.makeText(context, getResources().getString(R.string.protected_account),
                                        Toast.LENGTH_SHORT).show();
                                if (settings.roundContactImages) {
                                    ImageUtils.loadSizedCircleImage(context, profilePicture,
                                            thisUser.getOriginalProfileImageURL(), mCache, 96);
                                } else {
                                    ImageUtils.loadImage(context, profilePicture,
                                            user.getOriginalProfileImageURL(), mCache);
                                }

                                String url = user.getProfileBannerURL();
                                ImageUtils.loadImage(context, background, url, mCache);
                            } else {
                                Toast.makeText(context,
                                        getResources().getString(R.string.error_loading_timeline),
                                        Toast.LENGTH_SHORT).show();
                            }
                            spinner.setVisibility(View.GONE);
                        } catch (Exception e) {
                            // fragment not attached
                        }
                        canRefresh = false;
                        hasMore = false;
                    }
                });
            }
        }
    }).start();
}