package cn.com.hh.view;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import cn.com.hh.domian.AsyncImageLoader;
import cn.com.hh.domian.AsyncImageLoader.ImageCallback;
import cn.com.hh.domian.UserInfo;
import cn.com.hh.domian.WeiBoInfo;
import cn.com.hh.oauth.OAuth;
import cn.com.hh.utils.DateUtilsDef;
import cn.com.hh.view.LoginActivity.ConfigHelper;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class HomeActivity extends Activity {
private List<WeiBoInfo> wbList;
private UserInfo user;
private LinearLayout loadingLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
loadingLayout = (LinearLayout)findViewById(R.id.loadingLayout);
loadList();
}
public class WeiBoHolder {
public ImageView wbimage;
public ImageView wbicon;
public TextView wbuser;
public TextView wbtime;
public TextView wbtext;
}
//微博列表Adapater
public class WeiBoAdapater extends BaseAdapter{
private AsyncImageLoader asyncImageLoader;
public int getCount() {
return wbList.size();
}
public Object getItem(int position) {
return wbList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
asyncImageLoader = new AsyncImageLoader();
convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.weibo, null);
WeiBoHolder wh = new WeiBoHolder();
wh.wbicon = (ImageView) convertView.findViewById(R.id.wbicon);
wh.wbtext = (TextView) convertView.findViewById(R.id.wbtext);
wh.wbtime = (TextView) convertView.findViewById(R.id.wbtime);
wh.wbuser = (TextView) convertView.findViewById(R.id.wbuser);
wh.wbimage=(ImageView) convertView.findViewById(R.id.wbimage);
WeiBoInfo wb = wbList.get(position);
if(wb!=null){
convertView.setTag(wb.getId());
wh.wbuser.setText(wb.getUserName());
wh.wbtime.setText(wb.getTime());
wh.wbtext.setText(wb.getText(), TextView.BufferType.SPANNABLE);
// textHighlight(wh.wbtext,new char[]{'#'},new char[]{'#'});
// textHighlight(wh.wbtext,new char[]{'@'},new char[]{':',' '});
// textHighlight2(wh.wbtext,"http://"," ");
if(wb.getHaveImage()){
// wh.wbimage.setImageResource(R.drawable.images);
}
Drawable cachedImage = asyncImageLoader.loadDrawable(wb.getUserIcon(),wh.wbicon, new ImageCallback(){
public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {
imageView.setImageDrawable(imageDrawable);
}
});
if (cachedImage == null) {
wh.wbicon.setImageResource(R.drawable.usericon);
}else{
wh.wbicon.setImageDrawable(cachedImage);
}
}
return convertView;
}
}
private void loadList(){
if(ConfigHelper.nowUser==null)
{
}
else
{
user=ConfigHelper.nowUser;
//显示当前用户名称
TextView showName=(TextView)findViewById(R.id.showName);
showName.setText(user.getUserName());
OAuth auth=new OAuth();
String url = "http://api.t.sina.com.cn/statuses/friends_timeline.json";
// String url = "http://api.t.sina.com.cn/statuses/public_timeline.json";
List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("source", auth.consumerKey));
HttpResponse response = auth.SignRequest(user.getToken(), user.getTokenSecret(), url, params);
if (200 == response.getStatusLine().getStatusCode()){
try {
InputStream is = response.getEntity().getContent();
Reader reader = new BufferedReader(new InputStreamReader(is), 4000);
StringBuilder buffer = new StringBuilder((int) response.getEntity().getContentLength());
try {
char[] tmp = new char[1024];
int l;
while ((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
} finally {
reader.close();
}
String string = buffer.toString();
//Log.e("json", "rs:" + string);
((org.apache.http.HttpResponse) response).getEntity().consumeContent();
JSONArray data=new JSONArray(string);
for(int i=0;i<data.length();i++)
{
JSONObject d=data.getJSONObject(i);
//Log.e("json", "rs:" + d.getString("created_at"));
if(d!=null){
JSONObject u=d.getJSONObject("user");
if(d.has("retweeted_status")){
JSONObject r=d.getJSONObject("retweeted_status");
}
//微博id
String id=d.getString("id");
String userId=u.getString("id");
String userName=u.getString("screen_name");
String userIcon=u.getString("profile_image_url");
// Log.e("userIcon", userIcon);
String time=d.getString("created_at");
String text=d.getString("text");
Boolean haveImg=false;
if(d.has("thumbnail_pic")){
haveImg=true;
//String thumbnail_pic=d.getString("thumbnail_pic");
//Log.e("thumbnail_pic", thumbnail_pic);
}
Date startDate=new Date(time);
Date nowDate = Calendar.getInstance().getTime();
time=new DateUtilsDef().twoDateDistance(startDate,nowDate);
if(wbList==null){
wbList=new ArrayList<WeiBoInfo>();
}
WeiBoInfo w=new WeiBoInfo();
w.setId(id);
w.setUserId(userId);
w.setUserName(userName);
w.setTime(time +" 前");
w.setText(text);
没有合适的资源?快使用搜索试试~ 我知道了~
Android应用源码之微博客户端源代码.zip项目安卓应用源码下载
共131个文件
png:54个
class:38个
xml:16个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 36 浏览量
2022-03-08
20:34:19
上传
评论
收藏 1002KB ZIP 举报
温馨提示
Android应用源码之微博客户端源代码.zip项目安卓应用源码下载Android应用源码之微博客户端源代码.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之微博客户端源代码.zip项目安卓应用源码下载 (131个子文件)
resources.ap_ 272KB
weiboSina.apk 316KB
proguard.cfg 1KB
ViewActivity.class 8KB
HomeActivity.class 6KB
OAuth.class 6KB
DataHelper.class 6KB
LoginActivity.class 5KB
MyBlogActivity.class 5KB
DateUtilsDef.class 4KB
HomeActivity$WeiBoAdapater.class 3KB
AsyncImageLoader.class 3KB
AuthorizeActivity.class 3KB
LoginActivity$UserAdapater.class 2KB
SqliteHelper.class 2KB
LoginActivity$1$1.class 2KB
LoginActivity$1.class 2KB
WeiBoInfo.class 2KB
HomeActivity$1.class 2KB
R$drawable.class 2KB
UserInfo.class 2KB
R$id.class 2KB
AsyncImageLoader$2.class 2KB
AsyncImageLoader$1.class 1KB
ViewActivity$2.class 1KB
AuthorizeActivity$1.class 1KB
HomeActivity$WeiBoAdapater$1.class 1KB
Download.class 1KB
ViewActivity$3.class 1KB
ViewActivity$1.class 1KB
LoginActivity$2.class 787B
R$layout.class 652B
HomeActivity$WeiBoHolder.class 635B
R.class 589B
ImageActivity.class 512B
R$style.class 449B
LoginActivity$ConfigHelper.class 448B
R$string.class 415B
R$anim.class 379B
AsyncImageLoader$ImageCallback.class 338B
R$attr.class 328B
.classpath 539B
classes.dex 84KB
start_wait.gif 14KB
HomeActivity.java 9KB
ViewActivity.java 9KB
DateUtilsDef.java 7KB
LoginActivity.java 6KB
R.java 6KB
OAuth.java 5KB
DataHelper.java 4KB
MyBlogActivity.java 4KB
AsyncImageLoader.java 2KB
AuthorizeActivity.java 2KB
SqliteHelper.java 2KB
WeiBoInfo.java 1KB
UserInfo.java 1KB
ImageActivity.java 1KB
Download.java 841B
wait.png 151KB
blog_bg.png 43KB
btn_sx.png 10KB
logo_s.png 6KB
usericon.png 5KB
touxiang.png 4KB
btn_start_selector.png 4KB
icon.png 4KB
btn_sc.png 4KB
logo_ss.png 3KB
btn_gz.png 3KB
icon.png 3KB
btn_pl.png 2KB
btn_shouquan.png 2KB
btn_cancel_selector.png 2KB
del_user.png 2KB
icon.png 2KB
add_count.png 2KB
info_icon.png 1KB
u_bg_v.png 1KB
btn_home_selector.png 1KB
btn_refresh_selector.png 1KB
btn_write_selector.png 1KB
tab_two_highlight.png 1KB
r8.png 1024B
r8.png 1024B
r4.png 1014B
r4.png 1014B
r5.png 1013B
r5.png 1013B
r1.png 1010B
r1.png 1010B
r7.png 998B
r7.png 998B
r2.png 992B
r2.png 992B
r3.png 986B
r3.png 986B
btn_return_selector.png 985B
r6.png 980B
r6.png 980B
共 131 条
- 1
- 2
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功