Android Open Source - SimpleTwitterClient Tweet






From Project

Back to project page SimpleTwitterClient.

License

The source code is released under:

Copyright (c) 2014 Keithen Hayenga Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the So...

If you think the Android project SimpleTwitterClient 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 com.codepath.apps.basictwitter.models;
//from  ww w  .j a v a  2s.co m
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Tweet {
  private String body;
  private long uid;
  private String createdAt;
  private User user;
  
  public String getBody() {
    return body;
  }

  public long getUid() {
    return uid;
  }

  public String getCreatedAt() {
    return createdAt;
  }

  public User getUser() {
    return user;
  }

  public static ArrayList<Tweet> fromJSONArray(JSONArray jsonArray) {
    ArrayList<Tweet> tweets = new ArrayList<Tweet>(jsonArray.length());
    
    for (int i = 0; i < jsonArray.length(); i++) {
      JSONObject tweetJson = null;
      try {
        tweetJson = jsonArray.getJSONObject(i);
      } catch (Exception e) {
        e.printStackTrace();
        continue;
      }
      Tweet tweet = Tweet.fromJSON(tweetJson);
      if (tweet != null)
        tweets.add(tweet);
    }
    
    return tweets;
  }
  
  public static Tweet fromJSON(JSONObject jsonObject) {
    Tweet tweet = new Tweet();
    // Extract values from JSON to populate member variables.
    try {
      tweet.body = jsonObject.getString("text");
      tweet.uid = jsonObject.getLong("id");
      tweet.createdAt = jsonObject.getString("created_at");
      tweet.user = User.fromJSON(jsonObject.getJSONObject("user"));
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }
    
    return tweet;
  }  
  
  @Override
  public String toString() {
    return getBody() + " = " + getUser().getScreenName();
//////    return getUser().getScreenName();
////    return getBody();
//    User u = getUser();
//    String s = u.getScreenName();
//    return s;
  }
}




Java Source Code List

com.codepath.apps.basictwitter.ComposeActivity.java
com.codepath.apps.basictwitter.LoginActivity.java
com.codepath.apps.basictwitter.TimelineActivity.java
com.codepath.apps.basictwitter.TweetArrayAdapter.java
com.codepath.apps.basictwitter.TwitterApplication.java
com.codepath.apps.basictwitter.TwitterClient.java
com.codepath.apps.basictwitter.models.SampleModel.java
com.codepath.apps.basictwitter.models.Tweet.java
com.codepath.apps.basictwitter.models.User.java