List of usage examples for twitter4j Twitter showStatus
Status showStatus(long id) throws TwitterException;
From source file:com.industrialtsi.mylyn.twitter.persistor.TwitterPersistor.java
License:Open Source License
@Override public IndustrialTask fetchTask(TaskRepository repository, String... taskId) throws SQLException, CoreException { Twitter t = getTwitter(repository); long id = Long.parseLong(taskId[0]); try {//from w w w .j a va2 s . c o m twitter4j.Status result = t.showStatus(id); IndustrialTask tweet = new IndustrialTask(repository.getUrl(), taskId[0], result.getText()); tweet.setOwner(result.getUser().getName()); tweet.setCreationDate(result.getCreatedAt()); tweet.setNotes(result.getText()); return tweet; } catch (TwitterException e) { IStatus status = CoreLogger.createStatus(IStatus.ERROR, e); throw new CoreException(status); } }
From source file:com.klinker.android.twitter.activities.tweet_viewer.fragments.ConversationFragment.java
License:Apache License
public void getReplies(final ListView listView, final long tweetId, final LinearLayout progressSpinner, final HoloTextView none) { Thread getReplies = new Thread(new Runnable() { @Override//from w w w . j a v a 2 s. c o m public void run() { if (!isRunning) { return; } Twitter twitter = Utils.getTwitter(context, settings); replies = new ArrayList<twitter4j.Status>(); try { status = twitter.showStatus(tweetId); if (status.isRetweet()) { status = status.getRetweetedStatus(); } twitter4j.Status replyStatus = twitter.showStatus(status.getInReplyToStatusId()); try { while (!replyStatus.getText().equals("")) { if (!isRunning) { return; } replies.add(replyStatus); Log.v("reply_status", replyStatus.getText()); replyStatus = twitter.showStatus(replyStatus.getInReplyToStatusId()); } } catch (Exception e) { // the list of replies has ended, but we dont want to go to null } } catch (TwitterException e) { e.printStackTrace(); } if (status != null && replies.size() > 0) { replies.add(0, status); } ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { try { if (replies.size() > 0) { ArrayList<twitter4j.Status> reversed = new ArrayList<twitter4j.Status>(); for (int i = replies.size() - 1; i >= 0; i--) { reversed.add(replies.get(i)); } replies = reversed; adapter = new TimelineArrayAdapter(context, replies); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); progressSpinner.setVisibility(View.GONE); } else { } } catch (Exception e) { // none and it got the null object } if (status != null) { // everything here worked, so get the discussion on the tweet getDiscussion(listView, tweetId, progressSpinner, none, status); } } }); } }); getReplies.setPriority(7); getReplies.start(); }
From source file:com.klinker.android.twitter.activities.tweet_viewer.fragments.TweetFragment.java
License:Apache License
public void getInfo(final View favButton, final TextView favCount, final TextView retweetCount, final long tweetId, final View retweetButton) { Thread getInfo = new Thread(new Runnable() { @Override//from w ww .ja v a 2 s. c om public void run() { String location = ""; String via = ""; long realTime = 0; boolean retweetedByMe = false; try { Twitter twitter = getTwitter(); TwitterMultipleImageHelper helper = new TwitterMultipleImageHelper(); status = twitter.showStatus(tweetId); ArrayList<String> i = new ArrayList<String>(); if (picture) { i = helper.getImageURLs(status, twitter); } final ArrayList<String> images = i; GeoLocation loc = status.getGeoLocation(); try { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); if (addresses.size() > 0) { Address address = addresses.get(0); location += address.getLocality() + ", " + address.getCountryName(); } else { location = ""; } } catch (Exception x) { location = ""; } via = android.text.Html.fromHtml(status.getSource()).toString(); final String sfavCount; if (status.isRetweet()) { twitter4j.Status status2 = status.getRetweetedStatus(); via = android.text.Html.fromHtml(status2.getSource()).toString(); realTime = status2.getCreatedAt().getTime(); sfavCount = status2.getFavoriteCount() + ""; } else { realTime = status.getCreatedAt().getTime(); sfavCount = status.getFavoriteCount() + ""; } retweetedByMe = status.isRetweetedByMe(); final String retCount = "" + status.getRetweetCount(); final String timeDisplay; if (!settings.militaryTime) { timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(realTime); } else { timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(realTime); } final String fVia = " " + getResources().getString(R.string.via) + " " + via; final String fLoc = location.equals("") ? "" : "\n" + location; final boolean fRet = retweetedByMe; final long fTime = realTime; final Status fStatus = status; ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { retweetCount.setText(" " + retCount); if (retweetButton instanceof ImageButton) { if (fRet) { if (!settings.addonTheme) { ((ImageButton) retweetButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) retweetButton).setColorFilter(settings.accentInt); } } else { ((ImageButton) retweetButton).clearColorFilter(); } } else { if (fRet) { if (!settings.addonTheme) { retweetButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { retweetButton.setBackgroundColor(settings.accentInt); } } else { retweetButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } timetv.setText(timeDisplay + fVia); timetv.append(fLoc); favCount.setText(" " + sfavCount); if (favButton instanceof ImageButton) { if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { ((ImageButton) favButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) favButton).setColorFilter(settings.accentInt); } ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = false; ((ImageButton) favButton).clearColorFilter(); } } else { if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { favButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { favButton.setBackgroundColor(settings.accentInt); } isFavorited = true; } else { isFavorited = false; favButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } for (String s : images) { Log.v("talon_image", s); } if (images.size() > 1) { Log.v("talon_images", "size: " + images.size()); try { mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { @Override public void onViewTap(View view, float x, float y) { Intent viewPics = new Intent(context, ViewPictures.class); viewPics.putExtra("images", images); startActivity(viewPics); } }); } catch (Exception e) { // addon theme without the attacher profilePic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent viewPics = new Intent(context, ViewPictures.class); viewPics.putExtra("images", images); startActivity(viewPics); } }); } } } }); } catch (Exception e) { } } }); getInfo.setPriority(Thread.MAX_PRIORITY); getInfo.start(); }
From source file:com.klinker.android.twitter.adapters.TimeLineCursorAdapter.java
License:Apache License
public void getCounts(final ViewHolder holder, final long tweetId) { Thread getCount = new Thread(new Runnable() { @Override//from w w w. j a v a 2 s.c o m public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); final Status status; if (holder.retweeter.getVisibility() != View.GONE) { status = twitter.showStatus(holder.tweetId).getRetweetedStatus(); } else { status = twitter.showStatus(tweetId); } if (status != null && holder.tweetId == tweetId) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { holder.favCount.setText(" " + status.getFavoriteCount()); holder.retweetCount.setText(" " + status.getRetweetCount()); if (status.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { holder.favorite .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { holder.favorite.setColorFilter(settings.accentInt); } holder.favorite.setImageDrawable(context.getResources().getDrawable(resource)); holder.isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); holder.favorite.setImageDrawable(context.getResources().getDrawable(resource)); holder.isFavorited = false; holder.favorite.clearColorFilter(); } if (status.isRetweetedByMe()) { if (!settings.addonTheme) { holder.retweet .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { holder.retweet.setColorFilter(settings.accentInt); } } else { holder.retweet.clearColorFilter(); } } }); } } catch (Exception e) { } } }); getCount.setPriority(7); getCount.start(); }
From source file:com.klinker.android.twitter.ui.tweet_viewer.fragments.TweetFragment.java
License:Apache License
public void getFavoriteCount(final TextView favs, final View favButton, final long tweetId) { new Thread(new Runnable() { @Override//from w ww .ja v a 2 s .c o m public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); twitter4j.Status status = twitter.showStatus(tweetId); if (status.isRetweet()) { twitter4j.Status retweeted = status.getRetweetedStatus(); status = retweeted; } final twitter4j.Status fStatus = status; ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { favs.setText(" " + fStatus.getFavoriteCount()); if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (favButton instanceof ImageButton) { if (!settings.addonTheme) { ((ImageButton) favButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) favButton).setColorFilter(settings.accentInt); } ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); } else if (favButton instanceof LinearLayout) { if (!settings.addonTheme) { favButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { favButton.setBackgroundColor(settings.accentInt); } } isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (favButton instanceof ImageButton) { ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = false; ((ImageButton) favButton).clearColorFilter(); } else { favButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } } }); } catch (Exception e) { } } }).start(); }
From source file:com.klinker.android.twitter.ui.tweet_viewer.fragments.TweetFragment.java
License:Apache License
public void getInfo(final View favButton, final TextView favCount, final TextView retweetCount, final long tweetId, final View retweetButton) { Thread getInfo = new Thread(new Runnable() { @Override//from w ww .j a va 2 s . c o m public void run() { String location = ""; String via = ""; long realTime = 0; boolean retweetedByMe = false; try { Twitter twitter = Utils.getTwitter(context, settings); TwitterMultipleImageHelper helper = new TwitterMultipleImageHelper(); status = twitter.showStatus(tweetId); ArrayList<String> i = new ArrayList<String>(); if (picture) { i = helper.getImageURLs(status, twitter); } final ArrayList<String> images = i; GeoLocation loc = status.getGeoLocation(); try { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); if (addresses.size() > 0) { Address address = addresses.get(0); location += address.getLocality() + ", " + address.getCountryName(); } else { location = ""; } } catch (Exception x) { location = ""; } via = android.text.Html.fromHtml(status.getSource()).toString(); final String sfavCount; if (status.isRetweet()) { twitter4j.Status status2 = status.getRetweetedStatus(); via = android.text.Html.fromHtml(status2.getSource()).toString(); realTime = status2.getCreatedAt().getTime(); sfavCount = status2.getFavoriteCount() + ""; } else { realTime = status.getCreatedAt().getTime(); sfavCount = status.getFavoriteCount() + ""; } retweetedByMe = status.isRetweetedByMe(); final String retCount = "" + status.getRetweetCount(); final String timeDisplay; if (!settings.militaryTime) { timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(realTime); } else { timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(realTime); } final String fVia = " " + getResources().getString(R.string.via) + " " + via; final String fLoc = location.equals("") ? "" : "\n" + location; final boolean fRet = retweetedByMe; final long fTime = realTime; final Status fStatus = status; ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { // you can't retweet a protected account if (status.getUser().isProtected()) { retweetButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, getString(R.string.protected_account), Toast.LENGTH_SHORT).show(); } }); } retweetCount.setText(" " + retCount); if (retweetButton instanceof ImageButton) { if (fRet) { if (!settings.addonTheme) { ((ImageButton) retweetButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) retweetButton).setColorFilter(settings.accentInt); } } else { ((ImageButton) retweetButton).clearColorFilter(); } } else { if (fRet) { if (!settings.addonTheme) { retweetButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { retweetButton.setBackgroundColor(settings.accentInt); } } else { retweetButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } timetv.setText(timeDisplay + fVia); timetv.append(fLoc); favCount.setText(" " + sfavCount); if (favButton instanceof ImageButton) { if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { ((ImageButton) favButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) favButton).setColorFilter(settings.accentInt); } ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = false; ((ImageButton) favButton).clearColorFilter(); } } else { if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { favButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { favButton.setBackgroundColor(settings.accentInt); } isFavorited = true; } else { isFavorited = false; favButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } for (String s : images) { Log.v("talon_image", s); } if (images.size() > 1) { Log.v("talon_images", "size: " + images.size()); try { mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { @Override public void onViewTap(View view, float x, float y) { Intent viewPics = new Intent(context, ViewPictures.class); viewPics.putExtra("images", images); startActivity(viewPics); } }); } catch (Exception e) { // addon theme without the attacher profilePic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent viewPics = new Intent(context, ViewPictures.class); viewPics.putExtra("images", images); startActivity(viewPics); } }); } } } }); } catch (Exception e) { } } }); getInfo.setPriority(Thread.MAX_PRIORITY); getInfo.start(); }
From source file:com.klinker.android.twitter.ui.tweet_viewer.fragments.TweetFragment.java
License:Apache License
public void getRetweetCount(final TextView retweetCount, final long tweetId, final View retweetButton) { new Thread(new Runnable() { @Override//from ww w .ja v a 2 s . c o m public void run() { boolean retweetedByMe; try { Twitter twitter = Utils.getTwitter(context, settings); twitter4j.Status status = twitter.showStatus(tweetId); retweetedByMe = status.isRetweetedByMe(); final String retCount = "" + status.getRetweetCount(); final boolean fRet = retweetedByMe; ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { try { retweetCount.setText(" " + retCount); if (retweetButton instanceof ImageButton) { if (fRet) { if (!settings.addonTheme) { ((ImageButton) retweetButton).setColorFilter( context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) retweetButton).setColorFilter(settings.accentInt); } } else { ((ImageButton) retweetButton).clearColorFilter(); } } else { if (fRet) { if (!settings.addonTheme) { retweetButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { retweetButton.setBackgroundColor(settings.accentInt); } } else { retweetButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } } catch (Exception x) { // not attached to activity } } }); } catch (Exception e) { } } }).start(); }
From source file:com.klinker.android.twitter.ui.tweet_viewer.ViewRetweeters.java
License:Apache License
public void onRefreshStarted() { new Thread(new Runnable() { @Override//from w ww . java 2s . c om public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); Status stat = twitter.showStatus(tweetId); if (stat.isRetweet()) { tweetId = stat.getRetweetedStatus().getId(); } // can get 100 retweeters is all ResponseList<twitter4j.Status> lists = twitter.getRetweets(tweetId); users.clear(); for (Status status : lists) { users.add(status.getUser()); } ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { adapter = new PeopleArrayAdapter(context, users); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); if (users.size() == 0) { noContent.setVisibility(View.VISIBLE); } mPullToRefreshLayout.setRefreshing(false); } }); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } } }).start(); }
From source file:com.left8.evs.utilities.dsretriever.TweetsRetriever.java
License:Open Source License
/** * Method to retrieve and store historical tweets by collecting them with * their ID./*from w ww . ja va 2s .c o m*/ * @param tweetIDs The IDs of the tweets that are going to be collected. * @param mongoDB A MongoHandler object. * @param config A configuration object. * @param event The ground truth event for which the tweets that are going * to be collected, are referring to. */ public final void retrieveTweetsById(List<String> tweetIDs, MongoHandler mongoDB, Config config, String event) { ConfigurationBuilder cb = getAuthorization(); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); tweetIDs.stream().forEach((item) -> { try { //Get tweet and all its metadata and store it Status status = twitter.showStatus(Long.parseLong(item)); mongoDB.insertSingleTweetIntoMongoDB(status, event); } catch (TwitterException e) { Utilities.printMessageln("Failed to retrieve tweet with ID: " + item); Logger.getLogger(TweetsRetriever.class.getName()).log(Level.SEVERE, null, e); } }); }
From source file:com.oldterns.vilebot.handlers.user.UrlTweetAnnouncer.java
License:Open Source License
/** * Accesses the source of a HTML page and looks for a title element * /*from ww w . ja v a 2 s . c o m*/ * @param url http tweet String * @return String of text which represents the tweet. Empty if error. */ private String scrapeURLHTMLTitle(String url) { String text = ""; URL page; try { page = new URL(url); } catch (MalformedURLException x) { // System.err.format("scrapeURLHTMLTitle new URL error: %s%n", x); return text; } //split the url into pieces, change the request based on what we have String parts[] = url.split("/"); int userPosition = 0; long tweetID = 0; for (int i = 0; i < parts.length; i++) { if (parts[i].toString().equals("twitter.com")) userPosition = i + 1; if (parts[i].toString().equals("status") || parts[i].toString().equals("statuses")) tweetID = Long.valueOf(parts[i + 1].toString()).longValue(); } if (userPosition == 0) return text; else { try { String consumerKey = ""; //may be known as 'API key' String consumerSecret = ""; //may be known as 'API secret' String accessToken = ""; //may be known as 'Access token' String accessTokenSecret = ""; //may be known as 'Access token secret' ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); if (tweetID != 0) //tweet of the twitter.com/USERID/status/TWEETID variety { Status status = twitter.showStatus(tweetID); return (status.getUser().getName() + ": " + status.getText()); } else //just the user is given, ie, twitter.com/USERID { User user = twitter.showUser(parts[userPosition].toString()); if (!user.getDescription().isEmpty()) //the user has a description return ("Name: " + user.getName() + " | " + user.getDescription() + "\'\nLast Tweet: \'" + user.getStatus().getText()); else //the user doesn't have a description, don't print it return ("Name: " + user.getName() + "\'\nLast Tweet: \'" + user.getStatus().getText()); } } catch (TwitterException x) { return text; } } }