Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)

 
如果是自己的微博,可以干掉它 
 

 
下面三幅图是转播,对话以及点评界面 
 

 

 


Java代码  收藏代码
  1. public class WeiboDetailActivity extends Activity {  
  2.     private DataHelper dataHelper;  
  3.     private UserInfo user;  
  4.     private MyWeiboSync weibo;  
  5.     private Handler handler;  
  6.     private AsyncImageLoader asyncImageLoader;   
  7.     private GetDetailThread thread;  
  8.     private String weiboid;  
  9.     private String returnJsonStr;  
  10.     private JSONObject dataObj ;  
  11.     private ImageView show_headicon;  
  12.     private ImageView show_image;  
  13.     private TextView show_count_mcount;  
  14.     private ImageView show_delete;  
  15.     private TextView show_nick;  
  16.     private TextView show_email;  
  17.     private TextView show_origtext;  
  18.     private TextView show_time;  
  19.     private TextView show_from;  
  20.     private Button to_userinfo_btn;  
  21.     private Button show_star_btn;  
  22.     private Button show_back_btn;  
  23.     private TextView show_rebroad_btn;  
  24.     private TextView show_dialog_btn;  
  25.     private TextView show_remark_btn;  
  26.     private Button show_tohome_btn;  
  27.     private RelativeLayout show_top;  
  28.     private View weibodetail_bottom3_bar;  
  29.     private JSONObject source = null;  
  30.   
  31.     @Override  
  32.     protected void onCreate(Bundle savedInstanceState) {  
  33.         super.onCreate(savedInstanceState);  
  34.         setContentView(R.layout.weibo_detail);  
  35.         setUpViews();//设置view  
  36.         setUpListeners();//设置listenter  
  37.         asyncImageLoader = new AsyncImageLoader();  
  38.           
  39.         Intent intent = getIntent();  
  40.         weiboid = intent.getStringExtra("weiboid");  
  41.         dataHelper = new DataHelper(WeiboDetailActivity.this);  
  42.         weibo = new MyWeiboSync();  
  43.           
  44.         List<UserInfo> userList = dataHelper.GetUserList(false);  
  45.           
  46.         SharedPreferences preferences = getSharedPreferences("default_user",Activity.MODE_PRIVATE);  
  47.         String nick = preferences.getString("user_default_nick""");  
  48.           
  49.         if (nick != "") {  
  50.             user = dataHelper.getUserByName(nick,userList);  
  51.         }  
  52.           
  53.         weibo.setAccessTokenKey(user.getToken());  
  54.         weibo.setAccessTokenSecrect(user.getTokenSecret());  
  55.           
  56.         handler = new DealHandler();  
  57.         thread = new GetDetailThread();  
  58.         thread.start();//开启一个线程获取数据  
  59.     }  
  60.       
  61.     private void setUpViews(){  
  62.         show_headicon = (ImageView) findViewById(R.id.show_headicon);  
  63.         show_delete = (ImageView) findViewById(R.id.show_delete);  
  64.         show_nick = (TextView) findViewById(R.id.show_nick);  
  65.         show_email = (TextView) findViewById(R.id.show_email);  
  66.         show_origtext = (TextView) findViewById(R.id.show_origtext);  
  67.         show_image = (ImageView) findViewById(R.id.show_image);  
  68.         show_count_mcount = (TextView)findViewById(R.id.show_count_mcount);  
  69.         show_time = (TextView) findViewById(R.id.show_time);  
  70.         show_from = (TextView) findViewById(R.id.show_from);  
  71.         to_userinfo_btn = (Button) findViewById(R.id.to_userinfo_btn);  
  72.         show_star_btn = (Button) findViewById(R.id.show_star_btn);  
  73.         show_back_btn = (Button) findViewById(R.id.show_back_btn);  
  74.         weibodetail_bottom3_bar = (View)findViewById(R.id.weibo_detail_bottom_bar);  
  75.         show_rebroad_btn = (TextView)weibodetail_bottom3_bar.findViewById(R.id.show_rebroad_btn);  
  76.         show_dialog_btn = (TextView)weibodetail_bottom3_bar.findViewById(R.id.show_dialog_btn);  
  77.         show_remark_btn = (TextView)weibodetail_bottom3_bar.findViewById(R.id.show_remark_btn);  
  78.         show_tohome_btn = (Button) findViewById(R.id.show_tohome_btn);  
  79.         show_top = (RelativeLayout)findViewById(R.id.show_top);  
  80.     }  
  81.       
  82.     private void setUpListeners(){  
  83.         show_top.setOnClickListener(new OnClickListener() {  
  84.             @Override  
  85.             public void onClick(View v) {  
  86.                 Intent intent = new Intent(WeiboDetailActivity.this,UserInfoActivity.class);  
  87.                 try {  
  88.                     intent.putExtra("name", dataObj.getString("name"));  
  89.                     intent.putExtra("nick", dataObj.getString("nick"));  
  90.                     intent.putExtra("origtext", dataObj.getString("origtext"));  
  91.                     intent.putExtra("timestamp", TimeUtil.getStandardTime(dataObj.getLong("timestamp")));  
  92.                 } catch (JSONException e) {  
  93.                     e.printStackTrace();  
  94.                 }  
  95.                 startActivity(intent);//跳转到用户信息界面  
  96.                   
  97.             }  
  98.         });  
  99.         to_userinfo_btn.setOnClickListener(new OnClickListener() {  
  100.             @Override  
  101.             public void onClick(View v) {  
  102.                 Intent intent = new Intent(WeiboDetailActivity.this,UserInfoActivity.class);  
  103.                 try {  
  104.                     intent.putExtra("name", dataObj.getString("name"));  
  105.                     intent.putExtra("nick", dataObj.getString("nick"));  
  106.                     intent.putExtra("origtext", dataObj.getString("origtext"));  
  107.                     intent.putExtra("timestamp", TimeUtil.getStandardTime(dataObj.getLong("timestamp")));  
  108.                 } catch (JSONException e) {  
  109.                     e.printStackTrace();  
  110.                 }  
  111.                 startActivity(intent);//跳转到用户信息界面  
  112.             }  
  113.         });  
  114.         show_image.setOnClickListener(new OnClickListener() {  
  115.             @Override  
  116.             public void onClick(View arg0) {  
  117.                 //跳到大图浏览界面.  
  118.             }  
  119.         });  
  120.           
  121.         show_count_mcount.setOnClickListener(new OnClickListener() {  
  122.             @Override  
  123.             public void onClick(View arg0) {  
  124.                 //此微博的转播和点评  
  125.                 Toast.makeText(WeiboDetailActivity.this"将显示此微博的转播和点评列表", Toast.LENGTH_SHORT).show();  
  126.             }  
  127.         });  
  128.           
  129.         show_rebroad_btn.setOnClickListener(new OnClickListener() {  
  130.             @Override  
  131.             public void onClick(View arg0) {//转播此条微博  
  132.                 Intent intent = new Intent(WeiboDetailActivity.this,AddWeiboActivity.class);  
  133.                 try {  
  134.                     if(source!=null){  
  135.                         intent.putExtra("tip""转播 "+source.getString("nick"));  
  136.                     }else{  
  137.                         intent.putExtra("tip""转播 "+dataObj.getString("nick"));  
  138.                     }  
  139.                     if(dataObj.getString("origtext")!=null&&!"".equals(dataObj.getString("origtext"))){  
  140.                         intent.putExtra("content""|| @"+dataObj.getString("nick")+": "+dataObj.getString("origtext"));  
  141.                         intent.putExtra("reid", dataObj.getString("id"));  
  142.                     }else{  
  143.                         intent.putExtra("content""|| @"+source.getString("nick")+": ");  
  144.                         intent.putExtra("reid", source.getString("id"));  
  145.                     }  
  146.                     intent.putExtra("from_flag""rebroad");  
  147.                 } catch (JSONException e) {  
  148.                     e.printStackTrace();  
  149.                 }  
  150.                 startActivity(intent);  
  151.             }  
  152.         });  
  153.           
  154.         show_dialog_btn.setOnClickListener(new OnClickListener() {  
  155.             @Override  
  156.             public void onClick(View arg0) {//对话此条微博所有者  
  157.                 Intent intent = new Intent(WeiboDetailActivity.this,AddWeiboActivity.class);  
  158.                 try {  
  159.                     intent.putExtra("tip""对话 "+dataObj.getString("nick"));  
  160.                     intent.putExtra("to",dataObj.getString("name"));//对话人的name  
  161.                     intent.putExtra("from_flag""private");  
  162.                     intent.putExtra("content""");  
  163.                 } catch (JSONException e) {  
  164.                     e.printStackTrace();  
  165.                 }  
  166.                 startActivity(intent);  
  167.             }  
  168.         });  
  169.           
  170.         show_remark_btn.setOnClickListener(new OnClickListener() {  
  171.             @Override  
  172.             public void onClick(View arg0) {//点评此条微博  
  173.                 Intent intent = new Intent(WeiboDetailActivity.this,AddWeiboActivity.class);  
  174.                 try {  
  175.                     if(source!=null){  
  176.                         intent.putExtra("tip""点评 "+source.getString("nick"));  
  177.                     }else{  
  178.                         intent.putExtra("tip""点评 "+dataObj.getString("nick"));  
  179.                     }  
  180.                     if(dataObj.getString("origtext")!=null&&!"".equals(dataObj.getString("origtext"))){  
  181.                         intent.putExtra("content""|| @"+dataObj.getString("nick")+": "+dataObj.getString("origtext"));  
  182.                         intent.putExtra("reid", dataObj.getString("id"));  
  183.                     }else{  
  184.                         intent.putExtra("content""|| @"+source.getString("nick")+": ");  
  185.                         intent.putExtra("reid", source.getString("id"));  
  186.                     }  
  187.                     intent.putExtra("from_flag""comment");  
  188.                 } catch (JSONException e) {  
  189.                     e.printStackTrace();  
  190.                 }  
  191.                 startActivity(intent);  
  192.             }  
  193.         });  
  194.           
  195.     }  
  196.       
  197.     class GetDetailThread extends Thread {  
  198.         @Override  
  199.         public void run() {  
  200.             returnJsonStr = weibo.getWeiboDetail(weibo.getAccessTokenKey(), weibo.getAccessTokenSecrect(), weiboid);  
  201.             Message msg = handler.obtainMessage();  
  202.             handler.sendMessage(msg);  
  203.         }  
  204.     }  
  205.       
  206.     class DealHandler extends Handler {   
  207.         @Override  
  208.         public void handleMessage(Message msg){  
  209.             Drawable cachedImage;  
  210.             try {  
  211.                 dataObj = new JSONObject(returnJsonStr).getJSONObject("data");  
  212.                   
  213.                 cachedImage = asyncImageLoader.loadDrawable(dataObj.getString("head")+"/100",show_headicon, new ImageCallback(){  
  214.                     @Override  
  215.                     public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {  
  216.                         imageView.setImageDrawable(imageDrawable);  
  217.                     }  
  218.                 });  
  219.                 if (cachedImage == null) {  
  220.                     show_headicon.setImageResource(R.drawable.icon);  
  221.                 } else {  
  222.                     show_headicon.setImageDrawable(cachedImage);  
  223.                 }  
  224.                   
  225.                 String count_mcount_text = "转播和点评("+(dataObj.getInt("count")+dataObj.getInt("mcount"))+")";//加下划线  
  226.                 SpannableStringBuilder underlineSpannable=new SpannableStringBuilder(count_mcount_text);  
  227.                 CharacterStyle span=new UnderlineSpan();    
  228.                 underlineSpannable.setSpan(span, 0, count_mcount_text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
  229.                 show_count_mcount.setText(underlineSpannable);  
  230.                   
  231.                   
  232.                 show_nick.setText(dataObj.getString("nick"));  
  233.                 show_email.setText("@"+dataObj.getString("name"));  
  234.                 show_origtext.setText(dataObj.getString("origtext"));  
  235.                 show_time.setText(TimeUtil.getStandardTime(dataObj.getLong("timestamp")));  
  236.                 show_from.setText("来自"+dataObj.getString("from"));  
  237.                 if(dataObj.getString("nick").equals(user.getUserName())){  
  238.                     show_delete.setVisibility(View.VISIBLE);  
  239.                 }  
  240.                   
  241.                 JSONArray imageArray = dataObj.optJSONArray("image");//如果此微博有图片内容,就显示出来  
  242.                 if(imageArray!=null&&imageArray.length()>0){  
  243.                     String imageUrl = imageArray.optString(0)+"/460";//为什么加/460,腾讯规定的,支持160,2000,460还有一些,记不住了  
  244.                     Drawable drawable = asyncImageLoader.loadDrawable(imageUrl,show_image, new ImageCallback(){  
  245.                         @Override  
  246.                         public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {  
  247.                             imageView.setImageDrawable(imageDrawable);  
  248.                         }  
  249.                     });  
  250.                     show_image.setVisibility(View.VISIBLE);  
  251.                 }  
  252.                   
  253.                 if(!"null".equals(dataObj.getString("source"))){  
  254.                     source = dataObj.getJSONObject("source");  
  255.                 }  
  256.                   
  257.             } catch (JSONException e) {  
  258.                 e.printStackTrace();  
  259.             }  
  260.         }  
  261.     }  
  262. }  


Java代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout android:id="@+id/widget28"  
  3.     android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffffff"  
  4.     xmlns:android="http://schemas.android.com/apk/res/android">  
  5.     <RelativeLayout android:id="@+id/show_top" android:paddingTop="5.0dip" android:layout_width="fill_parent" android:layout_height="60.0dip" android:background="#c7cbd6" android:layout_alignParentTop="true" android:layout_centerHorizontal="true">  
  6.         <ImageView android:id="@+id/show_headicon" android:layout_marginLeft="8.0dip" android:layout_width="45.0dip" android:layout_height="45.0dip" android:layout_alignParentLeft="true"/>  
  7.         <TextView android:id="@+id/show_nick" android:layout_marginLeft="5.0dip" android:layout_width="wrap_content" android:layout_toRightOf="@id/show_headicon" android:textColor="#384050"  
  8.             android:layout_height="wrap_content"/>  
  9.         <TextView android:id="@+id/show_email" android:layout_width="wrap_content" android:layout_marginLeft="10.0dip" android:layout_toRightOf="@id/show_headicon" android:textColor="#687888"  
  10.             android:layout_height="wrap_content" android:layout_below="@id/show_nick"/>  
  11.         <Button android:id="@+id/to_userinfo_btn" android:layout_width="wrap_content" android:background="@drawable/arrow_more_info_selector"  
  12.             android:layout_height="wrap_content" android:layout_alignParentRight="true"/>  
  13.     </RelativeLayout>  
  14.     <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/show_top" android:paddingTop="5.0dip">  
  15.         <TextView android:id="@+id/show_origtext" android:layout_width="fill_parent" android:layout_marginLeft="5.0dip" android:textSize="16.0sp" android:textColor="#707878"  
  16.             android:layout_height="wrap_content"/>  
  17.         <ImageView android:id="@+id/show_image" android:visibility="gone" android:layout_centerInParent="true" android:layout_below="@id/show_origtext" android:layout_width="fill_parent" android:layout_height="120.0dip"/>  
  18.         <TextView android:id="@+id/show_count_mcount" android:layout_below="@id/show_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18.0sp" android:textColor="#1d5884"/>  
  19.         <TextView android:id="@+id/show_time" android:layout_width="wrap_content" android:layout_marginLeft="5.0dip" android:layout_marginTop="10.0dip" android:textSize="12.0sp"  
  20.             android:layout_height="wrap_content" android:layout_below="@id/show_count_mcount"/>  
  21.         <TextView android:id="@+id/show_from" android:layout_width="wrap_content" android:layout_marginLeft="3.0dip" android:layout_marginTop="10.0dip" android:textSize="12.0sp"  
  22.             android:layout_height="wrap_content" android:layout_below="@id/show_count_mcount" android:layout_toRightOf="@id/show_time"/>  
  23.         <Button android:id="@+id/show_star_btn" android:layout_width="wrap_content" android:layout_marginRight="5.0dip" android:layout_marginTop="10.0dip"  
  24.             android:layout_height="wrap_content" android:background="@drawable/btn_fav" android:layout_below="@id/show_count_mcount" android:layout_alignParentRight="true"/>  
  25.         <ImageView android:id="@+id/show_delete" android:src="@drawable/delete" android:layout_width="wrap_content" android:layout_marginRight="3.0dip" android:layout_marginTop="10.0dip" android:visibility="invisible" android:layout_height="wrap_content" android:layout_below="@id/show_count_mcount" android:layout_toLeftOf="@id/show_star_btn"/>  
  26.     </RelativeLayout>  
  27.     <RelativeLayout android:layout_width="fill_parent" android:layout_height="40.0dip" android:layout_alignParentBottom="true">  
  28.         <Button android:id="@+id/show_back_btn" android:layout_width="40.0dip" android:drawableTop="@drawable/btn_back_selector" android:background="@drawable/bottom_back_bg"  
  29.             android:layout_height="40.0dip"  android:layout_alignParentLeft="true"/>  
  30.         <LinearLayout  android:layout_width="wrap_content" android:layout_height="wrap_content"  android:layout_marginLeft="70.0dip">  
  31.             <include android:id="@+id/weibo_detail_bottom_bar" layout="@layout/weibodetail_bottombar_3"/>  
  32.         </LinearLayout>  
  33.         <Button android:id="@+id/show_tohome_btn" android:layout_width="40.0dip"  
  34.             android:layout_height="40.0dip" android:drawableTop="@drawable/btn_home_selector" android:background="@drawable/bottom_home_bg" android:layout_alignParentRight="true"/>  
  35.     </RelativeLayout>  
  36. </RelativeLayout>  


Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <LinearLayout android:orientation="horizontal" android:id="@id/bottom_bar" android:layout_width="fill_parent" android:layout_height="fill_parent"  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <TextView android:textSize="16.0dip" android:text="转播" android:textColor="@color/bottom_button_text_selector" android:gravity="center" android:id="@+id/show_rebroad_btn" android:background="@drawable/bottom_3btn_l_selector" android:focusable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />  
  5.     <TextView android:textSize="16.0dip" android:text="对话" android:textColor="@color/bottom_button_text_selector" android:gravity="center" android:id="@+id/show_dialog_btn" android:background="@drawable/bottom_3btn_m_selector" android:focusable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />  
  6.     <TextView android:textSize="16.0dip" android:text="点评" android:textColor="@color/bottom_button_text_selector" android:gravity="center" android:id="@+id/show_remark_btn" android:background="@drawable/bottom_3btn_r_selector" android:focusable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />  
  7. </LinearLayout>  
posted @ 2012-02-20 17:27  aflylove  阅读(303)  评论(0编辑  收藏  举报