List of usage examples for twitter4j Status getId
long getId();
From source file:com.javielinux.infos.InfoTweet.java
License:Apache License
public InfoTweet(Status status) { urls = new ArrayList<URLContent>(); mTypeFrom = FROM_STATUS;/*w w w. j a v a 2 s.c o m*/ id = status.getId(); urlAvatar = status.getUser().getProfileImageURL().toString(); userId = status.getUser().getId(); text = status.getText(); username = status.getUser().getScreenName(); fullname = status.getUser().getName(); source = status.getSource(); toUsername = status.getInReplyToScreenName(); toUserId = status.getInReplyToUserId(); createAt = status.getCreatedAt(); toReplyId = status.getInReplyToStatusId(); favorited = status.isFavorited(); if (status.getGeoLocation() != null) { latitude = status.getGeoLocation().getLatitude(); longitude = status.getGeoLocation().getLongitude(); } if (status.getRetweetedStatus() != null) { retweet = true; urlAvatarRetweet = status.getRetweetedStatus().getUser().getProfileImageURL().toString(); textRetweet = status.getRetweetedStatus().getText(); usernameRetweet = status.getRetweetedStatus().getUser().getScreenName(); fullnameRetweet = status.getRetweetedStatus().getUser().getName(); sourceRetweet = status.getRetweetedStatus().getSource(); } urlTweet = "http://twitter.com/#!/" + username.toLowerCase() + PREFIX_URL_TWITTER + id; calculateLinks(); }
From source file:com.joanzapata.android.twitter.service.TwitterService.java
License:Apache License
public List<Status> getTweetsBefore(String username, Status beforeTweet) { try {/* ww w. j a v a 2s .c o m*/ final Paging paging = new Paging().count(TWEET_COUNT); if (beforeTweet != null) paging.maxId(beforeTweet.getId() - 1); final ResponseList<Status> userTimeline = twitter.getUserTimeline(username, paging); if (userTimeline == null) return new ArrayList<Status>(); return userTimeline; } catch (TwitterException e) { Log.e(TAG, "", e); return null; } }
From source file:com.joshlong.esb.springintegration.modules.social.twitter.TwitterMessageSource.java
License:Apache License
private Tweet buildTweetFromStatus(Status firstPost) { Tweet tweet = new Tweet(firstPost.getId(), firstPost.getUser().getName(), firstPost.getCreatedAt(), firstPost.getText());// w w w . j a v a 2 s. c om return tweet; }
From source file:com.k42b3.xoxa.TwitterBot.java
License:Open Source License
public ArrayList<Resource> getResources(int limit) { try {// w w w .j a v a 2s .com List<Status> statuses = this.twitter.getFriendsTimeline(); ArrayList<Resource> resources = new ArrayList<Resource>(limit); for (int i = 0; i < statuses.size() && resources.size() < limit; i++) { Status status = statuses.get(i); if (status.getCreatedAt().after(this.getLastUpdated())) { Resource res = new Resource(); res.setId("" + status.getId()); res.setTitle(status.getText()); res.setLink(status.getSource()); res.setDate(status.getCreatedAt()); resources.add(res); } } return resources; } catch (Exception e) { logger.warning(e.getMessage()); return null; } }
From source file:com.k42b3.xoxa.TwitterBot.java
License:Open Source License
public void onPart(String chan, IRCUser u, String msg) { super.onPart(chan, u, msg); if (chan.equals(this.nick)) { try {// ww w. j a va2 s.com Status status = twitter.updateStatus(msg); logger.info("Update status " + status.getId()); } catch (Exception e) { conn.doPrivmsg(u.getNick(), e.getMessage()); logger.warning(e.getMessage()); } } }
From source file:com.klinker.android.twitter.activities.tweet_viewer.fragments.ConversationFragment.java
License:Apache License
public void getDiscussion(final ListView listView, final long tweetId, final LinearLayout progressBar, final HoloTextView none, final Status status) { Log.v("talon_replies", "getting discussion"); if (replies.size() == 0) { replies.add(status);//from ww w . j a va 2 s . com } Thread getReplies = new Thread(new Runnable() { @Override public void run() { if (!isRunning) { return; } ArrayList<twitter4j.Status> all = null; Twitter twitter = Utils.getTwitter(context, settings); try { Log.v("talon_replies", "looking for discussion"); long id = status.getId(); String screenname = status.getUser().getScreenName(); query = new Query("@" + screenname + " since_id:" + id); Log.v("talon_replies", "query string: " + query.getQuery()); try { query.setCount(100); } catch (Throwable e) { // enlarge buffer error? query.setCount(30); } QueryResult result = twitter.search(query); Log.v("talon_replies", "result: " + result.getTweets().size()); all = new ArrayList<twitter4j.Status>(); do { Log.v("talon_replies", "do loop repetition"); if (!isRunning) { return; } List<Status> tweets = result.getTweets(); for (twitter4j.Status tweet : tweets) { if (tweet.getInReplyToStatusId() == id) { all.add(tweet); Log.v("talon_replies", tweet.getText()); } } if (all.size() > 0) { for (int i = all.size() - 1; i >= 0; i--) { Log.v("talon_replies", "inserting into arraylist:" + all.get(i).getText()); replies.add(all.get(i)); } all.clear(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { progressBar.setVisibility(View.GONE); try { if (replies.size() > 0) { if (adapter == null || adapter.getCount() == 0) { adapter = new TimelineArrayAdapter(context, replies); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); } else { Log.v("talon_replies", "notifying adapter change"); adapter.notifyDataSetChanged(); } } else { none.setVisibility(View.VISIBLE); } } catch (Exception e) { // none and it got the null object e.printStackTrace(); listView.setVisibility(View.GONE); none.setVisibility(View.VISIBLE); } } }); } try { Thread.sleep(250); } catch (Exception e) { // since we are changing the arraylist for the adapter in the background, we need to make sure it // gets updated before continuing } query = result.nextQuery(); if (query != null) result = twitter.search(query); } while (query != null); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } if (replies.size() < 2) { // nothing to show, so tell them that ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { progressBar.setVisibility(View.GONE); listView.setVisibility(View.GONE); none.setVisibility(View.VISIBLE); } }); } } }); getReplies.setPriority(8); getReplies.start(); }
From source file:com.klinker.android.twitter.adapters.PicturesArrayAdapter.java
License:Apache License
public void bindView(final View view, Context mContext, final String url, final Status status) { final ViewHolder holder = (ViewHolder) view.getTag(); Log.v("talon_picture", "text: " + status.getText()); Status thisStatus; String retweeter;/* w ww. ja v a 2 s.c om*/ final long time = status.getCreatedAt().getTime(); long originalTime = 0; if (status.isRetweet()) { retweeter = status.getUser().getScreenName(); thisStatus = status.getRetweetedStatus(); originalTime = thisStatus.getCreatedAt().getTime(); } else { retweeter = ""; thisStatus = status; } final String fRetweeter = retweeter; final long fOriginalTime = originalTime; User user = thisStatus.getUser(); final long id = thisStatus.getId(); final String profilePic = user.getBiggerProfileImageURL(); String tweetTexts = thisStatus.getText(); final String name = user.getName(); final String screenname = user.getScreenName(); String[] html = TweetLinkUtils.getLinksInStatus(thisStatus); final String tweetText = html[0]; final String picUrl = html[1]; final String otherUrl = html[2]; final String hashtags = html[3]; final String users = html[4]; holder.url = url; holder.iv.loadImage(url, false, new NetworkedCacheableImageView.OnImageLoadedListener() { @Override public void onImageLoaded(CacheableBitmapDrawable result) { holder.iv.setBackgroundDrawable(null); } }); holder.iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String link; boolean displayPic = !picUrl.equals(""); if (displayPic) { link = picUrl; } else { link = otherUrl.split(" ")[0]; } Log.v("tweet_page", "clicked"); Intent viewTweet = new Intent(context, TweetPager.class); viewTweet.putExtra("name", name); viewTweet.putExtra("screenname", screenname); viewTweet.putExtra("time", time); viewTweet.putExtra("tweet", tweetText); viewTweet.putExtra("retweeter", fRetweeter); viewTweet.putExtra("webpage", link); viewTweet.putExtra("other_links", otherUrl); viewTweet.putExtra("picture", displayPic); viewTweet.putExtra("tweetid", id); viewTweet.putExtra("proPic", profilePic); viewTweet.putExtra("users", users); viewTweet.putExtra("hashtags", hashtags); context.startActivity(viewTweet); } }); }
From source file:com.klinker.android.twitter.adapters.TimelineArrayAdapter.java
License:Apache License
public void bindView(final View view, Status status, int position) { final ViewHolder holder = (ViewHolder) view.getTag(); if (holder.expandArea.getVisibility() == View.VISIBLE) { removeExpansionNoAnimation(holder); }//w w w. j a va2 s .co m Status thisStatus; String retweeter; final long time = status.getCreatedAt().getTime(); long originalTime = 0; if (status.isRetweet()) { retweeter = status.getUser().getScreenName(); thisStatus = status.getRetweetedStatus(); originalTime = thisStatus.getCreatedAt().getTime(); } else { retweeter = ""; thisStatus = status; } final long fOriginalTime = originalTime; User user = thisStatus.getUser(); holder.tweetId = thisStatus.getId(); final long id = holder.tweetId; final String profilePic = user.getOriginalProfileImageURL(); String tweetTexts = thisStatus.getText(); final String name = user.getName(); final String screenname = user.getScreenName(); String[] html = TweetLinkUtils.getLinksInStatus(thisStatus); final String tweetText = html[0]; final String picUrl = html[1]; holder.picUrl = picUrl; final String otherUrl = html[2]; final String hashtags = html[3]; final String users = html[4]; if (!settings.reverseClickActions) { final String fRetweeter = retweeter; holder.background.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { String link; boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube"); if (displayPic) { link = holder.picUrl; } else { link = otherUrl.split(" ")[0]; } Log.v("tweet_page", "clicked"); Intent viewTweet = new Intent(context, TweetPager.class); viewTweet.putExtra("name", name); viewTweet.putExtra("screenname", screenname); viewTweet.putExtra("time", time); viewTweet.putExtra("tweet", tweetText); viewTweet.putExtra("retweeter", fRetweeter); viewTweet.putExtra("webpage", link); viewTweet.putExtra("other_links", otherUrl); viewTweet.putExtra("picture", displayPic); viewTweet.putExtra("tweetid", holder.tweetId); viewTweet.putExtra("proPic", profilePic); viewTweet.putExtra("users", users); viewTweet.putExtra("hashtags", hashtags); context.startActivity(viewTweet); return true; } }); holder.background.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (holder.preventNextClick) { holder.preventNextClick = false; return; } if (holder.expandArea.getVisibility() == View.GONE) { addExpansion(holder, screenname, users, otherUrl.split(" "), holder.picUrl, id); } else { removeExpansionWithAnimation(holder); removeKeyboard(holder); } } }); } else { final String fRetweeter = retweeter; holder.background.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (holder.preventNextClick) { holder.preventNextClick = false; return; } String link; boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube"); if (displayPic) { link = holder.picUrl; } else { link = otherUrl.split(" ")[0]; } Log.v("tweet_page", "clicked"); Intent viewTweet = new Intent(context, TweetPager.class); viewTweet.putExtra("name", name); viewTweet.putExtra("screenname", screenname); viewTweet.putExtra("time", time); viewTweet.putExtra("tweet", tweetText); viewTweet.putExtra("retweeter", fRetweeter); viewTweet.putExtra("webpage", link); viewTweet.putExtra("other_links", otherUrl); viewTweet.putExtra("picture", displayPic); viewTweet.putExtra("tweetid", holder.tweetId); viewTweet.putExtra("proPic", profilePic); viewTweet.putExtra("users", users); viewTweet.putExtra("hashtags", hashtags); context.startActivity(viewTweet); } }); holder.background.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { if (holder.expandArea.getVisibility() == View.GONE) { addExpansion(holder, screenname, users, otherUrl.split(" "), holder.picUrl, id); } else { removeExpansionWithAnimation(holder); removeKeyboard(holder); } return true; } }); } if (!screenname.equals(username)) { holder.profilePic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent viewProfile = new Intent(context, ProfilePager.class); viewProfile.putExtra("name", name); viewProfile.putExtra("screenname", screenname); viewProfile.putExtra("proPic", profilePic); viewProfile.putExtra("tweetid", holder.tweetId); viewProfile.putExtra("retweet", holder.retweeter.getVisibility() == View.VISIBLE); viewProfile.putExtra("long_click", false); context.startActivity(viewProfile); } }); holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { Intent viewProfile = new Intent(context, ProfilePager.class); viewProfile.putExtra("name", name); viewProfile.putExtra("screenname", screenname); viewProfile.putExtra("proPic", profilePic); viewProfile.putExtra("tweetid", holder.tweetId); viewProfile.putExtra("retweet", holder.retweeter.getVisibility() == View.VISIBLE); viewProfile.putExtra("long_click", true); context.startActivity(viewProfile); return false; } }); } else { // need to clear the click listener so it isn't left over from another profile holder.profilePic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return true; } }); } if (talonLayout == AppSettings.LAYOUT_FULL_SCREEN || (settings.nameAndHandleOnTweet && settings.addonTheme)) { if (holder.screenTV.getVisibility() == View.GONE) { holder.screenTV.setVisibility(View.VISIBLE); } holder.screenTV.setText("@" + screenname); holder.name.setText(name); } else { if (!settings.showBoth) { holder.name.setText(settings.displayScreenName ? "@" + screenname : name); } else { if (holder.screenTV.getVisibility() == View.GONE) { holder.screenTV.setVisibility(View.VISIBLE); } holder.name.setText(name); holder.screenTV.setText("@" + screenname); } } if (!settings.absoluteDate) { holder.time.setText(Utils.getTimeAgo(time, context)); } else { Date date = new Date(time); holder.time .setText(timeFormatter.format(date).replace("24:", "00:") + ", " + dateFormatter.format(date)); } holder.tweet.setText(tweetText); boolean picture = false; if (settings.inlinePics) { if (holder.picUrl.equals("")) { if (holder.image.getVisibility() != View.GONE) { holder.image.setVisibility(View.GONE); } if (holder.playButton.getVisibility() == View.VISIBLE) { holder.playButton.setVisibility(View.GONE); } } else { if (holder.picUrl.contains("youtube")) { if (holder.playButton.getVisibility() == View.GONE) { holder.playButton.setVisibility(View.VISIBLE); } final String fRetweeter = retweeter; holder.image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String link; boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube"); if (displayPic) { link = holder.picUrl; } else { link = otherUrl.split(" ")[0]; } Intent viewTweet = new Intent(context, TweetPager.class); viewTweet.putExtra("name", name); viewTweet.putExtra("screenname", screenname); viewTweet.putExtra("time", time); viewTweet.putExtra("tweet", tweetText); viewTweet.putExtra("retweeter", fRetweeter); viewTweet.putExtra("webpage", link); viewTweet.putExtra("other_links", otherUrl); viewTweet.putExtra("picture", displayPic); viewTweet.putExtra("tweetid", holder.tweetId); viewTweet.putExtra("proPic", profilePic); viewTweet.putExtra("users", users); viewTweet.putExtra("hashtags", hashtags); viewTweet.putExtra("clicked_youtube", true); context.startActivity(viewTweet); } }); holder.image.setImageDrawable(transparent); picture = true; } else { holder.image.setImageDrawable(transparent); picture = true; if (holder.playButton.getVisibility() == View.VISIBLE) { holder.playButton.setVisibility(View.GONE); } holder.image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (holder.picUrl.contains(" ")) { context.startActivity(new Intent(context, ViewPictures.class).putExtra("pictures", holder.picUrl)); } else { context.startActivity(new Intent(context, PhotoViewerDialog.class).putExtra("url", holder.picUrl)); } } }); } if (holder.image.getVisibility() == View.GONE) { holder.image.setVisibility(View.VISIBLE); } } } if (type == NORMAL) { if (retweeter.length() > 0) { holder.retweeter.setText(context.getResources().getString(R.string.retweeter) + retweeter); holder.retweeterName = retweeter; holder.retweeter.setVisibility(View.VISIBLE); } else if (holder.retweeter.getVisibility() == View.VISIBLE) { holder.retweeter.setVisibility(View.GONE); } } else if (type == RETWEET) { int count = status.getRetweetCount(); if (count > 1) { holder.retweeter.setText( status.getRetweetCount() + " " + context.getResources().getString(R.string.retweets_lower)); holder.retweeter.setVisibility(View.VISIBLE); } else if (count == 1) { holder.retweeter.setText( status.getRetweetCount() + " " + context.getResources().getString(R.string.retweet_lower)); holder.retweeter.setVisibility(View.VISIBLE); } } if (picture) { CacheableBitmapDrawable wrapper = mCache.getFromMemoryCache(holder.picUrl); if (wrapper != null) { holder.image.setImageDrawable(wrapper); picture = false; } } final boolean hasPicture = picture; mHandler[currHandler].removeCallbacksAndMessages(null); mHandler[currHandler].postDelayed(new Runnable() { @Override public void run() { if (holder.tweetId == id) { if (hasPicture) { loadImage(context, holder, holder.picUrl, mCache, id); } if (settings.useEmoji && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) { String text = holder.tweet.getText().toString(); if (EmojiUtils.emojiPattern.matcher(text).find()) { final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText)); holder.tweet.setText(span); } } holder.tweet.setSoundEffectsEnabled(false); holder.tweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!TouchableMovementMethod.touched) { Log.v("talon_clickable", "clicked in the cursor adapter"); // we need to manually set the background for click feedback because the spannable // absorbs the click on the background if (!holder.preventNextClick) { holder.background.getBackground() .setState(new int[] { android.R.attr.state_pressed }); new Handler().postDelayed(new Runnable() { @Override public void run() { holder.background.getBackground() .setState(new int[] { android.R.attr.state_empty }); } }, 25); } holder.background.performClick(); } } }); holder.tweet.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { if (!TouchableMovementMethod.touched) { holder.background.performLongClick(); holder.preventNextClick = true; } return false; } }); if (holder.retweeter.getVisibility() == View.VISIBLE) { holder.retweeter.setSoundEffectsEnabled(false); holder.retweeter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!TouchableMovementMethod.touched) { if (!holder.preventNextClick) { holder.background.getBackground() .setState(new int[] { android.R.attr.state_pressed }); new Handler().postDelayed(new Runnable() { @Override public void run() { holder.background.getBackground() .setState(new int[] { android.R.attr.state_empty }); } }, 25); } holder.background.performClick(); } } }); holder.retweeter.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { if (!TouchableMovementMethod.touched) { holder.background.performLongClick(); holder.preventNextClick = true; } return false; } }); } TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false); TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false); } } }, 400); currHandler++; if (currHandler == 10) { currHandler = 0; } if (openFirst && position == 0) { holder.background.performClick(); } }
From source file:com.klinker.android.twitter.adapters.TimelineArrayAdapter.java
License:Apache License
public void addExpansion(final ViewHolder holder, String screenname, String users, final String[] otherLinks, final String webpage, final long id) { holder.retweet.setVisibility(View.VISIBLE); holder.retweetCount.setVisibility(View.VISIBLE); holder.favCount.setVisibility(View.VISIBLE); holder.favorite.setVisibility(View.VISIBLE); //holder.reply.setVisibility(View.GONE); try {/* ww w . j av a 2 s . c om*/ holder.replyButton.setVisibility(View.GONE); } catch (Exception e) { } holder.screenName = screenname; // used to find the other names on a tweet... could be optimized i guess, but only run when button is pressed final String text = holder.tweet.getText().toString(); String extraNames = ""; if (text.contains("@")) { for (String s : users.split(" ")) { if (!s.equals(settings.myScreenName) && !extraNames.contains(s) && !s.equals(screenname)) { extraNames += "@" + s + " "; } } } try { if (holder.retweeter.getVisibility() == View.VISIBLE && !extraNames.contains(holder.retweeterName)) { extraNames += "@" + holder.retweeterName + " "; } } catch (NullPointerException e) { } if (!screenname.equals(settings.myScreenName)) { holder.reply.setText("@" + screenname + " " + extraNames); } else { holder.reply.setText(extraNames); } holder.reply.setSelection(holder.reply.getText().length()); if (holder.favCount.getText().toString().length() <= 2) { holder.favCount.setText(" -"); holder.retweetCount.setText(" -"); } //ExpansionAnimation expandAni = new ExpansionAnimation(holder.expandArea, 450); holder.expandArea.setVisibility(View.VISIBLE);//startAnimation(expandAni); getCounts(holder, id); holder.favorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new FavoriteStatus(holder, holder.tweetId).execute(); } }); holder.retweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new RetweetStatus(holder, holder.tweetId).execute(); } }); holder.retweet.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.remove_retweet)) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { new RemoveRetweet(holder.tweetId).execute(); } }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).create().show(); return false; } class RemoveRetweet extends AsyncTask<String, Void, Boolean> { private long tweetId; public RemoveRetweet(long tweetId) { this.tweetId = tweetId; } protected void onPreExecute() { holder.retweet.clearColorFilter(); Toast.makeText(context, context.getResources().getString(R.string.removing_retweet), Toast.LENGTH_SHORT).show(); } protected Boolean doInBackground(String... urls) { try { Twitter twitter = Utils.getTwitter(context, settings); ResponseList<twitter4j.Status> retweets = twitter.getRetweets(tweetId); for (twitter4j.Status retweet : retweets) { if (retweet.getUser().getId() == settings.myId) twitter.destroyStatus(retweet.getId()); } return true; } catch (Exception e) { e.printStackTrace(); return false; } } protected void onPostExecute(Boolean deleted) { try { if (deleted) { Toast.makeText(context, context.getResources().getString(R.string.success), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, context.getResources().getString(R.string.error), Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // user has gone away from the window } } } }); holder.reply.requestFocus(); removeKeyboard(holder); holder.reply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent compose = new Intent(context, ComposeActivity.class); String string = holder.reply.getText().toString(); try { compose.putExtra("user", string.substring(0, string.length() - 1)); } catch (Exception e) { } compose.putExtra("id", holder.tweetId); compose.putExtra("reply_to_text", "@" + holder.screenName + ": " + text); context.startActivity(compose); removeExpansionWithAnimation(holder); } }); if (holder.replyButton != null) { holder.replyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new ReplyToStatus(holder, holder.tweetId).execute(); } }); } final String name = screenname; try { holder.shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); String text = holder.tweet.getText().toString(); text = TweetLinkUtils.removeColorHtml(text, settings); text = restoreLinks(text); if (!settings.preferRT) { text = "\"@" + name + ": " + text + "\" "; } else { text = " RT @" + name + ": " + text; } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, text); context.startActivity( Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); } public String restoreLinks(String text) { String full = text; String[] split = text.split("\\s"); String[] otherLink = new String[otherLinks.length]; for (int i = 0; i < otherLinks.length; i++) { otherLink[i] = "" + otherLinks[i]; } boolean changed = false; if (otherLink.length > 0) { for (int i = 0; i < split.length; i++) { String s = split[i]; //if (Patterns.WEB_URL.matcher(s).find()) { // we know the link is cut off if (s.contains("...")) { // we know the link is cut off String f = s.replace("...", "").replace("http", ""); Log.v("talon_links", ":" + s + ":"); for (int x = 0; x < otherLink.length; x++) { if (otherLink[x].toLowerCase().contains(f.toLowerCase())) { changed = true; // for some reason it wouldn't match the last "/" on a url and it was stopping it from opening try { if (otherLink[x] .substring(otherLink[x].length() - 1, otherLink[x].length()) .equals("/")) { otherLink[x] = otherLink[x].substring(0, otherLink[x].length() - 1); } f = otherLink[x].replace("http://", "").replace("https://", "") .replace("www.", ""); otherLink[x] = ""; } catch (Exception e) { } break; } } if (changed) { split[i] = f; } else { split[i] = s; } } else { split[i] = s; } } } if (!webpage.equals("")) { for (int i = 0; i < split.length; i++) { String s = split[i]; if (s.contains("...")) { s = s.replace("...", ""); if (Patterns.WEB_URL.matcher(s).find() && (s.startsWith("t.co/") || s.contains("twitter.com/"))) { // we know the link is cut off String replace = otherLinks[otherLinks.length - 1]; if (replace.replace(" ", "").equals("")) { replace = webpage; } split[i] = replace; changed = true; } } } } if (changed) { full = ""; for (String p : split) { full += p + " "; } full = full.substring(0, full.length() - 1); } return full; } }); holder.quoteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(context, ComposeActivity.class); intent.setType("text/plain"); String text = holder.tweet.getText().toString(); text = TweetLinkUtils.removeColorHtml(text, settings); text = restoreLinks(text); if (!settings.preferRT) { text = "\"@" + name + ": " + text + "\" "; } else { text = " RT @" + name + ": " + text; } intent.putExtra("user", text); intent.putExtra("id", id); context.startActivity(intent); } public String restoreLinks(String text) { String full = text; String[] split = text.split("\\s"); String[] otherLink = new String[otherLinks.length]; for (int i = 0; i < otherLinks.length; i++) { otherLink[i] = "" + otherLinks[i]; } boolean changed = false; if (otherLink.length > 0) { for (int i = 0; i < split.length; i++) { String s = split[i]; //if (Patterns.WEB_URL.matcher(s).find()) { // we know the link is cut off if (s.contains("...")) { // we know the link is cut off String f = s.replace("...", "").replace("http", ""); Log.v("talon_links", ":" + s + ":"); for (int x = 0; x < otherLink.length; x++) { if (otherLink[x].toLowerCase().contains(f.toLowerCase())) { changed = true; // for some reason it wouldn't match the last "/" on a url and it was stopping it from opening try { if (otherLink[x] .substring(otherLink[x].length() - 1, otherLink[x].length()) .equals("/")) { otherLink[x] = otherLink[x].substring(0, otherLink[x].length() - 1); } f = otherLink[x].replace("http://", "").replace("https://", "") .replace("www.", ""); otherLink[x] = ""; } catch (Exception e) { } break; } } if (changed) { split[i] = f; } else { split[i] = s; } } else { split[i] = s; } } } if (!webpage.equals("")) { for (int i = 0; i < split.length; i++) { String s = split[i]; s = s.replace("...", ""); if (Patterns.WEB_URL.matcher(s).find() && (s.startsWith("t.co/") || s.contains("twitter.com/"))) { // we know the link is cut off String replace = otherLinks[otherLinks.length - 1]; if (replace.replace(" ", "").equals("")) { replace = webpage; } split[i] = replace; changed = true; } } } if (changed) { full = ""; for (String p : split) { full += p + " "; } full = full.substring(0, full.length() - 1); } return full; } }); } catch (Exception e) { // theme made before these were implemented } }
From source file:com.klinker.android.twitter.adapters.TimeLineCursorAdapter.java
License:Apache License
public void addExpansion(final ViewHolder holder, String screenname, String users, final String[] otherLinks, final String webpage, final long tweetId, String[] hashtags) { if (isDM) {//from w w w . j av a 2 s . c o m holder.retweet.setVisibility(View.GONE); holder.retweetCount.setVisibility(View.GONE); holder.favCount.setVisibility(View.GONE); holder.favorite.setVisibility(View.GONE); } else { holder.retweet.setVisibility(View.VISIBLE); holder.retweetCount.setVisibility(View.VISIBLE); holder.favCount.setVisibility(View.VISIBLE); holder.favorite.setVisibility(View.VISIBLE); } try { holder.replyButton.setVisibility(View.GONE); } catch (Exception e) { } try { holder.charRemaining.setVisibility(View.GONE); } catch (Exception e) { } holder.screenName = screenname; // used to find the other names on a tweet... could be optimized i guess, but only run when button is pressed if (!isDM) { String text = holder.tweet.getText().toString(); String extraNames = ""; if (text.contains("@")) { for (String s : users.split(" ")) { if (!s.equals(settings.myScreenName) && !extraNames.contains(s) && !s.equals(screenname)) { extraNames += "@" + s + " "; } } } try { if (holder.retweeter.getVisibility() == View.VISIBLE && !extraNames.contains(holder.retweeterName)) { extraNames += "@" + holder.retweeterName + " "; } } catch (NullPointerException e) { } if (!screenname.equals(settings.myScreenName)) { holder.reply.setText("@" + screenname + " " + extraNames); } else { holder.reply.setText(extraNames); } if (settings.autoInsertHashtags && hashtags != null) { for (String s : hashtags) { if (!s.equals("")) { holder.reply.append("#" + s + " "); } } } } holder.reply.setSelection(holder.reply.getText().length()); if (holder.favCount.getText().toString().length() <= 2) { holder.favCount.setText(" -"); holder.retweetCount.setText(" -"); } //ExpansionAnimation expandAni = new ExpansionAnimation(holder.expandArea, 450); holder.expandArea.setVisibility(View.VISIBLE);//startAnimation(expandAni); if (holder.favCount.getText().toString().equals(" -")) { getCounts(holder, tweetId); } holder.favorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new FavoriteStatus(holder, holder.tweetId).execute(); } }); holder.retweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new RetweetStatus(holder, holder.tweetId).execute(); } }); holder.retweet.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.remove_retweet)) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { new RemoveRetweet(holder.tweetId).execute(); } }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).create().show(); return false; } class RemoveRetweet extends AsyncTask<String, Void, Boolean> { private long tweetId; public RemoveRetweet(long tweetId) { this.tweetId = tweetId; } protected void onPreExecute() { holder.retweet.clearColorFilter(); Toast.makeText(context, context.getResources().getString(R.string.removing_retweet), Toast.LENGTH_SHORT).show(); } protected Boolean doInBackground(String... urls) { try { Twitter twitter = Utils.getTwitter(context, settings); ResponseList<twitter4j.Status> retweets = twitter.getRetweets(tweetId); for (twitter4j.Status retweet : retweets) { if (retweet.getUser().getId() == settings.myId) twitter.destroyStatus(retweet.getId()); } return true; } catch (Exception e) { e.printStackTrace(); return false; } } protected void onPostExecute(Boolean deleted) { try { if (deleted) { Toast.makeText(context, context.getResources().getString(R.string.success), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, context.getResources().getString(R.string.error), Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // user has gone away from the window } } } }); holder.reply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent compose = new Intent(context, ComposeActivity.class); String string = holder.reply.getText().toString(); try { compose.putExtra("user", string.substring(0, string.length() - 1)); } catch (Exception e) { e.printStackTrace(); } compose.putExtra("id", holder.tweetId); compose.putExtra("reply_to_text", "@" + holder.screenName + ": " + holder.tweet.getText().toString()); if (isHomeTimeline) { sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId) .commit(); } context.startActivity(compose); removeExpansionWithAnimation(holder); } }); holder.reply.requestFocus(); removeKeyboard(holder); // this isn't going to run anymore, but just in case i put it back i guess if (holder.replyButton != null) { holder.replyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new ReplyToStatus(holder, holder.tweetId).execute(); } }); holder.charRemaining.setText(140 - holder.reply.getText().length() + ""); holder.reply.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { hasKeyboard = b; } }); holder.reply.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { holder.charRemaining.setText(140 - holder.reply.getText().length() + ""); } @Override public void afterTextChanged(Editable editable) { } }); } final String name = screenname; try { holder.shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); String text = holder.tweet.getText().toString(); text = restoreLinks(text); text = "@" + name + ": " + text; Log.v("talon_sharing", "text: " + text); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, text); if (isHomeTimeline) { sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId) .commit(); } context.startActivity( Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); } public String restoreLinks(String text) { String full = text; String[] split = text.split("\\s"); String[] otherLink = new String[otherLinks.length]; for (int i = 0; i < otherLinks.length; i++) { otherLink[i] = "" + otherLinks[i]; } boolean changed = false; if (otherLink.length > 0) { for (int i = 0; i < split.length; i++) { String s = split[i]; if (Patterns.WEB_URL.matcher(s).find()) { // we know the link is cut off String f = s.replace("...", "").replace("http", ""); for (int x = 0; x < otherLink.length; x++) { if (otherLink[x].contains(f)) { changed = true; // for some reason it wouldn't match the last "/" on a url and it was stopping it from opening if (otherLink[x].substring(otherLink[x].length() - 1, otherLink[x].length()) .equals("/")) { otherLink[x] = otherLink[x].substring(0, otherLink[x].length() - 1); } f = otherLink[x]; otherLink[x] = ""; break; } } if (changed) { split[i] = f; } else { split[i] = s; } } else { split[i] = s; } } } if (!webpage.equals("")) { for (int i = 0; i < split.length; i++) { String s = split[i]; if (s.contains("...")) { s = s.replace("...", ""); if (Patterns.WEB_URL.matcher(s).find() && (s.startsWith("t.co/") || s.contains("twitter.com/"))) { // we know the link is cut off String replace = otherLinks[otherLinks.length - 1]; if (replace.replace(" ", "").equals("")) { replace = webpage; } split[i] = replace; changed = true; } } } } if (changed) { full = ""; for (String p : split) { full += p + " "; } full = full.substring(0, full.length() - 1); } return full; } }); holder.quoteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(context, ComposeActivity.class); intent.setType("text/plain"); String text = holder.tweet.getText().toString(); text = TweetLinkUtils.removeColorHtml(text, settings); text = restoreLinks(text); if (!settings.preferRT) { text = "\"@" + name + ": " + text + "\" "; } else { text = " RT @" + name + ": " + text; } intent.putExtra("user", text); intent.putExtra("id", tweetId); if (isHomeTimeline) { sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId) .commit(); } context.startActivity(intent); } public String restoreLinks(String text) { String full = text; String[] split = text.split("\\s"); String[] otherLink = new String[otherLinks.length]; for (int i = 0; i < otherLinks.length; i++) { otherLink[i] = "" + otherLinks[i]; } boolean changed = false; if (otherLink.length > 0) { for (int i = 0; i < split.length; i++) { String s = split[i]; if (Patterns.WEB_URL.matcher(s).find()) { // we know the link is cut off String f = s.replace("...", "").replace("http", ""); for (int x = 0; x < otherLink.length; x++) { if (otherLink[x].contains(f)) { changed = true; // for some reason it wouldn't match the last "/" on a url and it was stopping it from opening if (otherLink[x].substring(otherLink[x].length() - 1, otherLink[x].length()) .equals("/")) { otherLink[x] = otherLink[x].substring(0, otherLink[x].length() - 1); } f = otherLink[x]; otherLink[x] = ""; break; } } if (changed) { split[i] = f; } else { split[i] = s; } } else { split[i] = s; } } } if (!webpage.equals("")) { for (int i = 0; i < split.length; i++) { String s = split[i]; s = s.replace("...", ""); if (Patterns.WEB_URL.matcher(s).find() && (s.startsWith("t.co/") || s.contains("twitter.com/"))) { // we know the link is cut off String replace = otherLinks[otherLinks.length - 1]; if (replace.replace(" ", "").equals("")) { replace = webpage; } split[i] = replace; changed = true; } } } if (changed) { full = ""; for (String p : split) { full += p + " "; } full = full.substring(0, full.length() - 1); } return full; } }); } catch (Exception e) { // theme made before these were implemented } if (settings.addonTheme) { try { Resources resourceAddon = context.getPackageManager() .getResourcesForApplication(settings.addonThemePackage); int back = resourceAddon.getIdentifier("reply_entry_background", "drawable", settings.addonThemePackage); holder.reply.setBackgroundDrawable(resourceAddon.getDrawable(back)); } catch (Exception e) { // theme does not include a reply entry box } } }