List of usage examples for twitter4j User getProfileImageURL
String getProfileImageURL();
From source file:com.javielinux.api.loaders.ProfileImageLoader.java
License:Apache License
private boolean refreshAvatar() { if (request.getUserId() > 0) { try {//from w w w. j a va 2 s. co m ConnectionManager.getInstance().open(getContext()); Entity ent = new Entity("users", request.getUserId()); User user = ConnectionManager.getInstance().getTwitter(request.getUserId()) .showUser(ent.getInt("user_id")); Bitmap avatar = BitmapFactory.decodeStream( new Utils.FlushedInputStream(new URL(user.getProfileImageURL()).openStream())); String file = ImageUtils.getFileAvatar(request.getUserId()); FileOutputStream out = new FileOutputStream(file); avatar.compress(Bitmap.CompressFormat.JPEG, 90, out); ent.setValue("fullname", user.getName()); ent.save(); avatar.recycle(); } catch (NullPointerException e) { e.printStackTrace(); return false; } catch (OutOfMemoryError e) { e.printStackTrace(); return false; } catch (TwitterException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } catch (Exception e) { e.printStackTrace(); return false; } } return true; }
From source file:com.javielinux.database.EntitySearch.java
License:Apache License
public InfoSaveTweets saveTweets(Context cnt, boolean saveNotifications, long since_id) { ConnectionManager.getInstance().open(cnt); Twitter twitter = ConnectionManager.getInstance().getUserForSearchesTwitter(); InfoSaveTweets out = new InfoSaveTweets(); try {/*from w w w .j a va2 s . c o m*/ int nResult = DataFramework.getInstance().getEntityListCount("tweets", "favorite=0 and search_id=" + getId()); Query query = getQuery(cnt); if (since_id != -1) query.setSinceId(since_id); QueryResult result = twitter.search(query); ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets(); if (tweets.size() > 0) { out.setNewMessages(tweets.size()); out.setNewerId(tweets.get(0).getId()); out.setOlderId(tweets.get(tweets.size() - 1).getId()); if (saveNotifications) { setValue("new_tweets_count", getInt("new_tweets_count") + tweets.size()); save(); } Log.d(Utils.TAG, tweets.size() + " mensajes nuevos en " + getString("name")); long fisrtId = 1; Cursor c = DataFramework.getInstance().getCursor("tweets", new String[] { DataFramework.KEY_ID }, null, null, null, null, DataFramework.KEY_ID + " desc", "1"); if (!c.moveToFirst()) { c.close(); fisrtId = 1; } else { long Id = c.getInt(0) + 1; c.close(); fisrtId = Id; } for (int i = tweets.size() - 1; i >= 0; i--) { /*String sql = "INSERT INTO 'tweets' (" + DataFramework.KEY_ID + ", search_id, url_avatar, username, user_id, tweet_id," + "text, source, to_username, to_user_id, date, favorite) VALUES (" + fisrtId + "," + getId() + ",'" +tweets.get(i).getProfileImageUrl() + "','"+tweets.get(i).getFromUser()+"','" + tweets.get(i).getFromUserId() + "','" + tweets.get(i).getId() + "','" + tweets.get(i).getText() + "','" + tweets.get(i).getSource() + "','"+tweets.get(i).getToUser() +"','"+tweets.get(i).getToUserId()+"','"+String.valueOf(tweets.get(i).getCreatedAt().getTime()) + "',0);\n";*/ User u = tweets.get(i).getUser(); ContentValues args = new ContentValues(); args.put(DataFramework.KEY_ID, "" + fisrtId); args.put("search_id", "" + getId()); if (u.getProfileImageURL() != null) { args.put("url_avatar", u.getProfileImageURL().toString()); } else { args.put("url_avatar", ""); } args.put("username", u.getScreenName()); args.put("fullname", u.getName()); args.put("user_id", "" + u.getId()); args.put("tweet_id", Utils.fillZeros("" + tweets.get(i).getId())); args.put("text", tweets.get(i).getText()); args.put("source", tweets.get(i).getSource()); args.put("to_username", tweets.get(i).getInReplyToScreenName()); args.put("to_user_id", "" + tweets.get(i).getInReplyToUserId()); args.put("date", String.valueOf(tweets.get(i).getCreatedAt().getTime())); if (tweets.get(i).getGeoLocation() != null) { args.put("latitude", tweets.get(i).getGeoLocation().getLatitude()); args.put("longitude", tweets.get(i).getGeoLocation().getLongitude()); } args.put("favorite", "0"); DataFramework.getInstance().getDB().insert("tweets", null, args); fisrtId++; } if (saveNotifications) { setValue("last_tweet_id_notifications", tweets.get(0).getId() + ""); save(); } int total = nResult + tweets.size(); if (total > Utils.MAX_ROW_BYSEARCH) { Log.d(Utils.TAG, "Limpiando base de datos"); String date = DataFramework.getInstance() .getEntityList("tweets", "favorite=0 and search_id=" + getId(), "date desc") .get(Utils.MAX_ROW_BYSEARCH).getString("date"); String sqldelete = "DELETE FROM tweets WHERE favorite=0 AND search_id=" + getId() + " AND date < '" + date + "'"; DataFramework.getInstance().getDB().execSQL(sqldelete); } } } catch (TwitterException e) { e.printStackTrace(); RateLimitStatus rate = e.getRateLimitStatus(); if (rate != null) { out.setError(Utils.LIMIT_ERROR); out.setRate(rate); } else { out.setError(Utils.UNKNOWN_ERROR); } } catch (Exception e) { e.printStackTrace(); out.setError(Utils.UNKNOWN_ERROR); } return out; }
From source file:com.javielinux.database.EntityTweetUser.java
License:Apache License
public InfoSaveTweets saveTweets(Context context, Twitter twitter) { InfoSaveTweets out = new InfoSaveTweets(); try {// w w w . j ava2 s.com String where = "type_id = " + tweet_type + " AND user_tt_id=" + getId(); int nResult = DataFramework.getInstance().getEntityListCount("tweets_user", where); if (nResult > 0) mLastIdNotification = DataFramework.getInstance().getTopEntity("tweets_user", where, "date desc") .getLong("tweet_id"); boolean breakTimeline = false; PreferenceManager.setDefaultValues(context, R.xml.preferences, false); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60")); if (maxDownloadTweet <= 0) maxDownloadTweet = 60; ResponseList<twitter4j.Status> statii = null; ResponseList<twitter4j.DirectMessage> directs = null; if (mLastIdNotification > 0) { if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) { Paging p = new Paging(1, maxDownloadTweet); p.setSinceId(mLastIdNotification); try { statii = twitter.getHomeTimeline(p); } catch (OutOfMemoryError e) { e.printStackTrace(); } if (statii != null && statii.size() >= maxDownloadTweet - 10) { p = new Paging(1, 10); p.setSinceId(mLastIdNotification); p.setMaxId(statii.get(statii.size() - 1).getId()); if (twitter.getHomeTimeline().size() > 0) { breakTimeline = true; } } } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) { Paging p = new Paging(); p.setCount(100); p.setSinceId(mLastIdNotification); statii = twitter.getMentionsTimeline(p); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) { Paging p = new Paging(); p.setCount(100); p.setSinceId(mLastIdNotification); directs = twitter.getDirectMessages(p); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) { Paging p = new Paging(); p.setCount(100); p.setSinceId(mLastIdNotification); directs = twitter.getSentDirectMessages(p); } } else { try { Log.d(Utils.TAG, "Primera carga de " + getTypeText()); if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) { statii = twitter.getHomeTimeline(new Paging(1, 40)); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) { statii = twitter.getMentionsTimeline(new Paging(1, 40)); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) { directs = twitter.getDirectMessages(); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) { directs = twitter.getSentDirectMessages(); } } catch (OutOfMemoryError e) { e.printStackTrace(); } } // guardar statii if (statii != null) { if (statii.size() > 0) { out.setNewMessages(statii.size()); out.setNewerId(statii.get(0).getId()); out.setOlderId(statii.get(statii.size() - 1).getId()); Log.d(Utils.TAG, statii.size() + " mensajes nuevos en " + getTypeText() + " de " + getString("name")); long nextId = 1; Cursor c = DataFramework.getInstance().getCursor("tweets_user", new String[] { DataFramework.KEY_ID }, null, null, null, null, DataFramework.KEY_ID + " desc", "1"); if (!c.moveToFirst()) { c.close(); nextId = 1; } else { long Id = c.getInt(0) + 1; c.close(); nextId = Id; } DataFramework.getInstance().getDB().beginTransaction(); try { boolean isFirst = true; for (int i = statii.size() - 1; i >= 0; i--) { User u = statii.get(i).getUser(); if (u != null) { ContentValues args = new ContentValues(); args.put(DataFramework.KEY_ID, "" + nextId); args.put("type_id", tweet_type); args.put("user_tt_id", "" + getId()); if (u.getProfileImageURL() != null) { args.put("url_avatar", u.getProfileImageURL().toString()); } else { args.put("url_avatar", ""); } args.put("username", u.getScreenName()); args.put("fullname", u.getName()); args.put("user_id", "" + u.getId()); args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId())); args.put("source", statii.get(i).getSource()); args.put("to_username", statii.get(i).getInReplyToScreenName()); args.put("to_user_id", "" + statii.get(i).getInReplyToUserId()); args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime())); if (statii.get(i).getRetweetedStatus() != null) { args.put("is_retweet", 1); args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser() .getProfileImageURL().toString()); args.put("retweet_username", statii.get(i).getRetweetedStatus().getUser().getScreenName()); args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource()); String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus()); if (t.equals("")) { args.put("text", statii.get(i).getRetweetedStatus().getText()); args.put("text_urls", Utils.getTextURLs(statii.get(i).getRetweetedStatus())); } else { args.put("text", t); } args.put("is_favorite", 0); } else { String t = Utils.getTwitLoger(statii.get(i)); if (t.equals("")) { args.put("text", statii.get(i).getText()); args.put("text_urls", Utils.getTextURLs(statii.get(i))); } else { args.put("text", t); } if (statii.get(i).isFavorited()) { args.put("is_favorite", 1); } } if (statii.get(i).getGeoLocation() != null) { args.put("latitude", statii.get(i).getGeoLocation().getLatitude()); args.put("longitude", statii.get(i).getGeoLocation().getLongitude()); } args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId()); if (breakTimeline && isFirst) args.put("has_more_tweets_down", 1); DataFramework.getInstance().getDB().insert("tweets_user", null, args); out.addId(nextId); nextId++; if (isFirst) isFirst = false; } } // finalizar int total = nResult + statii.size(); if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH || total > Utils.MAX_ROW_BYSEARCH_FORCE) { try { Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total + " registros"); String date = DataFramework.getInstance() .getEntityList("tweets_user", "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc") .get(Utils.MAX_ROW_BYSEARCH).getString("date"); String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type + " and user_tt_id=" + getId() + " AND date < '" + date + "'"; DataFramework.getInstance().getDB().execSQL(sqldelete); } catch (OutOfMemoryError e) { } } DataFramework.getInstance().getDB().setTransactionSuccessful(); } catch (SQLException e) { e.printStackTrace(); } finally { DataFramework.getInstance().getDB().endTransaction(); } } } // guardar directs if (directs != null) { if (directs.size() > 0) { out.setNewMessages(directs.size()); out.setNewerId(directs.get(0).getId()); out.setOlderId(directs.get(directs.size() - 1).getId()); Log.d(Utils.TAG, directs.size() + " mensajes directos a " + getString("name")); long nextId = 1; Cursor c = DataFramework.getInstance().getCursor("tweets_user", new String[] { DataFramework.KEY_ID }, null, null, null, null, DataFramework.KEY_ID + " desc", "1"); if (!c.moveToFirst()) { c.close(); nextId = 1; } else { long Id = c.getInt(0) + 1; c.close(); nextId = Id; } DataFramework.getInstance().getDB().beginTransaction(); try { for (int i = directs.size() - 1; i >= 0; i--) { User u = directs.get(i).getSender(); if (u != null) { ContentValues args = new ContentValues(); args.put(DataFramework.KEY_ID, "" + nextId); args.put("type_id", tweet_type); args.put("user_tt_id", "" + getId()); if (u.getProfileImageURL() != null) { args.put("url_avatar", u.getProfileImageURL().toString()); } else { args.put("url_avatar", ""); } args.put("username", u.getScreenName()); args.put("fullname", u.getName()); args.put("user_id", "" + u.getId()); args.put("tweet_id", Utils.fillZeros("" + directs.get(i).getId())); args.put("source", ""); args.put("to_username", directs.get(i).getRecipientScreenName()); args.put("to_user_id", "" + directs.get(i).getRecipientId()); args.put("date", String.valueOf(directs.get(i).getCreatedAt().getTime())); args.put("text", directs.get(i).getText()); DataFramework.getInstance().getDB().insert("tweets_user", null, args); out.addId(nextId); Log.d(Utils.TAG, "getRecipientScreenName: " + directs.get(i).getRecipientScreenName()); nextId++; } } // finalizar int total = nResult + directs.size(); if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH) { Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total + " registros"); String date = DataFramework.getInstance() .getEntityList("tweets_user", "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc") .get(Utils.MAX_ROW_BYSEARCH).getString("date"); String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type + " and user_tt_id=" + getId() + " AND date < '" + date + "'"; DataFramework.getInstance().getDB().execSQL(sqldelete); } DataFramework.getInstance().getDB().setTransactionSuccessful(); } catch (SQLException e) { e.printStackTrace(); } finally { DataFramework.getInstance().getDB().endTransaction(); } } } } catch (TwitterException e) { e.printStackTrace(); RateLimitStatus rate = e.getRateLimitStatus(); if (rate != null) { out.setError(Utils.LIMIT_ERROR); out.setRate(rate); } else { out.setError(Utils.UNKNOWN_ERROR); } } catch (Exception e) { e.printStackTrace(); out.setError(Utils.UNKNOWN_ERROR); } return out; }
From source file:com.javielinux.infos.InfoTweet.java
License:Apache License
public InfoTweet(User user) { urls = new ArrayList<URLContent>(); mTypeFrom = FROM_USER;/* ww w .ja v a 2s . c om*/ urlAvatar = user.getProfileImageURL().toString(); userId = user.getId(); username = user.getScreenName(); fullname = user.getName(); try { id = user.getStatus().getId(); text = user.getStatus().getText(); source = user.getStatus().getSource(); toUsername = user.getStatus().getInReplyToScreenName(); toUserId = user.getStatus().getInReplyToUserId(); createAt = user.getStatus().getCreatedAt(); toReplyId = user.getStatus().getInReplyToStatusId(); if (user.getStatus().getGeoLocation() != null) { latitude = user.getStatus().getGeoLocation().getLatitude(); longitude = user.getStatus().getGeoLocation().getLongitude(); } } catch (Exception e) { } calculateLinks(); }
From source file:com.javielinux.infos.InfoUsers.java
License:Apache License
public InfoUsers(User user) { setId(user.getId());//from ww w.j a v a 2 s .com setName(user.getScreenName()); setFullname(user.getName()); setCreated(user.getCreatedAt()); setLocation(user.getLocation()); if (user.getURL() != null) setUrl(user.getURL().toString()); setFollowers(user.getFollowersCount()); setFollowing(user.getFriendsCount()); setTweets(user.getStatusesCount()); setBio(user.getDescription()); if (user.getStatus() != null) setTextTweet(user.getStatus().getText()); setUrlAvatar(user.getProfileImageURL().toString()); ArrayList<Entity> ents = DataFramework.getInstance().getEntityList("users", "service is null or service = \"twitter.com\""); for (Entity ent : ents) { friendly.put(ent.getString("name"), new Friend(ent.getString("name"))); } }
From source file:com.javielinux.twitter.ConnectionManager.java
License:Apache License
private void storeAccessToken(Twitter twitter) { try {/*from www .ja v a 2 s .c o m*/ DataFramework.getInstance().open(context, Utils.packageName); } catch (Exception e) { e.printStackTrace(); } String where = KEY_AUTH_KEY + " = '" + accessTokenOAuth.getToken() + "' AND " + KEY_AUTH_SECRET_KEY + " = '" + accessTokenOAuth.getTokenSecret() + "'"; List<Entity> e = DataFramework.getInstance().getEntityList("users", where); if (e.size() == 0) { DataFramework.getInstance().getDB().execSQL("UPDATE users SET active = 0"); Entity ent = new Entity("users"); ent.setValue("service", "twitter.com"); try { ent.setValue("name", twitter.getScreenName()); ent.setValue("fullname", twitter.showUser(twitter.getId()).getName()); ent.setValue("user_id", twitter.getId()); ent.setValue(KEY_AUTH_KEY, accessTokenOAuth.getToken()); ent.setValue(KEY_AUTH_SECRET_KEY, accessTokenOAuth.getTokenSecret()); } catch (IllegalStateException e1) { e1.printStackTrace(); } catch (TwitterException e1) { e1.printStackTrace(); } ent.setValue("active", 1); ent.setValue("last_timeline_id", 0); ent.setValue("last_mention_id", 0); ent.setValue("last_direct_id", 0); ent.save(); loadUsers(); try { User user = twitter.showUser(ent.getInt("user_id")); Bitmap avatar = BitmapFactory.decodeStream( new Utils.FlushedInputStream(new URL(user.getProfileImageURL()).openStream())); if (avatar != null) { String file = ImageUtils.getFileAvatar(ent.getId()); FileOutputStream out = new FileOutputStream(file); avatar.compress(Bitmap.CompressFormat.JPEG, 90, out); avatar.recycle(); } } catch (IllegalStateException ex) { ex.printStackTrace(); } catch (TwitterException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } } DataFramework.getInstance().close(); }
From source file:com.marpies.ane.twitter.utils.UserUtils.java
License:Apache License
public static JSONObject getJSON(User user) throws JSONException { JSONObject userJSON = new JSONObject(); userJSON.put("id", user.getId()); userJSON.put("screenName", user.getScreenName()); userJSON.put("name", user.getName()); userJSON.put("createdAt", user.getCreatedAt()); userJSON.put("description", user.getDescription()); userJSON.put("tweetsCount", user.getStatusesCount()); userJSON.put("likesCount", user.getFavouritesCount()); userJSON.put("followersCount", user.getFollowersCount()); userJSON.put("friendsCount", user.getFriendsCount()); userJSON.put("profileImageURL", user.getProfileImageURL()); userJSON.put("isProtected", user.isProtected()); userJSON.put("isVerified", user.isVerified()); userJSON.put("location", user.getLocation()); return userJSON; }
From source file:com.twitstreet.db.data.Stock.java
License:Open Source License
public Stock(twitter4j.User twUser) { this.setId(twUser.getId()); this.setLongName(twUser.getName()); this.setName(twUser.getScreenName()); this.setTotal(twUser.getFollowersCount()); this.setPictureUrl(twUser.getProfileImageURL().toExternalForm()); this.setSold(0.0D); this.setVerified(twUser.isVerified()); this.setLanguage(twUser.getLang()); this.setCreatedAt(twUser.getCreatedAt()); this.setLocation(twUser.getLocation()); this.setDescription(twUser.getDescription()); }
From source file:com.twitstreet.twitter.SimpleTwitterUser.java
License:Open Source License
public SimpleTwitterUser(User user) { this.id = user.getId(); this.screenName = user.getScreenName(); this.pictureUrl = user.getProfileImageURL().toExternalForm(); this.followerCount = user.getFollowersCount(); this.verified = user.isVerified(); }
From source file:com.twitt4droid.data.dao.impl.sqlite.UserSQLiteDAO.java
License:Apache License
/** {@inheritDoc} */ @Override/*ww w .ja v a2 s .c o m*/ public void save(User user) { getSQLiteTemplate().execute(getSqlString(R.string.twitt4droid_insert_user_sql), new String[] { Objects.toString(user.getId()), user.getName(), user.getScreenName(), user.getProfileImageURL(), user.getProfileBannerURL(), user.getURL(), user.getDescription(), user.getLocation() }); }