List of usage examples for twitter4j User getId
long getId();
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;// w w w. j a v a 2 s. co 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(); }
From source file:com.daiv.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java
License:Apache License
public void getTimeline(final User user, final AsyncListView listView) { spinner.setVisibility(View.VISIBLE); canRefresh = false;/*from w w w . j a v a 2s .co m*/ new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); List<twitter4j.Status> statuses = twitter.getUserTimeline(user.getId(), timelinePaging); timelinePaging.setPage(timelinePaging.getPage() + 1); for (twitter4j.Status s : statuses) { timelineStatuses.add(s); } if (statuses.size() > 17) { hasMore = true; } else { hasMore = false; } ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (timelineAdapter != null) { timelineAdapter.notifyDataSetChanged(); } else { timelineAdapter = new TimelineArrayAdapter(context, timelineStatuses, screenName); listView.setItemManager(builder.build()); listView.setAdapter(timelineAdapter); } 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); spinner.setVisibility(View.GONE); canRefresh = true; } }); } 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) { // not attached } canRefresh = false; hasMore = false; } }); } catch (OutOfMemoryError x) { x.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { try { Toast.makeText(context, context.getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show(); spinner.setVisibility(View.GONE); } catch (Exception e) { // not attached } canRefresh = false; hasMore = false; } }); } } }).start(); }
From source file:com.dwdesign.tweetings.fragment.UserListDetailsFragment.java
License:Open Source License
public void changeUserList(final long account_id, final UserList user_list) { if (user_list == null || getActivity() == null || !isMyActivatedAccount(getActivity(), account_id)) return;/*from w w w. j ava 2 s. c om*/ getLoaderManager().destroyLoader(0); final User user = user_list.getUser(); if (user == null) return; final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user_list.getId()); mErrorRetryContainer.setVisibility(View.GONE); mAccountId = account_id; mUserListId = user_list.getId(); mUserName = user.getName(); mUserId = user.getId(); mUserScreenName = user.getScreenName(); mListName = user_list.getName(); mListSlug = user_list.getSlug(); final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1; mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0); if (is_multiple_account_enabled) { final Drawable d = mListView.getBackground(); if (d != null) { d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY); mListView.invalidate(); } } mListNameView.setText(mListName); mUserNameView.setText(mDisplayName ? mUserName : mUserScreenName); final String description = user_list.getDescription(); mDescriptionContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE); mDescriptionContainer.setOnLongClickListener(this); mDescriptionView.setText(description); final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView); linkify.setOnLinkClickListener(this); linkify.addAllLinks(); mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); final String profile_image_url_string = parseString(user.getProfileImageURL()); final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image); mProfileImageLoader.displayProfileImage(mProfileImageView, hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); mUserList = user_list; //if (mUserId == mAccountId) { mFollowMoreButton.setText(R.string.more); mFollowMoreButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.expander_open_holo, 0); //} else { // mFollowMoreButton.setText(user_list.isFollowing() ? R.string.unfollow : R.string.follow); // mFollowMoreButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); //} mAdapter.notifyDataSetChanged(); }
From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java
License:Open Source License
public void changeUser(final long account_id, final User user) { mFriendship = null;/* ww w.ja va 2 s . co m*/ mUserId = -1; mAccountId = -1; if (user == null || user.getId() <= 0 || getActivity() == null || !isMyActivatedAccount(getActivity(), account_id)) return; if (mUserInfoTask != null && mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING) { mUserInfoTask.cancel(true); } final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user.getId()); mUserInfoTask = null; mErrorRetryContainer.setVisibility(View.GONE); mAccountId = account_id; mUserId = user.getId(); mScreenName = user.getScreenName(); updateUserColor(); final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1; mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0); if (is_multiple_account_enabled) { final Drawable d = mListView.getBackground(); if (d != null) { d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY); mListView.invalidate(); } } mNameView.setText(user.getName()); mScreenNameView.setText("@" + user.getScreenName()); mScreenNameView.setCompoundDrawablesWithIntrinsicBounds( getUserTypeIconRes(user.isVerified(), user.isProtected()), 0, 0, 0); final String description = user.getDescription(); mDescriptionContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE); mDescriptionContainer.setOnLongClickListener(this); mDescriptionView.setText(description); final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView); linkify.setOnLinkClickListener(this); linkify.addAllLinks(); mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); final String location = user.getLocation(); mLocationContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(location) ? View.VISIBLE : View.GONE); mLocationContainer.setOnLongClickListener(this); mLocationView.setText(location); final String url = user.getURL() != null ? user.getURL().toString() : null; mURLContainer.setVisibility(is_my_activated_account || !isNullOrEmpty(url) ? View.VISIBLE : View.GONE); mURLContainer.setOnLongClickListener(this); mURLView.setText(url); mCreatedAtView.setText(formatToLongTimeString(getActivity(), getTimestampFromDate(user.getCreatedAt()))); mTweetCount.setText(String.valueOf(user.getStatusesCount())); mFollowersCount.setText(String.valueOf(user.getFollowersCount())); mFriendsCount.setText(String.valueOf(user.getFriendsCount())); // final boolean display_profile_image = // mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true); // mProfileImageView.setVisibility(display_profile_image ? View.VISIBLE // : View.GONE); // if (display_profile_image) { final String profile_image_url_string = parseString(user.getProfileImageURL()); final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image); mLazyImageLoader.displayProfileImage(mProfileImageView, hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); // } String profile_banner_url_string = parseString(user.getProfileBannerImageUrl()); if (profile_banner_url_string != null) { final int def_width = getResources().getDisplayMetrics().widthPixels; profile_banner_url_string = profile_banner_url_string + "/" + getBestBannerType(def_width); } final String banner_url = profile_banner_url_string; if (mProfileBackgroundView != null) { mProfileBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP); if (banner_url != null) { mLazyImageLoader.displayPreviewImage(mProfileBackgroundView, banner_url); } else { final Drawable d = getResources().getDrawable(R.drawable.linen); mProfileBackgroundView.setImageDrawable(d); } } mUser = user; if (isMyAccount(getActivity(), user.getId())) { final ContentResolver resolver = getContentResolver(); final ContentValues values = new ContentValues(); final URL profile_image_url = user.getProfileImageURL(); if (profile_image_url != null) { values.put(Accounts.PROFILE_IMAGE_URL, profile_image_url.toString()); } values.put(Accounts.USERNAME, user.getScreenName()); final String where = Accounts.USER_ID + " = " + user.getId() + " AND 1 = 1"; resolver.update(Accounts.CONTENT_URI, values, where, null); } mAdapter.add(new UserRecentPhotosAction()); mAdapter.add(new FavoritesAction()); mAdapter.add(new UserMentionsAction()); mAdapter.add(new UserListTypesAction()); if (user.getId() == mAccountId) { mAdapter.add(new MyTweetsRetweetedAction()); mAdapter.add(new SavedSearchesAction()); boolean nativeMapSupported = true; try { Class.forName("com.google.android.maps.MapActivity"); Class.forName("com.google.android.maps.MapView"); } catch (final ClassNotFoundException e) { nativeMapSupported = false; } if (nativeMapSupported) { mAdapter.add(new UserNearbyAction()); } if (user.isProtected()) { mAdapter.add(new IncomingFriendshipsAction()); } mAdapter.add(new UserBlocksAction()); } mAdapter.notifyDataSetChanged(); if (mRecentPhotosGallery != null) { mRecentPhotosGallery.setVisibility(View.GONE); mRecentPhotosGallery.setAdapter(new ImageAdapter(this.getActivity())); mRecentPhotosGallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ParcelableStatus pStatus = mMediaStatuses.get(position); final ImageSpec spec = getAllAvailableImage(pStatus.image_orig_url_string); if (spec != null) { openImage(UserProfileFragment.this.getActivity(), Uri.parse(spec.full_image_link), pStatus.is_possibly_sensitive); } } }); mMediaTimelineTask = new MediaTimelineTask(this.getActivity(), mAccountId, mUser.getScreenName()); if (mMediaTimelineTask != null) { mMediaTimelineTask.execute(); } } getFriendship(); checkPushTracked(); }
From source file:com.dwdesign.tweetings.loader.IDsUsersLoader.java
License:Open Source License
@Override public List<ParcelableUser> getUsers() throws TwitterException { final Twitter twitter = getTwitter(); if (twitter == null) return null; if (mIDs == null) { mIDs = getIDs();/* ww w. j a va 2s .c o m*/ if (mIDs == null) return null; } final long[] ids = mIDs.getIDs(); final int max_id_idx = mMaxId > 0 ? ArrayUtils.indexOf(ids, mMaxId) : 0; if (max_id_idx < 0) return null; if (max_id_idx == ids.length - 1) return Collections.emptyList(); final int count = max_id_idx + mLoadItemLimit < ids.length ? mLoadItemLimit : ids.length - max_id_idx; final long[] ids_to_load = new long[count]; int temp_idx = max_id_idx; for (int i = 0; i < count; i++) { ids_to_load[i] = ids[temp_idx]; temp_idx++; } final ResponseList<User> users = twitter.lookupUsers(ids_to_load); final List<ParcelableUser> result = new ArrayList<ParcelableUser>(); for (final User user : users) { final int position = ArrayUtils.indexOf(mIDs.getIDs(), user.getId()); result.add(new ParcelableUser(user, mAccountId, position)); } return result; }
From source file:com.dwdesign.tweetings.loader.UserListMembersLoader.java
License:Open Source License
@Override public List<ParcelableUser> getUsers() throws TwitterException { final Twitter twitter = getTwitter(); if (twitter == null) return null; final PagableResponseList<User> users; if (mListId > 0) { if (mUserListId <= 0) { mUserListId = mListId;/*from w ww . j a v a2 s . co m*/ } if (mOwnerId <= 0) { final UserList list = twitter.showUserList(mListId); final User owner = list != null ? list.getUser() : null; mOwnerId = owner != null ? owner.getId() : -1; } users = twitter.getUserListMembers(mListId, mCursor); } else { final UserList list = findUserList(twitter, mUserId, mScreenName, mListName); if (list == null) return null; if (mOwnerId <= 0) { final User owner = list.getUser(); mOwnerId = owner != null ? owner.getId() : -1; } if (list != null && list.getId() > 0) { if (mUserListId <= 0) { mUserListId = list.getId(); } users = twitter.getUserListMembers(list.getId(), mCursor); } else return null; } mNextCursor = users.getNextCursor(); mPrevCursor = users.getPreviousCursor(); final List<ParcelableUser> result = new ArrayList<ParcelableUser>(); final int size = users.size(); for (int i = 0; i < size; i++) { result.add(new ParcelableUser(users.get(i), mAccountId, (mCursor + 1) * 20 + i)); } return result; }
From source file:com.dwdesign.tweetings.model.ParcelableDirectMessage.java
License:Open Source License
public ParcelableDirectMessage(final DirectMessage message, final long account_id, final boolean is_gap) { this.account_id = account_id; this.is_gap = is_gap; final User sender = message.getSender(), recipient = message.getRecipient(); message_id = message.getId();//from w w w . ja va 2 s. com message_timestamp = getTime(message.getCreatedAt()); sender_id = sender != null ? sender.getId() : -1; recipient_id = recipient != null ? recipient.getId() : -1; text = message.getText(); sender_name = sender != null ? sender.getName() : null; recipient_name = recipient != null ? recipient.getName() : null; sender_screen_name = sender != null ? sender.getScreenName() : null; recipient_screen_name = recipient != null ? recipient.getScreenName() : null; sender_profile_image_url = sender != null ? sender.getProfileImageURL() : null; recipient_profile_image_url = recipient != null ? recipient.getProfileImageURL() : null; }
From source file:com.dwdesign.tweetings.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(Status status, final long account_id, final boolean is_gap, final boolean large_inline_image_preview) { this.is_gap = is_gap; this.account_id = account_id; status_id = status.getId();/*from w ww . jav a2s . co m*/ is_retweet = status.isRetweet(); final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null; final User retweet_user = retweeted_status != null ? status.getUser() : null; retweet_id = retweeted_status != null ? retweeted_status.getId() : -1; retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; if (retweeted_status != null) { status = retweeted_status; } final User user = status.getUser(); user_id = user != null ? user.getId() : -1; name = user != null ? user.getName() : null; screen_name = user != null ? user.getScreenName() : null; profile_image_url = user != null ? user.getProfileImageURL() : null; profile_image_url_string = profile_image_url != null ? profile_image_url.toString() : null; is_protected = user != null ? user.isProtected() : false; is_verified = user != null ? user.isVerified() : false; final MediaEntity[] medias = status.getMediaEntities(); status_timestamp = getTime(status.getCreatedAt()); text_html = formatStatusText(status); final PreviewImage preview = getPreviewImage(text_html, large_inline_image_preview ? INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH : INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_SMALL); text_plain = status.getText(); retweet_count = status.getRetweetCount(); in_reply_to_screen_name = status.getInReplyToScreenName(); in_reply_to_status_id = status.getInReplyToStatusId(); source = status.getSource(); location = new ParcelableLocation(status.getGeoLocation()); location_string = location.toString(); is_favorite = status.isFavorited(); has_media = medias != null && medias.length > 0 || preview.has_image; text = text_html != null ? Html.fromHtml(text_html) : null; image_preview_url_string = preview.matched_url; image_orig_url_string = preview.orig_url; image_preview_url = parseURL(image_preview_url_string); text_unescaped = unescape(text_html); String play = null; URLEntity[] urls = status.getURLEntities(); if (urls != null) { for (final URLEntity url : urls) { final URL tco_url = url.getURL(); final URL expanded_url = url.getExpandedURL(); if (tco_url != null && expanded_url != null && expanded_url.toString().contains("play.google.com/store/apps")) { play = expanded_url.toString(); break; } } } play_package = play; is_possibly_sensitive = status.isPossiblySensitive(); }
From source file:com.dwdesign.tweetings.model.ParcelableUser.java
License:Open Source License
public ParcelableUser(final User user, final long account_id, final long position) { this.position = position; this.account_id = account_id; user_id = user.getId(); created_at = getTime(user.getCreatedAt()); is_protected = user.isProtected(); is_verified = user.isVerified();//from w ww . ja va 2s . c o m name = user.getName(); screen_name = user.getScreenName(); description = user.getDescription(); location = user.getLocation(); profile_image_url = user.getProfileImageURL(); profile_image_url_string = parseString(profile_image_url); }
From source file:com.dwdesign.tweetings.model.ParcelableUserList.java
License:Open Source License
public ParcelableUserList(final UserList list, final long account_id, final long position) { final User user = list.getUser(); this.position = position; this.account_id = account_id; list_id = list.getId();//from w w w . j a va2 s .com is_public = list.isPublic(); is_following = list.isFollowing(); name = list.getName(); description = list.getDescription(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageURL(); user_profile_image_url_string = parseString(user_profile_image_url); }