2 package com
.weibo
.sina
;
4 import java
.util
.ArrayList
;
7 import com
.weibo
.json
.Comment
;
8 import com
.weibo
.json
.Comments
;
9 import com
.weibo
.json
.Reposts
;
10 import com
.weibo
.client
.Weibo
;
11 import android
.app
.TabActivity
;
12 import android
.graphics
.drawable
.Drawable
;
13 import android
.os
.Bundle
;
14 import android
.os
.Handler
;
15 import android
.os
.Message
;
16 import android
.util
.Log
;
17 import android
.view
.LayoutInflater
;
18 import android
.view
.View
;
19 import android
.widget
.ArrayAdapter
;
20 import android
.widget
.ImageView
;
21 import android
.widget
.LinearLayout
;
22 import android
.widget
.ListView
;
23 import android
.widget
.ProgressBar
;
24 import android
.widget
.TabHost
;
25 import android
.widget
.TabWidget
;
26 import android
.widget
.TextView
;
28 import com
.weibo
.json
.Statuses
;
29 import com
.weibo
.util
.AsyncImageLoader
;
30 import com
.weibo
.view
.StatusView
;
32 public class MessageDetail
extends TabActivity
{
34 private TextView reply_title
;
36 private TextView retweet_title
;
38 private ImageView mImageView
;
40 private Drawable mDrawable
= null;
42 private static final int UPDATEFACE
= 0x00;
44 private static final int UPDATECONTENT
= 0x01;
46 private static final String TAG
= "MessageDetail";
48 private List
<String
> mComments
;
50 private ArrayAdapter
<String
> mReplyAdapter
;
52 private List
<String
> mRetweet
;
54 private ArrayAdapter
<String
> mRetweetAdapter
;
56 private Statuses mStatuses
;
60 private Handler mHandler
= new Handler() {
63 public void handleMessage(Message msg
) {
65 case UPDATEFACE
: // 更新用户头像
66 mImageView
.setBackgroundDrawable(mDrawable
);
67 mImageView
.invalidate();
69 case UPDATECONTENT
: // 更新用户评论,转发数
70 reply_title
.setText(String
.format(getString(R
.string
.reply_number
), msg
71 .getData().getLong("replyCount")));
72 retweet_title
.setText(String
.format(getString(R
.string
.retweet_number
), msg
73 .getData().getLong("retweetCount")));
74 if (msg
.getData().getLong("replyCount") > 0
75 || msg
.getData().getLong("retweetCount") > 0) {
76 mHandler
.post(new Thread() {
80 Comments comments
= Weibo
.getInstance().getComments(mMid
+ "");
82 for (Comment comment
: comments
.getComments()) {
83 mComments
.add(comment
.getText());
85 mReplyAdapter
.notifyDataSetChanged();
86 Reposts reposts
= Weibo
.getInstance().getReposttimeline(
88 for (Statuses repost
: reposts
.getReposts()) {
89 mRetweet
.add(repost
.getText());
91 mRetweetAdapter
.notifyDataSetChanged();
92 } catch (com
.weibo
.net
.WeiboException e
) {
93 // TODO Auto-generated catch block
96 ProgressBar proBar
= (ProgressBar
) findViewById(R
.id
.updateProgressBar
);
97 proBar
.setVisibility(View
.INVISIBLE
);
101 ProgressBar proBar
= (ProgressBar
) findViewById(R
.id
.updateProgressBar
);
102 proBar
.setVisibility(View
.INVISIBLE
);
107 super.handleMessage(msg
);
112 protected void onCreate(Bundle savedInstanceState
) {
113 setContentView(R
.layout
.message_detail
);
114 super.onCreate(savedInstanceState
);
115 TabHost tabHost
= getTabHost();
116 LayoutInflater
.from(this).inflate(R
.layout
.message_detail_tab_body
,
117 tabHost
.getTabContentView(), true);
118 TabWidget tw
= tabHost
.getTabWidget();
119 LinearLayout reply
= (LinearLayout
) LayoutInflater
.from(this).inflate(
120 R
.layout
.tab_indicator
, tw
, false);
121 reply_title
= (TextView
) reply
.getChildAt(0);
122 reply_title
.setText(String
.format(getString(R
.string
.reply_number
), "*"));
123 LinearLayout retweet
= (LinearLayout
) LayoutInflater
.from(this).inflate(
124 R
.layout
.tab_indicator
, tw
, false);
125 retweet_title
= (TextView
) retweet
.getChildAt(0);
126 retweet_title
.setText(String
.format(getString(R
.string
.reply_number
), "*"));
127 tabHost
.addTab(tabHost
.newTabSpec("tab1").setIndicator(reply
).setContent(R
.id
.reply_list
));
128 tabHost
.addTab(tabHost
.newTabSpec("tab2").setIndicator(retweet
)
129 .setContent(R
.id
.retweet_list
));
130 StatusView statusView
= (StatusView
) findViewById(R
.id
.status_view
);
131 statusView
.getUser_name().setText(getIntent().getStringExtra("name"));
132 statusView
.getContent().setText(getIntent().getStringExtra("content"));
133 mImageView
= statusView
.getFace();
134 mImageView
.setBackgroundResource(R
.drawable
.face
);
136 ListView replyListView
= (ListView
) findViewById(R
.id
.reply_list
);
137 mComments
= new ArrayList
<String
>();
138 mReplyAdapter
= new ArrayAdapter
<String
>(getBaseContext(),
139 android
.R
.layout
.simple_list_item_1
, mComments
);
140 replyListView
.setAdapter(mReplyAdapter
);
141 replyListView
= (ListView
) findViewById(R
.id
.retweet_list
);
142 mRetweet
= new ArrayList
<String
>();
143 mRetweetAdapter
= new ArrayAdapter
<String
>(getBaseContext(),
144 android
.R
.layout
.simple_list_item_1
, mRetweet
);
145 replyListView
.setAdapter(mRetweetAdapter
);
146 new LoadingThread(getIntent().getStringExtra("face_url")).start();
147 new ContentThread().start();
152 protected void onStart() {
157 private class LoadingThread
extends Thread
{
161 LoadingThread(String url
) {
167 mDrawable
= AsyncImageLoader
.loadImageFromUrl(getBaseContext(), mUrl
);
168 mHandler
.obtainMessage(UPDATEFACE
).sendToTarget();
174 private class ContentThread
extends Thread
{
178 * @see java.lang.Thread#run()
182 mMid
= getIntent().getLongExtra("id", 0);
183 // List<Comment> comments = weibo.getComments(id);
184 // Log.e(TAG, "Comment = " + comments.get(0).toString());
186 mStatuses
= Weibo
.getInstance().showStatus(mMid
);
187 } catch (com
.weibo
.net
.WeiboException e
) {
188 // TODO Auto-generated catch block
192 Message msg
= new Message();
193 Bundle bundle
= new Bundle();
194 bundle
.putLong("replyCount", mStatuses
.getComments_count());
195 bundle
.putLong("retweetCount", mStatuses
.getReposts_count());
197 msg
.what
= UPDATECONTENT
;
198 mHandler
.sendMessage(msg
);