Android Open Source - cheepcheep Single Tweet Activity






From Project

Back to project page cheepcheep.

License

The source code is released under:

Apache License

If you think the Android project cheepcheep listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.tarrio.cheepcheep;
/*ww w.ja  v a2  s.  c o m*/
import java.util.ArrayList;

import org.tarrio.cheepcheep.R;
import org.tarrio.cheepcheep.model.Preferences;
import org.tarrio.cheepcheep.model.Tweet;
import org.tarrio.cheepcheep.service.PreferencesProvider;
import org.tarrio.cheepcheep.task.AsyncTwitterTask;
import org.tarrio.cheepcheep.task.GetSingleTweetTask;
import org.tarrio.cheepcheep.task.TaskCallback;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class SingleTweetActivity extends Activity implements OnClickListener {

  private PreferencesProvider preferencesProvider;
  private TweetListActions tweetListActions;
  private Tweet tweet;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    preferencesProvider = new PreferencesProvider(this);
    Preferences pref = preferencesProvider.get();

    Intent intent = getIntent();
    String username = intent.getData().getPathSegments().get(0);
    long tweetId = Long
        .parseLong(intent.getData().getPathSegments().get(1));
    setWindowTitle(username);
    doGetTweet(pref, tweetId);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    tweetListActions.createContextMenuForTweet(menu, tweet);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (tweetListActions.processContextItemSelectedForTweets(item, tweet))
      return true;
    else
      return super.onOptionsItemSelected(item);
  }

  public void setView(Tweet tweet) {
    View view = getLayoutInflater().inflate(R.layout.singletweet, null);
    TextView author = (TextView) view.findViewById(R.id.Author);
    TextView date = (TextView) view.findViewById(R.id.Date);
    TextView text = (TextView) view.findViewById(R.id.Text);

    author.setText(tweet.getScreenName());
    date.setText(DateUtils.getRelativeDateTimeString(this, tweet
        .getDateTime().getTime(), DateUtils.SECOND_IN_MILLIS,
        DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL));
    text.setText(tweet.getText());

    ArrayList<Tweet> tweets = new ArrayList<Tweet>();
    tweets.add(tweet);
    this.tweet = tweet;
    tweetListActions = new TweetListActions(this, preferencesProvider,
        tweets, new UpdateTweetsCallback(), new ReloadTweetsCallback());
    view.setOnClickListener(this);
    setContentView(view);
  }

  /**
   * Sets the window's title.
   */
  private void setWindowTitle(String username) {
    String appName = getString(R.string.app_name);
    String titleFormat = getString(R.string.single_tweet_title);
    setTitle(String.format(titleFormat, appName, username));
  }

  private void doGetTweet(Preferences pref, long tweetId) {
    TaskCallback callback = new TaskCallback() {
      @Override
      public void onSuccess(AsyncTwitterTask task) {
        GetSingleTweetTask theTask = (GetSingleTweetTask) task;
        setView(theTask.getTweet());
      }

      @Override
      public void onFailure(int statusCode, AsyncTwitterTask task) {
        setResult(RESULT_CANCELED);
        finish();
      }
    };
    new GetSingleTweetTask(this, preferencesProvider.get(), callback,
        tweetId).run();
  }

  @Override
  public void onClick(View v) {
    tweetListActions.createMenuForTweet(tweet);
  }

  private class UpdateTweetsCallback implements TaskCallback {
    /**
     * Exits the activity if a tweet was posted, signalling the
     * previous activity that it should update its list of tweets.
     */
    @Override
    public void onSuccess(AsyncTwitterTask task) {
      setResult(Constants.RESULT_UPDATE);
      finish();
    }

    @Override
    public void onFailure(int statusCode, AsyncTwitterTask task) {
    }
  }

  private class ReloadTweetsCallback implements TaskCallback {
    /**
     * Exits the activity if a tweet was posted or deleted, signalling to
     * the previous activity that it should reload its list of tweets.
     */
    @Override
    public void onSuccess(AsyncTwitterTask task) {
      setResult(Constants.RESULT_RELOAD);
      finish();
    }

    @Override
    public void onFailure(int statusCode, AsyncTwitterTask task) {
    }
  }

}




Java Source Code List

org.tarrio.cheepcheep.Constants.java
org.tarrio.cheepcheep.HomeTimelineActivity.java
org.tarrio.cheepcheep.OAuthActivity.java
org.tarrio.cheepcheep.SingleTweetActivity.java
org.tarrio.cheepcheep.TweetListActions.java
org.tarrio.cheepcheep.TweetListAdapter.java
org.tarrio.cheepcheep.UserInfoActivity.java
org.tarrio.cheepcheep.dialog.CheepCheepDialog.java
org.tarrio.cheepcheep.dialog.ConfirmDeleteTweetDialog.java
org.tarrio.cheepcheep.dialog.NewTweetDialog.java
org.tarrio.cheepcheep.exceptions.AuthError.java
org.tarrio.cheepcheep.exceptions.CheepCheepException.java
org.tarrio.cheepcheep.exceptions.NetError.java
org.tarrio.cheepcheep.exceptions.ParseError.java
org.tarrio.cheepcheep.exceptions.TweetNotFoundError.java
org.tarrio.cheepcheep.exceptions.UserNotFoundError.java
org.tarrio.cheepcheep.http.HttpClientFactory.java
org.tarrio.cheepcheep.http.OAuthHttpClient.java
org.tarrio.cheepcheep.model.Preferences.java
org.tarrio.cheepcheep.model.Tweet.java
org.tarrio.cheepcheep.model.User.java
org.tarrio.cheepcheep.service.PreferencesProvider.java
org.tarrio.cheepcheep.service.TwitterJSONSerializer.java
org.tarrio.cheepcheep.service.TwitterService.java
org.tarrio.cheepcheep.service.TwitterStatusSaverService.java
org.tarrio.cheepcheep.task.AsyncTwitterTask.java
org.tarrio.cheepcheep.task.CreateNewTweetTask.java
org.tarrio.cheepcheep.task.DeleteTweetTask.java
org.tarrio.cheepcheep.task.FollowUnfollowUserTask.java
org.tarrio.cheepcheep.task.GetSingleTweetTask.java
org.tarrio.cheepcheep.task.GetUserInfoTask.java
org.tarrio.cheepcheep.task.TaskCallback.java
org.tarrio.cheepcheep.task.UpdateTweetsTask.java
org.tarrio.cheepcheep.task.VerifyCredentialsTask.java