List of usage examples for twitter4j Status getURLEntities
URLEntity[] getURLEntities();
From source file:com.freshdigitable.udonroad.module.realm.StatusRealm.java
License:Apache License
StatusRealm(Status status) { this.id = status.getId(); this.createdAt = status.getCreatedAt(); this.retweetedStatus = status.getRetweetedStatus(); this.retweet = status.isRetweet(); if (status.isRetweet()) { this.retweetedStatusId = this.retweetedStatus.getId(); }//from w w w .ja v a 2 s . c om this.text = status.getText(); this.source = status.getSource(); this.retweetCount = status.getRetweetCount(); this.favoriteCount = status.getFavoriteCount(); this.reaction = new StatusReactionImpl(status); this.user = status.getUser(); this.userId = user.getId(); this.urlEntities = URLEntityRealm.createList(status.getURLEntities()); this.mediaEntities = new RealmList<>(); final ExtendedMediaEntity[] me = status.getExtendedMediaEntities(); for (ExtendedMediaEntity m : me) { mediaEntities.add(new ExtendedMediaEntityRealm(m)); } final UserMentionEntity[] userMentionEntities = status.getUserMentionEntities(); this.userMentionEntities = new RealmList<>(); for (UserMentionEntity u : userMentionEntities) { this.userMentionEntities.add(new UserMentionEntityRealm(u)); } this.quotedStatus = status.getQuotedStatus(); this.quotedStatusId = status.getQuotedStatusId(); }
From source file:com.freshdigitable.udonroad.QuotedStatusView.java
License:Apache License
@Override protected CharSequence parseText(Status status) { String text = getBindingStatus(status).getText(); final URLEntity[] urlEntities = status.getURLEntities(); for (URLEntity u : urlEntities) { text = text.replace(u.getURL(), u.getDisplayURL()); }/* w w w . j av a2 s . c om*/ return removeMediaUrl(text, status.getExtendedMediaEntities()); }
From source file:com.freshdigitable.udonroad.SpannableStringUtil.java
License:Apache License
private static List<SpanningInfo> createURLSpanningInfo(Status bindingStatus) { final String text = bindingStatus.getText(); final String quotedStatusIdStr = bindingStatus.getQuotedStatus() != null ? Long.toString(bindingStatus.getQuotedStatusId()) : ""; final List<SpanningInfo> info = new ArrayList<>(); final URLEntity[] urlEntities = bindingStatus.getURLEntities(); info.addAll(createURLSpanningInfo(text, urlEntities, quotedStatusIdStr)); final ExtendedMediaEntity[] eme = bindingStatus.getExtendedMediaEntities(); for (ExtendedMediaEntity e : eme) { int start = text.indexOf(e.getURL()); int end = start + e.getURL().length(); if (isInvalidRange(text, start, end)) { continue; }// ww w . j av a2 s .c o m info.add(new SpanningInfo(null, start, end, "")); } return info; }
From source file:com.freshdigitable.udonroad.StatusDetailFragment.java
License:Apache License
@Override public void onStart() { super.onStart(); final long statusId = getStatusId(); statusRequestWorker.open();//from w ww. j a v a 2 s .c o m final TypedCache<Status> statusCache = statusRequestWorker.getCache(); final Status status = statusCache.find(statusId); if (status == null) { Toast.makeText(getContext(), "status is not found", Toast.LENGTH_SHORT).show(); return; } final StatusDetailView statusView = binding.statusView; StatusViewImageHelper.load(status, statusView); final User user = StatusViewImageHelper.getBindingUser(status); final ImageView icon = statusView.getIcon(); final OnUserIconClickedListener userIconClickedListener = createUserIconClickedListener(); icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { userIconClickedListener.onUserIconClicked(view, user); } }); statusView.getUserName().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { userIconClickedListener.onUserIconClicked(icon, user); } }); statusView.getMediaContainer().setOnMediaClickListener(new OnMediaClickListener() { @Override public void onMediaClicked(View view, int index) { MediaViewActivity.start(view.getContext(), status, index); } }); setTintList(binding.sdFav.getDrawable(), R.color.selector_fav_icon); binding.sdFav.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (status.isFavorited()) { statusRequestWorker.destroyFavorite(statusId); } else { statusRequestWorker.createFavorite(statusId); } } }); setTintList(binding.sdRetweet.getDrawable(), R.color.selector_rt_icon); binding.sdRetweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (status.isRetweeted()) { statusRequestWorker.destroyRetweet(statusId); } else { statusRequestWorker.retweetStatus(statusId); } } }); DrawableCompat.setTint(binding.sdReply.getDrawable(), ContextCompat.getColor(getContext(), R.color.twitter_action_normal)); binding.sdReply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setupInput(TweetInputFragment.TYPE_REPLY); } }); setTintList(binding.sdQuote.getDrawable(), R.color.twitter_action_normal); binding.sdQuote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setupInput(TweetInputFragment.TYPE_QUOTE); } }); subscription = statusCache.observeById(statusId).subscribe(new Action1<Status>() { @Override public void call(Status status) { binding.statusView.bindStatus(status); binding.sdFav.setActivated(status.isFavorited()); binding.sdRetweet.setActivated(status.isRetweeted()); } }); final Status bindingStatus = StatusViewImageHelper.getBindingStatus(status); if (bindingStatus.getURLEntities().length < 1) { return; } if (twitterCard != null) { setupTwitterCard(twitterCard); } else { TwitterCardFetcher.observeFetch(bindingStatus.getURLEntities()[0].getExpandedURL()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<TwitterCard>() { @Override public void call(final TwitterCard twitterCard) { setupTwitterCard(twitterCard); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { Log.e(TAG, "card fetch: ", throwable); } }); } }
From source file:com.freshdigitable.udonroad.StatusView.java
License:Apache License
@Override protected String parseText(Status status) { final Status bindingStatus = getBindingStatus(status); String text = bindingStatus.getText(); final String quotedStatusIdStr = Long.toString(bindingStatus.getQuotedStatusId()); final URLEntity[] urlEntities = bindingStatus.getURLEntities(); for (URLEntity u : urlEntities) { if (bindingStatus.getQuotedStatus() != null && u.getExpandedURL().contains(quotedStatusIdStr)) { text = text.replace(u.getURL(), ""); } else {// w ww .j a v a2 s . co m text = text.replace(u.getURL(), u.getDisplayURL()); } } return removeMediaUrl(text, bindingStatus.getExtendedMediaEntities()); }
From source file:com.freshdigitable.udonroad.util.TwitterResponseMock.java
License:Apache License
public static Status createStatus(long id, User user) { final Status status = mock(Status.class); when(status.getId()).thenReturn(id); when(status.getCreatedAt()).thenReturn(new Date()); when(status.getText()).thenReturn(createText(id)); when(status.isRetweet()).thenReturn(false); when(status.getSource()).thenReturn("<a href=\"https://twitter.com/akihito104\">Udonroad</a>"); when(status.getURLEntities()).thenReturn(new URLEntity[0]); when(status.getExtendedMediaEntities()).thenReturn(new ExtendedMediaEntity[0]); when(status.getUserMentionEntities()).thenReturn(new UserMentionEntity[0]); when(status.getUser()).thenReturn(user); return status; }
From source file:com.github.daytron.twaattin.ui.tabledecorator.TweetColumnDecorator.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Object generateCell(Table source, Object itemId, Object columnId) { fragments = new ArrayList<>(); Item item = source.getItem(itemId);/*from w w w . j a v a 2s . c om*/ @SuppressWarnings("rawtypes") BeanItem<Status> beanItem = (BeanItem) item; Status status = beanItem.getBean(); createFragmentsWithUrl(status.getURLEntities()); createFragmentsWithTag(status.getHashtagEntities()); createFragmentsWithMention(status.getUserMentionEntities()); Collections.sort(fragments); StringBuilder builder = new StringBuilder(status.getText()); int offset = 0; for (TweetFragment fragment : fragments) { builder.replace(fragment.getStart() + offset, fragment.getEnd() + offset, fragment.getReplacement()); offset += fragment.getOffset(); } return new Label(builder.toString(), HTML); }
From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java
License:Apache License
public static void convert(Status status, Struct struct) { struct.put("CreatedAt", status.getCreatedAt()).put("Id", status.getId()).put("Text", status.getText()) .put("Source", status.getSource()).put("Truncated", status.isTruncated()) .put("InReplyToStatusId", status.getInReplyToStatusId()) .put("InReplyToUserId", status.getInReplyToUserId()) .put("InReplyToScreenName", status.getInReplyToScreenName()).put("Favorited", status.isFavorited()) .put("Retweeted", status.isRetweeted()).put("FavoriteCount", status.getFavoriteCount()) .put("Retweet", status.isRetweet()).put("RetweetCount", status.getRetweetCount()) .put("RetweetedByMe", status.isRetweetedByMe()) .put("CurrentUserRetweetId", status.getCurrentUserRetweetId()) .put("PossiblySensitive", status.isPossiblySensitive()).put("Lang", status.getLang()); Struct userStruct;/*from ww w . j a va 2s . com*/ if (null != status.getUser()) { userStruct = new Struct(USER_SCHEMA); convert(status.getUser(), userStruct); } else { userStruct = null; } struct.put("User", userStruct); Struct placeStruct; if (null != status.getPlace()) { placeStruct = new Struct(PLACE_SCHEMA); convert(status.getPlace(), placeStruct); } else { placeStruct = null; } struct.put("Place", placeStruct); Struct geoLocationStruct; if (null != status.getGeoLocation()) { geoLocationStruct = new Struct(GEO_LOCATION_SCHEMA); convert(status.getGeoLocation(), geoLocationStruct); } else { geoLocationStruct = null; } struct.put("GeoLocation", geoLocationStruct); List<Long> contributers = new ArrayList<>(); if (null != status.getContributors()) { for (Long l : status.getContributors()) { contributers.add(l); } } struct.put("Contributors", contributers); List<String> withheldInCountries = new ArrayList<>(); if (null != status.getWithheldInCountries()) { for (String s : status.getWithheldInCountries()) { withheldInCountries.add(s); } } struct.put("WithheldInCountries", withheldInCountries); struct.put("HashtagEntities", convert(status.getHashtagEntities())); struct.put("UserMentionEntities", convert(status.getUserMentionEntities())); struct.put("MediaEntities", convert(status.getMediaEntities())); struct.put("SymbolEntities", convert(status.getSymbolEntities())); struct.put("URLEntities", convert(status.getURLEntities())); }
From source file:com.javielinux.utils.Utils.java
License:Apache License
static public String getTextURLs(twitter4j.Status st) { String out = ""; URLEntity[] urls = st.getURLEntities(); if (urls != null && urls.length > 0) { for (URLEntity url : urls) { if (url.getDisplayURL() != null && !url.getDisplayURL().equals("")) { out += url.getURL().toString() + SEP_VALUES + url.getDisplayURL() + SEP_VALUES + url.getExpandedURL().toString() + SEP_BLOCK; }//from w w w .j a v a 2s .co m } } MediaEntity[] medias = st.getMediaEntities(); if (medias != null && medias.length > 0) { for (MediaEntity media : medias) { if (media.getDisplayURL() != null && !media.getDisplayURL().equals("")) { out += media.getURL().toString() + SEP_VALUES + media.getDisplayURL() + SEP_VALUES + media.getExpandedURL().toString() + SEP_VALUES + media.getMediaURL().toString() + ":thumb" + SEP_VALUES + media.getMediaURL().toString() + ":medium" + SEP_BLOCK; } } } return out; }
From source file:com.javielinux.utils.Utils.java
License:Apache License
static public String getTwitLoger(twitter4j.Status st) { String out = ""; String link = ""; if (st.getText().contains("(cont) http://t.co/")) { URLEntity[] urls = st.getURLEntities(); if (urls == null || urls.length <= 0) return out; for (URLEntity url : urls) { if (url.getDisplayURL() != null) { if (url.getDisplayURL().contains("tl.gd")) { link = url.getDisplayURL(); }/* w w w. j a v a2 s . co m*/ } } if (!link.equals("")) { String id = link.substring(link.lastIndexOf("/") + 1); String strURL = "http://www.twitlonger.com/api_read/" + id; Document doc = null; try { URL url; URLConnection urlConn = null; url = new URL(strURL); urlConn = url.openConnection(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(urlConn.getInputStream()); } catch (IOException ioe) { } catch (ParserConfigurationException pce) { } catch (SAXException se) { } if (doc != null) { try { //String content = doc.getElementsByTagName("content").item(0).getChildNodes().getLength()+"";//.getFirstChild().getNodeValue(); String content = ""; NodeList nodes = doc.getElementsByTagName("content").item(0).getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { content += nodes.item(i).getNodeValue(); } if (!content.equals("")) { return content; } } catch (Exception e) { } } } } return out; }