List of usage examples for twitter4j Twitter destroyStatus
Status destroyStatus(long statusId) throws TwitterException;
From source file:au.edu.anu.portal.portlets.tweetal.servlet.TweetalServlet.java
License:Apache License
public void deleteTweets(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userToken = request.getParameter("u"); String userSecret = request.getParameter("s"); long statusID = Long.parseLong(request.getParameter("d")); log.debug("Deleting tweet " + statusID); Twitter twitter = twitterLogic.getTwitterAuthForUser(userToken, userSecret); if (twitter == null) { // no connection response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return;/*w w w . jav a2 s .c o m*/ } try { Status s = twitter.destroyStatus(statusID); if (s != null) { // success response.setStatus(HttpServletResponse.SC_OK); // remove tweets from cache String cacheKey = userToken; tweetsCache.remove(cacheKey); } else { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } } catch (TwitterException e) { // problem in deleting the tweet log.error("Delete Tweet: " + e.getStatusCode() + ": " + e.getClass() + e.getMessage()); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } }
From source file:br.shura.team.mpsbot.venusext.Delete.java
License:Open Source License
@Override public void callVoid(Context context, FunctionCallDescriptor descriptor) throws ScriptRuntimeException { ConnectedBot bot = context.getApplicationContext().getUserData("bot", ConnectedBot.class); Twitter twitter = bot.getHandler(); IntegerValue value = (IntegerValue) descriptor.get(0); Helper.execute(context, () -> twitter.destroyStatus(value.value())); }
From source file:com.daiv.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 {// w w w.ja va 2s . co m 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) { if (holder.isFavorited || !settings.crossAccActions) { new FavoriteStatus(holder, holder.tweetId, FavoriteStatus.TYPE_ACC_ONE).execute(); } else if (settings.crossAccActions) { // dialog for favoriting String[] options = new String[3]; options[0] = "@" + settings.myScreenName; options[1] = "@" + settings.secondScreenName; options[2] = context.getString(R.string.both_accounts); new AlertDialog.Builder(context).setItems(options, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int item) { new FavoriteStatus(holder, holder.tweetId, item + 1).execute(); } }).create().show(); } } }); holder.retweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!settings.crossAccActions) { new RetweetStatus(holder, holder.tweetId, FavoriteStatus.TYPE_ACC_ONE).execute(); } else { // dialog for favoriting String[] options = new String[3]; options[0] = "@" + settings.myScreenName; options[1] = "@" + settings.secondScreenName; options[2] = context.getString(R.string.both_accounts); new AlertDialog.Builder(context).setItems(options, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int item) { new RetweetStatus(holder, holder.tweetId, item + 1).execute(); } }).create().show(); } } }); 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); switch (settings.quoteStyle) { case AppSettings.QUOTE_STYLE_TWITTER: text = " " + "https://twitter.com/" + name + "/status/" + id; break; case AppSettings.QUOTE_STYLE_Test: text = "\"@" + name + ": " + text + "\" "; break; case AppSettings.QUOTE_STYLE_RT: text = " RT @" + name + ": " + text; break; } 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]; } for (String s : otherLink) { Log.v("Test_links", ":" + s + ":"); } boolean changed = false; int otherIndex = 0; 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 (Patterns.WEB_URL.matcher(s).find()) { // we know the link is cut off String f = s.replace("...", "").replace("http", ""); f = stripTrailingPeriods(f); try { if (otherIndex < otherLinks.length) { if (otherLink[otherIndex].substring(otherLink[otherIndex].length() - 1, otherLink[otherIndex].length()).equals("/")) { otherLink[otherIndex] = otherLink[otherIndex].substring(0, otherLink[otherIndex].length() - 1); } f = otherLink[otherIndex].replace("http://", "").replace("https://", "") .replace("www.", ""); otherLink[otherIndex] = ""; otherIndex++; changed = true; } } catch (Exception e) { } if (changed) { split[i] = f; } else { split[i] = s; } } else { split[i] = s; } } } if (!webpage.equals("")) { for (int i = split.length - 1; i >= 0; i--) { String s = split[i]; if (Patterns.WEB_URL.matcher(s).find()) { String replace = otherLinks[otherLinks.length - 1]; if (replace.replace(" ", "").equals("")) { replace = webpage; } split[i] = replace; changed = true; break; } } } if (changed) { full = ""; for (String p : split) { full += p + " "; } full = full.substring(0, full.length() - 1); } return full; } private String stripTrailingPeriods(String url) { try { if (url.substring(url.length() - 1, url.length()).equals(".")) { return stripTrailingPeriods(url.substring(0, url.length() - 1)); } else { return url; } } catch (Exception e) { return url; } } }); 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); switch (settings.quoteStyle) { case AppSettings.QUOTE_STYLE_TWITTER: text = " " + "https://twitter.com/" + name + "/status/" + id; break; case AppSettings.QUOTE_STYLE_Test: text = "\"@" + name + ": " + text + "\" "; break; case AppSettings.QUOTE_STYLE_RT: text = " RT @" + name + ": " + text; break; } 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("Test_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.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 {//from w ww. j a va 2s . com 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 www. jav a2 s . c om*/ 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 } } }
From source file:org.examproject.tweet.service.SimpleTweetService.java
License:Apache License
private Status destroyStatus(long statusId) { Status status = null;/*w w w. j a v a2s.c om*/ try { Twitter twitter = getTwitter(); status = twitter.destroyStatus(statusId); } catch (TwitterException te) { LOG.error("an error occurred: " + te.getMessage()); throw new RuntimeException(te); } return status; }
From source file:org.wso2.carbon.connector.twitter.TwitterDestroyStatus.java
License:Open Source License
public void connect(MessageContext messageContext) throws ConnectException { try {//from w ww . j a v a2s .c o m String statusId = TwitterUtils.lookupTemplateParamater(messageContext, STATUSID); if (statusId == null || "".equals(statusId.trim())) { log.error("Required status Id: "); return; } Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); Status status = twitter.destroyStatus(Long.parseLong(statusId)); TwitterUtils.storeResponseStatus(messageContext, status); } catch (TwitterException te) { log.error("Failed to destroy the status: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:twitter4j.examples.tweets.DestroyStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.DestroyStatus [status id] * * @param args message/*from w w w. ja va 2 s. co m*/ */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.tweets.DestroyStatus [status id]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); twitter.destroyStatus(Long.parseLong(args[0])); System.out.println("Successfully deleted status [" + args[0] + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to delete status: " + te.getMessage()); System.exit(-1); } }