1 package com
.weibo
.sina
;
3 import java
.util
.ArrayList
;
6 import weibo4android
.Comment
;
7 import weibo4android
.Count
;
8 import weibo4android
.Status
;
9 import weibo4android
.Weibo
;
10 import weibo4android
.WeiboException
;
11 import weibo4android
.androidexamples
.OAuthConstant
;
12 import android
.app
.TabActivity
;
13 import android
.graphics
.drawable
.Drawable
;
14 import android
.os
.Bundle
;
15 import android
.os
.Handler
;
16 import android
.os
.Message
;
17 import android
.util
.Log
;
18 import android
.view
.LayoutInflater
;
19 import android
.view
.View
;
20 import android
.widget
.ArrayAdapter
;
21 import android
.widget
.ImageView
;
22 import android
.widget
.LinearLayout
;
23 import android
.widget
.ListView
;
24 import android
.widget
.ProgressBar
;
25 import android
.widget
.TabHost
;
26 import android
.widget
.TabWidget
;
27 import android
.widget
.TextView
;
29 import com
.weibo
.util
.AsyncImageLoader
;
30 import com
.weibo
.view
.StatusView
;
32 public class MessageDetail
extends TabActivity
{
34 private TextView reply_title
;
35 private TextView retweet_title
;
37 private ImageView mImageView
;
38 private Drawable mDrawable
= null;
43 private static final int UPDATEFACE
=0x00;
44 private static final int UPDATECONTENT
=0x01;
46 private static final String TAG
= "MessageDetail";
47 private List
<String
> mComments
;
48 private ArrayAdapter
<String
> mReplyAdapter
;
50 private List
<String
> mRetweet
;
51 private ArrayAdapter
<String
> mRetweetAdapter
;
55 private Handler mHandler
= new Handler() {
58 public void handleMessage(Message msg
) {
60 case UPDATEFACE
: //更新用户头像
61 mImageView
.setBackgroundDrawable(mDrawable
);
62 mImageView
.invalidate();
64 case UPDATECONTENT
: //更新用户评论,转发数
65 reply_title
.setText(String
.format(
66 getString(R
.string
.reply_number
), msg
.getData().getLong("replyCount")));
67 retweet_title
.setText(String
.format(
68 getString(R
.string
.retweet_number
), msg
.getData().getLong("retweetCount")));
69 if(msg
.getData().getLong("replyCount")>0 || msg
.getData().getLong("retweetCount")>0){
70 mHandler
.post( new Thread(){
75 List
<Comment
> comments
= weibo
.getComments(mMid
+"");
76 for(Comment comment
: comments
){
77 mComments
.add(comment
.getText());
79 mReplyAdapter
.notifyDataSetChanged();
80 List
<Status
> reposts
= weibo
.getreposttimeline(mMid
+"");
81 for(Status repost
: reposts
){
82 mRetweet
.add(repost
.getText());
84 mRetweetAdapter
.notifyDataSetChanged();
85 } catch (WeiboException e
) {
86 // TODO Auto-generated catch block
89 ProgressBar proBar
= (ProgressBar
)findViewById(R
.id
.updateProgressBar
);
90 proBar
.setVisibility(View
.INVISIBLE
);
94 ProgressBar proBar
= (ProgressBar
)findViewById(R
.id
.updateProgressBar
);
95 proBar
.setVisibility(View
.INVISIBLE
);
100 super.handleMessage(msg
);
105 protected void onCreate(Bundle savedInstanceState
) {
106 setContentView(R
.layout
.message_detail
);
107 super.onCreate(savedInstanceState
);
108 TabHost tabHost
= getTabHost();
109 weibo
= OAuthConstant
.getInstance().getWeibo();
110 LayoutInflater
.from(this).inflate(R
.layout
.message_detail_tab_body
,
111 tabHost
.getTabContentView(), true);
112 TabWidget tw
= tabHost
.getTabWidget();
113 LinearLayout reply
= (LinearLayout
) LayoutInflater
.from(this).inflate(
114 R
.layout
.tab_indicator
, tw
, false);
115 reply_title
= (TextView
) reply
.getChildAt(0);
116 reply_title
.setText(String
.format(
117 getString(R
.string
.reply_number
), "*"));
118 LinearLayout retweet
= (LinearLayout
) LayoutInflater
.from(this)
119 .inflate(R
.layout
.tab_indicator
, tw
, false);
120 retweet_title
= (TextView
) retweet
.getChildAt(0);
121 retweet_title
.setText(String
.format(
122 getString(R
.string
.reply_number
), "*"));
123 tabHost
.addTab(tabHost
.newTabSpec("tab1").setIndicator(reply
)
124 .setContent(R
.id
.reply_list
));
125 tabHost
.addTab(tabHost
.newTabSpec("tab2").setIndicator(retweet
)
126 .setContent(R
.id
.retweet_list
));
127 StatusView statusView
= (StatusView
) findViewById(R
.id
.status_view
);
128 statusView
.getUser_name().setText(getIntent().getStringExtra("name"));
129 statusView
.getContent().setText(getIntent().getStringExtra("content"));
130 mImageView
= statusView
.getFace();
131 mImageView
.setBackgroundResource(R
.drawable
.face
);
133 ListView replyListView
= (ListView
)findViewById(R
.id
.reply_list
);
134 mComments
= new ArrayList
<String
>();
135 mReplyAdapter
= new ArrayAdapter
<String
>(getBaseContext(),android
.R
.layout
.simple_list_item_1
,mComments
);
136 replyListView
.setAdapter(mReplyAdapter
);
137 replyListView
= (ListView
)findViewById(R
.id
.retweet_list
);
138 mRetweet
= new ArrayList
<String
>();
139 mRetweetAdapter
= new ArrayAdapter
<String
>(getBaseContext(),android
.R
.layout
.simple_list_item_1
,mRetweet
);
140 replyListView
.setAdapter(mRetweetAdapter
);
141 new LoadingThread(getIntent().getStringExtra("face_url")).start();
142 new ContentThread().start();
147 protected void onStart() {
153 private class LoadingThread
extends Thread
{
157 LoadingThread(String url
) {
163 mDrawable
= AsyncImageLoader
.loadImageFromUrl(getBaseContext(),
165 mHandler
.obtainMessage(UPDATEFACE
).sendToTarget();
171 private class ContentThread
extends Thread
{
174 * @see java.lang.Thread#run()
178 mMid
= getIntent().getLongExtra("id", 0) ;
180 // List<Comment> comments = weibo.getComments(id);
181 // Log.e(TAG, "Comment = " + comments.get(0).toString());
182 List
<Count
> counts
= weibo
.getCounts(mMid
+ "");
185 Log
.e(TAG
, "counts = " + counts
.get(0).toString());
187 Message msg
= new Message();
188 Bundle bundle
= new Bundle();
189 bundle
.putLong("replyCount", counts
.get(0)
191 bundle
.putLong("retweetCount", counts
.get(0)
194 msg
.what
=UPDATECONTENT
;
195 mHandler
.sendMessage(msg
);
196 } catch (WeiboException e
) {
197 // TODO Auto-generated catch block