List of usage examples for twitter4j URLEntity getExpandedURL
String getExpandedURL();
From source file:com.klinker.android.twitter.utils.TweetLinkUtils.java
License:Apache License
public static String[] getLinksInStatus(Status status) { UserMentionEntity[] users = status.getUserMentionEntities(); String mUsers = ""; for (UserMentionEntity name : users) { String n = name.getScreenName(); if (n.length() > 1) { mUsers += n + " "; }// www . ja v a 2s . c o m } HashtagEntity[] hashtags = status.getHashtagEntities(); String mHashtags = ""; for (HashtagEntity hashtagEntity : hashtags) { String text = hashtagEntity.getText(); if (text.length() > 1) { mHashtags += text + " "; } } URLEntity[] urls = status.getURLEntities(); String expandedUrls = ""; String compressedUrls = ""; for (URLEntity entity : urls) { String url = entity.getExpandedURL(); if (url.length() > 1) { expandedUrls += url + " "; compressedUrls += entity.getURL() + " "; } } MediaEntity[] medias = status.getMediaEntities(); String mediaExp = ""; String mediaComp = ""; String mediaDisplay = ""; for (MediaEntity e : medias) { String url = e.getURL(); if (url.length() > 1) { mediaComp += url + " "; mediaExp += e.getExpandedURL() + " "; mediaDisplay += e.getDisplayURL() + " "; } } String[] sExpandedUrls; String[] sCompressedUrls; String[] sMediaExp; String[] sMediaComp; String[] sMediaDisplay; try { sCompressedUrls = compressedUrls.split(" "); } catch (Exception e) { sCompressedUrls = new String[0]; } try { sExpandedUrls = expandedUrls.split(" "); } catch (Exception e) { sExpandedUrls = new String[0]; } try { sMediaComp = mediaComp.split(" "); } catch (Exception e) { sMediaComp = new String[0]; } try { sMediaExp = mediaExp.split(" "); } catch (Exception e) { sMediaExp = new String[0]; } try { sMediaDisplay = mediaDisplay.split(" "); } catch (Exception e) { sMediaDisplay = new String[0]; } String tweetTexts = status.getText(); String imageUrl = ""; String otherUrl = ""; for (int i = 0; i < sCompressedUrls.length; i++) { String comp = sCompressedUrls[i]; String exp = sExpandedUrls[i]; if (comp.length() > 1 && exp.length() > 1) { String str = exp.toLowerCase(); try { tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", "").substring(0, 30) + "..."); } catch (Exception e) { tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", "")); } if (str.contains("instag") && !str.contains("blog.insta")) { imageUrl = exp + "media/?size=m"; otherUrl += exp + " "; } else if (exp.toLowerCase().contains("youtub") && !(str.contains("channel") || str.contains("user"))) { // first get the youtube video code int start = exp.indexOf("v=") + 2; int end = exp.length(); if (exp.substring(start).contains("&")) { end = exp.indexOf("&"); } else if (exp.substring(start).contains("?")) { end = exp.indexOf("?"); } try { imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg"; } catch (Exception e) { imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1) + "/hqdefault.jpg"; } otherUrl += exp + " "; } else if (str.contains("youtu.be")) { // first get the youtube video code int start = exp.indexOf(".be/") + 4; int end = exp.length(); if (exp.substring(start).contains("&")) { end = exp.indexOf("&"); } else if (exp.substring(start).contains("?")) { end = exp.indexOf("?"); } try { imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg"; } catch (Exception e) { imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1) + "/mqefault.jpg"; } otherUrl += exp + " "; } else if (str.contains("twitpic")) { int start = exp.indexOf(".com/") + 5; imageUrl = "http://twitpic.com/show/full/" + exp.substring(start).replace("/", ""); otherUrl += exp + " "; } else if (str.contains("i.imgur") && !str.contains("/a/")) { int start = exp.indexOf(".com/") + 5; imageUrl = "http://i.imgur.com/" + exp.replace("http://i.imgur.com/", "").replace(".jpg", "") + "m.jpg"; imageUrl = imageUrl.replace("gallery/", ""); otherUrl += exp + " "; } else if (str.contains("imgur") && !str.contains("/a/")) { int start = exp.indexOf(".com/") + 6; imageUrl = "http://i.imgur.com/" + exp.replace("http://imgur.com/", "").replace(".jpg", "") + "m.jpg"; imageUrl = imageUrl.replace("gallery/", "").replace("a/", ""); otherUrl += exp + " "; } else if (str.contains("pbs.twimg.com")) { imageUrl = exp; otherUrl += exp + " "; } else if (str.contains("ow.ly/i")) { imageUrl = "http://static.ow.ly/photos/original/" + exp.substring(exp.lastIndexOf("/")).replaceAll("/", "") + ".jpg"; otherUrl += exp + " "; } else if (str.contains("p.twipple.jp")) { imageUrl = "http://p.twipple.jp/show/large/" + exp.replace("p.twipple.jp/", "") .replace("http://", "").replace("https://", "").replace("www.", ""); otherUrl += exp + " "; } else if (str.contains(".jpg") || str.contains(".png")) { imageUrl = exp; otherUrl += exp + " "; } else { otherUrl += exp + " "; } } } for (int i = 0; i < sMediaComp.length; i++) { String comp = sMediaComp[i]; String exp = sMediaExp[i]; if (comp.length() > 1 && exp.length() > 1) { try { tweetTexts = tweetTexts.replace(comp, sMediaDisplay[i].replace("http://", "") .replace("https://", "").replace("www.", "").substring(0, 22) + "..."); } catch (Exception e) { tweetTexts = tweetTexts.replace(comp, sMediaDisplay[i].replace("http://", "").replace("https://", "").replace("www.", "")); } imageUrl = status.getMediaEntities()[0].getMediaURL(); for (MediaEntity m : status.getExtendedMediaEntities()) { if (m.getType().equals("photo")) { if (!imageUrl.contains(m.getMediaURL())) { imageUrl += " " + m.getMediaURL(); } } } otherUrl += sMediaDisplay[i]; } } return new String[] { tweetTexts, imageUrl, otherUrl, mHashtags, mUsers }; }
From source file:com.klinker.android.twitter.utils.TweetLinkUtils.java
License:Apache License
public static String[] getLinksInStatus(DirectMessage status) { UserMentionEntity[] users = status.getUserMentionEntities(); String mUsers = ""; for (UserMentionEntity name : users) { String n = name.getScreenName(); if (n.length() > 1) { mUsers += n + " "; }//w w w . j a v a2 s .c om } HashtagEntity[] hashtags = status.getHashtagEntities(); String mHashtags = ""; for (HashtagEntity hashtagEntity : hashtags) { String text = hashtagEntity.getText(); if (text.length() > 1) { mHashtags += text + " "; } } URLEntity[] urls = status.getURLEntities(); String expandedUrls = ""; String compressedUrls = ""; for (URLEntity entity : urls) { String url = entity.getExpandedURL(); if (url.length() > 1) { expandedUrls += url + " "; compressedUrls += entity.getURL() + " "; } } MediaEntity[] medias = status.getMediaEntities(); String mediaExp = ""; String mediaComp = ""; String mediaDisplay = ""; for (MediaEntity e : medias) { String url = e.getURL(); if (url.length() > 1) { mediaComp += url + " "; mediaExp += e.getExpandedURL() + " "; mediaDisplay += e.getDisplayURL() + " "; } } String[] sExpandedUrls; String[] sCompressedUrls; String[] sMediaExp; String[] sMediaComp; String[] sMediaDisply; try { sCompressedUrls = compressedUrls.split(" "); } catch (Exception e) { sCompressedUrls = new String[0]; } try { sExpandedUrls = expandedUrls.split(" "); } catch (Exception e) { sExpandedUrls = new String[0]; } try { sMediaComp = mediaComp.split(" "); } catch (Exception e) { sMediaComp = new String[0]; } try { sMediaExp = mediaExp.split(" "); } catch (Exception e) { sMediaExp = new String[0]; } try { sMediaDisply = mediaDisplay.split(" "); } catch (Exception e) { sMediaDisply = new String[0]; } String tweetTexts = status.getText(); String imageUrl = ""; String otherUrl = ""; for (int i = 0; i < sCompressedUrls.length; i++) { String comp = sCompressedUrls[i]; String exp = sExpandedUrls[i]; if (comp.length() > 1 && exp.length() > 1) { String str = exp.toLowerCase(); tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", "")); if (str.contains("instag") && !str.contains("blog.instag")) { imageUrl = exp + "media/?size=m"; otherUrl += exp + " "; } else if (str.contains("youtub") && !(str.contains("channel") || str.contains("user"))) { // normal youtube link // first get the youtube video code int start = exp.indexOf("v=") + 2; int end = exp.length(); if (exp.substring(start).contains("&")) { end = exp.indexOf("&"); } else if (exp.substring(start).contains("?")) { end = exp.indexOf("?"); } imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg"; otherUrl += exp + " "; } else if (str.contains("youtu.be")) { // shortened youtube link // first get the youtube video code int start = exp.indexOf(".be/") + 4; int end = exp.length(); if (exp.substring(start).contains("&")) { end = exp.indexOf("&"); } else if (exp.substring(start).contains("?")) { end = exp.indexOf("?"); } imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg"; otherUrl += exp + " "; } else if (str.contains("twitpic")) { int start = exp.indexOf(".com/") + 5; imageUrl = "http://twitpic.com/show/full/" + exp.substring(start).replace("/", ""); otherUrl += exp + " "; } else if (str.contains("imgur") && !str.contains("/a/")) { int start = exp.indexOf(".com/") + 6; imageUrl = "http://i.imgur.com/" + exp.substring(start) + "m.jpg"; imageUrl = imageUrl.replace("gallery/", "").replace("a/", ""); otherUrl += exp + " "; } else if (str.contains("pbs.twimg.com")) { imageUrl = exp; otherUrl += exp + " "; } else if (str.contains("ow.ly/i")) { Log.v("talon_owly", exp); imageUrl = "http://static.ow.ly/photos/original/" + exp.substring(exp.lastIndexOf("/")).replaceAll("/", "") + ".jpg"; otherUrl += exp + " "; } else if (str.contains(".jpg") || str.contains(".png")) { imageUrl = exp; otherUrl += exp + " "; } else { otherUrl += exp + " "; } } } for (int i = 0; i < sMediaComp.length; i++) { String comp = sMediaComp[i]; String exp = sMediaExp[i]; if (comp.length() > 1 && exp.length() > 1) { tweetTexts = tweetTexts.replace(comp, sMediaDisply[i]); /*try { tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", "").substring(0, 30) + "..."); } catch (Exception e) { tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", "")); }*/ imageUrl = status.getMediaEntities()[0].getMediaURL(); otherUrl += sMediaDisply[i]; } } return new String[] { tweetTexts, imageUrl, otherUrl, mHashtags, mUsers }; }
From source file:com.klinker.android.twitter.utils.TweetLinkUtils.java
License:Apache License
public static ArrayList<String> getAllExternalPictures(Status status) { URLEntity[] urls = status.getURLEntities(); String expandedUrls = ""; String compressedUrls = ""; for (URLEntity entity : urls) { String url = entity.getExpandedURL(); if (url.length() > 1) { expandedUrls += url + " "; compressedUrls += entity.getURL() + " "; }/*from w w w .j av a 2 s.co m*/ } MediaEntity[] medias = status.getMediaEntities(); String mediaExp = ""; String mediaComp = ""; for (MediaEntity e : medias) { String url = e.getURL(); if (url.length() > 1) { mediaComp += url + " "; mediaExp += e.getExpandedURL() + " "; } } String[] sExpandedUrls; String[] sCompressedUrls; String[] sMediaExp; String[] sMediaComp; try { sCompressedUrls = compressedUrls.split(" "); } catch (Exception e) { sCompressedUrls = new String[0]; } try { sExpandedUrls = expandedUrls.split(" "); } catch (Exception e) { sExpandedUrls = new String[0]; } try { sMediaComp = mediaComp.split(" "); } catch (Exception e) { sMediaComp = new String[0]; } try { sMediaExp = mediaExp.split(" "); } catch (Exception e) { sMediaExp = new String[0]; } ArrayList<String> images = new ArrayList<String>(); for (int i = 0; i < sCompressedUrls.length; i++) { String comp = sCompressedUrls[i]; String exp = sExpandedUrls[i]; if (comp.length() > 1 && exp.length() > 1) { String str = exp.toLowerCase(); if (str.contains("instag") && !str.contains("blog.insta")) { images.add(exp + "media/?size=m"); } else if (exp.toLowerCase().contains("youtub") && !(str.contains("channel") || str.contains("user"))) { // first get the youtube video code int start = exp.indexOf("v=") + 2; int end = exp.length(); if (exp.substring(start).contains("&")) { end = exp.indexOf("&"); } else if (exp.substring(start).contains("?")) { end = exp.indexOf("?"); } try { images.add("http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg"); } catch (Exception e) { images.add("http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1) + "/hqdefault.jpg"); } } else if (str.contains("youtu.be")) { // first get the youtube video code int start = exp.indexOf(".be/") + 4; int end = exp.length(); if (exp.substring(start).contains("&")) { end = exp.indexOf("&"); } else if (exp.substring(start).contains("?")) { end = exp.indexOf("?"); } try { images.add("http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg"); } catch (Exception e) { images.add("http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1) + "/mqefault.jpg"); } } else if (str.contains("twitpic")) { int start = exp.indexOf(".com/") + 5; images.add("http://twitpic.com/show/full/" + exp.substring(start).replace("/", "")); } else if (str.contains("i.imgur") && !str.contains("/a/")) { images.add(("http://i.imgur.com/" + exp.replace("http://i.imgur.com/", "").replace(".jpg", "") + "m.jpg").replace("gallery/", "")); } else if (str.contains("imgur") && !str.contains("/a/")) { images.add(("http://i.imgur.com/" + exp.replace("http://imgur.com/", "").replace(".jpg", "") + "m.jpg").replace("gallery/", "").replace("a/", "")); } else if (str.contains("pbs.twimg.com")) { images.add(exp); } else if (str.contains("ow.ly/i")) { images.add("http://static.ow.ly/photos/original/" + exp.substring(exp.lastIndexOf("/")).replaceAll("/", "") + ".jpg"); } else if (str.contains("p.twipple.jp")) { images.add("http://p.twipple.jp/show/large/" + exp.replace("p.twipple.jp/", "") .replace("http://", "").replace("https://", "").replace("www.", "")); } else if (str.contains(".jpg") || str.contains(".png")) { images.add(exp); } } } for (int i = 0; i < sMediaComp.length; i++) { String comp = sMediaComp[i]; String exp = sMediaExp[i]; if (comp.length() > 1 && exp.length() > 1) { images.add(status.getMediaEntities()[0].getMediaURL()); } } return images; }
From source file:com.mothsoft.alexis.engine.retrieval.TwitterRetrievalTaskImpl.java
License:Apache License
private List<TweetLink> readLinks(Status status) { final List<TweetLink> links = new ArrayList<TweetLink>(); if (status.getURLEntities() != null) { for (final URLEntity entity : status.getURLEntities()) { final String displayUrl = entity.getDisplayURL(); final String expandedUrl = entity.getExpandedURL(); final String url = entity.getURL(); final TweetLink link = new TweetLink((short) entity.getStart(), (short) entity.getEnd(), displayUrl, expandedUrl, url);//from w w w . j a v a2 s . c om links.add(link); } } return links; }
From source file:com.mycompany.omnomtweets.Search.java
public static boolean writeToStdErr(Status tweet) { //System.out.println("Writing " + tweets.size() + " tweets"); boolean success = true; if (tweet != null) { String tweetText;//w w w . ja v a 2 s. co m String idOfRetweetee = ""; if (tweet.getRetweetedStatus() != null) { tweetText = "RT " + tweet.getRetweetedStatus().getText(); idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName(); //System.out.println("retweeted" + tweetText); } else { tweetText = tweet.getText(); } String urlText = ""; if (tweet.getURLEntities().length > 0) { for (URLEntity url : tweet.getURLEntities()) { if (url.getExpandedURL() != null) { urlText += url.getExpandedURL() + " "; tweetText = tweetText.replace(url.getURL(), url.getExpandedURL()); //System.out.println("Expanded URL " + url.getExpandedURL()); } else { urlText += url.getURL() + " "; //System.out.println("URL " + url.getURL()); } } } if (tweet.getMediaEntities().length > 0) { for (MediaEntity media : tweet.getMediaEntities()) { if (media.getExpandedURL() != null) { urlText += media.getExpandedURL() + " "; tweetText = tweetText.replace(media.getMediaURL(), media.getExpandedURL()); //System.out.println("Expanded URL " + media.getExpandedURL()); } else { urlText += media.getMediaURL() + " "; //System.out.println("URL " + media.getMediaURL()); } } } String encodedText = tweetText.replaceAll("\"", "\"\""); encodedText = encodedText.replaceAll("\\s", " "); String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + "," + tweet.getId() + "," + candidate.name + "," + sdf.format(tweet.getCreatedAt()) + "," + idOfRetweetee + "\n"; System.err.print(writeMe); //writeTweets.write(writeMe); } return success; }
From source file:com.mycompany.omnomtweets.Search.java
/** * Method to write the tweets to file, base 64 encoded tweet text. * @param tweets the tweets to be written * @param filename the file to write the tweets into * @return true unless something bad happens *///from w w w .ja va2s . c o m public static boolean writeTweetsToFile(List<Status> tweets, String filename) { //System.out.println("Writing " + tweets.size() + " tweets"); boolean success = true; try { FileWriter addTweets = new FileWriter(new File(filename), true); if (tweets != null && tweets.size() > 0) { for (Status tweet : tweets) { String tweetText; String idOfRetweetee = ""; if (tweet.getRetweetedStatus() != null) { tweetText = "RT " + tweet.getRetweetedStatus().getText(); idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName(); //System.out.println("retweeted" + tweetText); } else { tweetText = tweet.getText(); } String urlText = ""; if (tweet.getURLEntities().length > 0) { for (URLEntity url : tweet.getURLEntities()) { if (url.getExpandedURL() != null) { urlText += url.getExpandedURL() + " "; tweetText = tweetText.replace(url.getURL(), url.getExpandedURL()); //System.out.println("Expanded URL " + url.getExpandedURL()); } else { urlText += url.getURL() + " "; //System.out.println("URL " + url.getURL()); } } } if (tweet.getMediaEntities().length > 0) { for (MediaEntity media : tweet.getMediaEntities()) { if (media.getExpandedURL() != null) { urlText += media.getExpandedURL() + " "; tweetText = tweetText.replace(media.getMediaURL(), media.getExpandedURL()); //System.out.println("Expanded URL " + media.getExpandedURL()); } else { urlText += media.getMediaURL() + " "; //System.out.println("URL " + media.getMediaURL()); } } } String encodedText = tweetText.replaceAll("\"", "\"\""); encodedText = encodedText.replaceAll("\n", " "); String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + "," + tweet.getId() + "," + candidate.name + "," + tweet.getCreatedAt() + "," + idOfRetweetee + "\n"; //System.out.println(writeMe); addTweets.write(writeMe); } } addTweets.close(); } catch (IOException ex) { //System.out.println("Something broke lol"); success = false; } return success; }
From source file:com.mycompany.omnomtweets.TweetsAboutCandidates.java
/** * Method to write the tweets to file, base 64 encoded tweet text. * @param tweets the tweets to be written * @param filename the file to write the tweets into * @return true unless something bad happens */// w w w. j a va 2s .c o m public boolean writeTweetsToFile(List<Status> tweets, String filename) { //System.out.println("Writing " + tweets.size() + " tweets"); boolean success = true; try { FileWriter addTweets = new FileWriter(new File(filename), true); if (tweets != null && tweets.size() > 0) { for (Status tweet : tweets) { String tweetText; String idOfRetweetee = ""; if (tweet.getRetweetedStatus() != null) { tweetText = "RT " + tweet.getRetweetedStatus().getText(); idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName(); //System.out.println("retweeted" + tweetText); } else { tweetText = tweet.getText(); } String urlText = ""; if (tweet.getURLEntities().length > 0) { for (URLEntity url : tweet.getURLEntities()) { if (url.getExpandedURL() != null) { urlText += url.getExpandedURL() + " "; //System.out.println("Expanded URL " + url.getExpandedURL()); } else { urlText += url.getURL() + " "; //System.out.println("URL " + url.getURL()); } } } if (tweet.getMediaEntities().length > 0) { for (MediaEntity media : tweet.getMediaEntities()) { if (media.getExpandedURL() != null) { urlText += media.getExpandedURL() + " "; //System.out.println("Expanded URL " + media.getExpandedURL()); } else { urlText += media.getMediaURL() + " "; //System.out.println("URL " + media.getMediaURL()); } } } String encodedText = tweet.getText().replaceAll("\"", "\"\""); String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + "," + tweet.getId() + "," + candidate.name + "," + tweet.getCreatedAt() + "," + idOfRetweetee + "\n"; //System.out.println(writeMe); addTweets.write(writeMe); } } addTweets.close(); } catch (IOException ex) { System.out.println("Something broke lol"); success = false; } return success; }
From source file:com.ocpsoft.hatchling.twitter.PersistentStatusListener.java
License:Open Source License
@Override public void onStatus(final Status status) { Tweet t = new Tweet(); t.setReceived(status.getCreatedAt()); t.setText(status.getText());/*from www .jav a 2s. co m*/ t.setScreenName(status.getUser().getScreenName()); t.setUserName(status.getUser().getName()); t.setUserProfileImageURL(status.getUser().getProfileImageURL()); t.setProfileURL(null); t.setTweetId(status.getId()); URLEntity[] urlEntities = status.getURLEntities(); if (urlEntities != null) { for (URLEntity url : urlEntities) { TweetURL tweetURL = new TweetURL(); if (url.getExpandedURL() != null) { tweetURL.setURL(url.getExpandedURL()); } else if (url.getURL() != null) { tweetURL.setURL(url.getURL()); } t.getURLs().add(tweetURL); } } buffer.add(t); }
From source file:de.vanita5.twittnuker.model.ParcelableMedia.java
License:Open Source License
public static ParcelableMedia[] fromEntities(final EntitySupport entities) { final List<ParcelableMedia> list = new ArrayList<>(); final MediaEntity[] mediaEntities; if (entities instanceof ExtendedEntitySupport) { final ExtendedEntitySupport extendedEntities = (ExtendedEntitySupport) entities; final MediaEntity[] extendedMedias = extendedEntities.getExtendedMediaEntities(); mediaEntities = extendedMedias != null ? extendedMedias : entities.getMediaEntities(); } else {/*w w w . ja va 2 s. c om*/ mediaEntities = entities.getMediaEntities(); } if (mediaEntities != null) { for (final MediaEntity media : mediaEntities) { final URL mediaURL = media.getMediaURL(); if (mediaURL != null) { list.add(new ParcelableMedia(media)); } } } final URLEntity[] urlEntities = entities.getURLEntities(); if (urlEntities != null) { for (final URLEntity url : urlEntities) { final String expanded = ParseUtils.parseString(url.getExpandedURL()); final String media_url = MediaPreviewUtils.getSupportedLink(expanded); if (expanded != null && media_url != null) { list.add(new ParcelableMedia(expanded, media_url, url.getStart(), url.getEnd(), TYPE_IMAGE)); } } } if (list.isEmpty()) return null; return list.toArray(new ParcelableMedia[list.size()]); }
From source file:de.vanita5.twittnuker.util.MediaPreviewUtils.java
License:Open Source License
public static String getSupportedFirstLink(final Status status) { if (status == null) return null; final MediaEntity[] mediaEntities = status.getMediaEntities(); if (mediaEntities != null) { for (final MediaEntity mediaEntity : mediaEntities) { final String expanded = ParseUtils.parseString(mediaEntity.getMediaURLHttps()); if (getSupportedLink(expanded) != null) return expanded; }/*from w w w . j a va2 s .c o m*/ } final URLEntity[] urlEntities = status.getURLEntities(); if (urlEntities != null) { for (final URLEntity urlEntity : urlEntities) { final String expanded = ParseUtils.parseString(urlEntity.getExpandedURL()); if (getSupportedLink(expanded) != null) return expanded; } } return null; }