首页 > 代码库 > Android MaoZhuaWeiBo 好友动态信息列表数据抓取 -3

Android MaoZhuaWeiBo 好友动态信息列表数据抓取 -3

前面2篇把大致的开发说的差不多了,接下来说说粉丝动态消息列表或时间线数据的抓取与解析显示,我将他全部写在了一个

类里,并以封装类对象的形式存储数据,下面看看主要的服务代码:


粉丝动态消息列表数据抓取:

package com.neweriweibo.service;
/**
 * 用户消息列表
 * @author Engineer-Jsp
 * @date 2014.10.29
 * */
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

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

import com.neweriweibo.model.UserWeibo;
import com.neweriweibo.utils.TencentAPI;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
public class WeiBoService extends Service {
	
    private ArrayList<UserWeibo> data ;
	private String access_token;
	private String openid;
	private String openkey;
	private String getURL; 
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		data = http://www.mamicode.com/new ArrayList() ;>


UserWeiBO:

package com.neweriweibo.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 用户个人的微博
 * @author Engineer-Jsp
 * @date 2014.10.28
 *
 */
public class UserWeibo  implements Parcelable{
	
	
	private String form ;   //从哪里发送的消息
	private String location ;  // 地址
	private String name ;  //名字
	private String origtext ;   //发送微博的信息
	private String timestamp ;  // 发表的时间
	private String number ;  //  广播的条数
	

	
	public UserWeibo() {
		super();
		// TODO Auto-generated constructor stub
	}
	public UserWeibo(String form, String location, String name,
			String origtext, String timestamp,String number ) {
		super();
		this.form = form;
		this.location = location;
		this.name = name;
		this.origtext = origtext;
		this.timestamp = timestamp;
		this.number = number ;
		
	}
	
	
	
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	public String getForm() {
		return form;
	}
	public void setForm(String form) {
		this.form = form;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getOrigtext() {
		return origtext;
	}
	public void setOrigtext(String origtext) {
		this.origtext = origtext;
	}
	public String getTimestamp() {
		return timestamp;
	}
	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}
	
	
	public static final Parcelable.Creator<UserWeibo> CREATOR = new Parcelable.Creator<UserWeibo>() {

		@Override
		public UserWeibo createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			UserWeibo userweibo = new UserWeibo() ;
			userweibo.form = source.readString() ;
			userweibo.location = source.readString() ;
			userweibo.name = source.readString() ;
			userweibo.origtext = source.readString() ;
			userweibo.timestamp = source.readString() ;
			userweibo.number = source.readString() ;
			
			return userweibo;
		}

		@Override
		public UserWeibo[] newArray(int size) {
			// TODO Auto-generated method stub
			return new UserWeibo[size];
		}
	};
	
	
	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		
		dest.writeString(form);
		dest.writeString(location);
		dest.writeString(name);
		dest.writeString(origtext);
		dest.writeString(timestamp);
		dest.writeString(number) ;
		
	}
	

	
	
	  

}

UserWeiBoInfo:

package com.neweriweibo.model;
/**
 * 接收个人微博信息 
 * @author Engineer-Jsp
 * @date 2014.10.28
 */
import android.os.Parcel;
import android.os.Parcelable;
public class UserWeiBiInfo  implements Parcelable{
	
	 private String  id ;  //微博id
	 private String  name ;  //微博人的名字
	 private String  origtext ;  //发送的信息
	 private String  headimg;//头像

	public String getHeadimg() {
		return headimg;
	}
	public void setHeadimg(String headimg) {
		this.headimg = headimg;
	}
	public UserWeiBiInfo() {
		super();
	}
	public UserWeiBiInfo(String id, String name, String origtext,String headimg) {
		super();
		this.id = id;
		this.name = name;
		this.origtext = origtext;
		this.headimg = headimg;
	}
	
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getOrigtext() {
		return origtext;
	}
	
	
	public void setOrigtext(String origtext) {
		this.origtext = origtext;
	}
	@Override
	public int describeContents() {
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		
		dest.writeString(id);
		dest.writeString(name);
		dest.writeString(origtext);
		dest.writeString(headimg);		
	}
	
	 public static final Parcelable.Creator<UserWeiBiInfo> CREATOR = new Creator<UserWeiBiInfo>() {

		@Override
		public UserWeiBiInfo createFromParcel(Parcel source) {
			UserWeiBiInfo userWeiBiInfo = new UserWeiBiInfo() ;
			
			userWeiBiInfo.id = source.readString() ;
			userWeiBiInfo.name = source.readString() ;
			userWeiBiInfo.origtext = source.readString() ;
			userWeiBiInfo.headimg = source.readString();
			
			return userWeiBiInfo;
		}

		@Override
		public UserWeiBiInfo[] newArray(int size) {
			return new UserWeiBiInfo[size];
		}
	};
	
	@Override
	public String toString() {
		return "UserWeiBiInfo [帐号=" + id + ", 昵称=" + name + ", 微博消息="
				+ origtext + ",头像地址="+headimg+"]";
	}
}

界面效果:



标题菜单:



转发、赞、评论功能都没有拓展,有兴趣的可以继续做下去,跟着API写就是了,不难~~

Android MaoZhuaWeiBo 好友动态信息列表数据抓取 -3