update ui layout
[freespace.git] / weibosrc / com / weibo / sina / MessageDetail.java
blobd05ffcc9305ae459afb80e56d51792450c8e5c47
2 package com.weibo.sina;
4 import java.util.ArrayList;
5 import java.util.List;
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;
58 private long mMid;
60 private Handler mHandler = new Handler() {
62 @Override
63 public void handleMessage(Message msg) {
64 switch (msg.what) {
65 case UPDATEFACE: // 更新用户头像
66 mImageView.setBackgroundDrawable(mDrawable);
67 mImageView.invalidate();
68 break;
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() {
77 @Override
78 public void run() {
79 try {
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(
87 mMid + "");
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
94 e.printStackTrace();
96 ProgressBar proBar = (ProgressBar) findViewById(R.id.updateProgressBar);
97 proBar.setVisibility(View.INVISIBLE);
99 });
100 } else {
101 ProgressBar proBar = (ProgressBar) findViewById(R.id.updateProgressBar);
102 proBar.setVisibility(View.INVISIBLE);
105 break;
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();
151 @Override
152 protected void onStart() {
154 super.onStart();
157 private class LoadingThread extends Thread {
159 String mUrl;
161 LoadingThread(String url) {
162 mUrl = url;
165 @Override
166 public void run() {
167 mDrawable = AsyncImageLoader.loadImageFromUrl(getBaseContext(), mUrl);
168 mHandler.obtainMessage(UPDATEFACE).sendToTarget();
169 super.run();
174 private class ContentThread extends Thread {
177 * (non-Javadoc)
178 * @see java.lang.Thread#run()
180 @Override
181 public void run() {
182 mMid = getIntent().getLongExtra("id", 0);
183 // List<Comment> comments = weibo.getComments(id);
184 // Log.e(TAG, "Comment = " + comments.get(0).toString());
185 try {
186 mStatuses = Weibo.getInstance().showStatus(mMid);
187 } catch (com.weibo.net.WeiboException e) {
188 // TODO Auto-generated catch block
189 e.printStackTrace();
192 Message msg = new Message();
193 Bundle bundle = new Bundle();
194 bundle.putLong("replyCount", mStatuses.getComments_count());
195 bundle.putLong("retweetCount", mStatuses.getReposts_count());
196 msg.setData(bundle);
197 msg.what = UPDATECONTENT;
198 mHandler.sendMessage(msg);
199 super.run();