欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-03-02 23:05:38
...
Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
如果是自己的微博,可以干掉它
Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 

Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
下面三幅图是转播,对话以及点评界面
Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 

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

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


public class WeiboDetailActivity extends Activity {
	private DataHelper dataHelper;
	private UserInfo user;
	private MyWeiboSync weibo;
	private Handler handler;
	private AsyncImageLoader asyncImageLoader; 
	private GetDetailThread thread;
	private String weiboid;
	private String returnJsonStr;
	private JSONObject dataObj ;
	private ImageView show_headicon;
	private ImageView show_image;
	private TextView show_count_mcount;
	private ImageView show_delete;
	private TextView show_nick;
	private TextView show_email;
	private TextView show_origtext;
	private TextView show_time;
	private TextView show_from;
	private Button to_userinfo_btn;
	private Button show_star_btn;
	private Button show_back_btn;
	private TextView show_rebroad_btn;
	private TextView show_dialog_btn;
	private TextView show_remark_btn;
	private Button show_tohome_btn;
	private RelativeLayout show_top;
	private View weibodetail_bottom3_bar;
	private JSONObject source = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.weibo_detail);
		setUpViews();//设置view
		setUpListeners();//设置listenter
		asyncImageLoader = new AsyncImageLoader();
		
		Intent intent = getIntent();
		weiboid = intent.getStringExtra("weiboid");
		dataHelper = new DataHelper(WeiboDetailActivity.this);
		weibo = new MyWeiboSync();
		
		List<UserInfo> userList = dataHelper.GetUserList(false);
		
		SharedPreferences preferences = getSharedPreferences("default_user",Activity.MODE_PRIVATE);
		String nick = preferences.getString("user_default_nick", "");
		
		if (nick != "") {
			user = dataHelper.getUserByName(nick,userList);
		}
		
		weibo.setAccessTokenKey(user.getToken());
		weibo.setAccessTokenSecrect(user.getTokenSecret());
		
		handler = new DealHandler();
		thread = new GetDetailThread();
		thread.start();//开启一个线程获取数据
	}
	
	private void setUpViews(){
		show_headicon = (ImageView) findViewById(R.id.show_headicon);
		show_delete = (ImageView) findViewById(R.id.show_delete);
		show_nick = (TextView) findViewById(R.id.show_nick);
		show_email = (TextView) findViewById(R.id.show_email);
		show_origtext = (TextView) findViewById(R.id.show_origtext);
		show_image = (ImageView) findViewById(R.id.show_image);
		show_count_mcount = (TextView)findViewById(R.id.show_count_mcount);
		show_time = (TextView) findViewById(R.id.show_time);
		show_from = (TextView) findViewById(R.id.show_from);
		to_userinfo_btn = (Button) findViewById(R.id.to_userinfo_btn);
		show_star_btn = (Button) findViewById(R.id.show_star_btn);
		show_back_btn = (Button) findViewById(R.id.show_back_btn);
		weibodetail_bottom3_bar = (View)findViewById(R.id.weibo_detail_bottom_bar);
		show_rebroad_btn = (TextView)weibodetail_bottom3_bar.findViewById(R.id.show_rebroad_btn);
		show_dialog_btn = (TextView)weibodetail_bottom3_bar.findViewById(R.id.show_dialog_btn);
		show_remark_btn = (TextView)weibodetail_bottom3_bar.findViewById(R.id.show_remark_btn);
		show_tohome_btn = (Button) findViewById(R.id.show_tohome_btn);
		show_top = (RelativeLayout)findViewById(R.id.show_top);
	}
	
	private void setUpListeners(){
		show_top.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(WeiboDetailActivity.this,UserInfoActivity.class);
				try {
					intent.putExtra("name", dataObj.getString("name"));
					intent.putExtra("nick", dataObj.getString("nick"));
					intent.putExtra("origtext", dataObj.getString("origtext"));
					intent.putExtra("timestamp", TimeUtil.getStandardTime(dataObj.getLong("timestamp")));
				} catch (JSONException e) {
					e.printStackTrace();
				}
				startActivity(intent);//跳转到用户信息界面
				
			}
		});
		to_userinfo_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(WeiboDetailActivity.this,UserInfoActivity.class);
				try {
					intent.putExtra("name", dataObj.getString("name"));
					intent.putExtra("nick", dataObj.getString("nick"));
					intent.putExtra("origtext", dataObj.getString("origtext"));
					intent.putExtra("timestamp", TimeUtil.getStandardTime(dataObj.getLong("timestamp")));
				} catch (JSONException e) {
					e.printStackTrace();
				}
				startActivity(intent);//跳转到用户信息界面
			}
		});
		show_image.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				//跳到大图浏览界面.
			}
		});
		
		show_count_mcount.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				//此微博的转播和点评
				Toast.makeText(WeiboDetailActivity.this, "将显示此微博的转播和点评列表", Toast.LENGTH_SHORT).show();
			}
		});
		
		show_rebroad_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {//转播此条微博
				Intent intent = new Intent(WeiboDetailActivity.this,AddWeiboActivity.class);
				try {
					if(source!=null){
						intent.putExtra("tip", "转播 "+source.getString("nick"));
					}else{
						intent.putExtra("tip", "转播 "+dataObj.getString("nick"));
					}
					if(dataObj.getString("origtext")!=null&&!"".equals(dataObj.getString("origtext"))){
						intent.putExtra("content", "|| @"+dataObj.getString("nick")+": "+dataObj.getString("origtext"));
						intent.putExtra("reid", dataObj.getString("id"));
					}else{
						intent.putExtra("content", "|| @"+source.getString("nick")+": ");
						intent.putExtra("reid", source.getString("id"));
					}
					intent.putExtra("from_flag", "rebroad");
				} catch (JSONException e) {
					e.printStackTrace();
				}
				startActivity(intent);
			}
		});
		
		show_dialog_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {//对话此条微博所有者
				Intent intent = new Intent(WeiboDetailActivity.this,AddWeiboActivity.class);
				try {
					intent.putExtra("tip", "对话 "+dataObj.getString("nick"));
					intent.putExtra("to",dataObj.getString("name"));//对话人的name
					intent.putExtra("from_flag", "private");
					intent.putExtra("content", "");
				} catch (JSONException e) {
					e.printStackTrace();
				}
				startActivity(intent);
			}
		});
		
		show_remark_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {//点评此条微博
				Intent intent = new Intent(WeiboDetailActivity.this,AddWeiboActivity.class);
				try {
					if(source!=null){
						intent.putExtra("tip", "点评 "+source.getString("nick"));
					}else{
						intent.putExtra("tip", "点评 "+dataObj.getString("nick"));
					}
					if(dataObj.getString("origtext")!=null&&!"".equals(dataObj.getString("origtext"))){
						intent.putExtra("content", "|| @"+dataObj.getString("nick")+": "+dataObj.getString("origtext"));
						intent.putExtra("reid", dataObj.getString("id"));
					}else{
						intent.putExtra("content", "|| @"+source.getString("nick")+": ");
						intent.putExtra("reid", source.getString("id"));
					}
					intent.putExtra("from_flag", "comment");
				} catch (JSONException e) {
					e.printStackTrace();
				}
				startActivity(intent);
			}
		});
		
	}
	
	class GetDetailThread extends Thread {
		@Override
		public void run() {
			returnJsonStr = weibo.getWeiboDetail(weibo.getAccessTokenKey(), weibo.getAccessTokenSecrect(), weiboid);
			Message msg = handler.obtainMessage();
			handler.sendMessage(msg);
		}
	}
	
	class DealHandler extends Handler { 
		@Override
		public void handleMessage(Message msg){
			Drawable cachedImage;
			try {
				dataObj = new JSONObject(returnJsonStr).getJSONObject("data");
				
				cachedImage = asyncImageLoader.loadDrawable(dataObj.getString("head")+"/100",show_headicon, new ImageCallback(){
	                @Override
	                public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {
	                    imageView.setImageDrawable(imageDrawable);
	                }
	            });
				if (cachedImage == null) {
					show_headicon.setImageResource(R.drawable.icon);
				} else {
					show_headicon.setImageDrawable(cachedImage);
				}
				
				String count_mcount_text = "转播和点评("+(dataObj.getInt("count")+dataObj.getInt("mcount"))+")";//加下划线
				SpannableStringBuilder underlineSpannable=new SpannableStringBuilder(count_mcount_text);
				CharacterStyle span=new UnderlineSpan();  
				underlineSpannable.setSpan(span, 0, count_mcount_text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				show_count_mcount.setText(underlineSpannable);
				
				
				show_nick.setText(dataObj.getString("nick"));
				show_email.setText("@"+dataObj.getString("name"));
				show_origtext.setText(dataObj.getString("origtext"));
				show_time.setText(TimeUtil.getStandardTime(dataObj.getLong("timestamp")));
				show_from.setText("来自"+dataObj.getString("from"));
				if(dataObj.getString("nick").equals(user.getUserName())){
					show_delete.setVisibility(View.VISIBLE);
				}
				
				JSONArray imageArray = dataObj.optJSONArray("image");//如果此微博有图片内容,就显示出来
				if(imageArray!=null&&imageArray.length()>0){
					String imageUrl = imageArray.optString(0)+"/460";//为什么加/460,腾讯规定的,支持160,2000,460还有一些,记不住了
					Drawable drawable = asyncImageLoader.loadDrawable(imageUrl,show_image, new ImageCallback(){
		                @Override
		                public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {
		                    imageView.setImageDrawable(imageDrawable);
		                }
		            });
					show_image.setVisibility(View.VISIBLE);
				}
				
				if(!"null".equals(dataObj.getString("source"))){
					source = dataObj.getJSONObject("source");
				}
				
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/widget28"
	android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffffff"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<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">
		<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"/>
		<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"
			android:layout_height="wrap_content"/>
		<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"
			android:layout_height="wrap_content" android:layout_below="@id/show_nick"/>
		<Button android:id="@+id/to_userinfo_btn" android:layout_width="wrap_content" android:background="@drawable/arrow_more_info_selector"
			android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
	</RelativeLayout>
	<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/show_top" android:paddingTop="5.0dip">
		<TextView android:id="@+id/show_origtext" android:layout_width="fill_parent" android:layout_marginLeft="5.0dip" android:textSize="16.0sp" android:textColor="#707878"
			android:layout_height="wrap_content"/>
		<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"/>
		<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"/>
		<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"
			android:layout_height="wrap_content" android:layout_below="@id/show_count_mcount"/>
		<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"
			android:layout_height="wrap_content" android:layout_below="@id/show_count_mcount" android:layout_toRightOf="@id/show_time"/>
		<Button android:id="@+id/show_star_btn" android:layout_width="wrap_content" android:layout_marginRight="5.0dip" android:layout_marginTop="10.0dip"
			android:layout_height="wrap_content" android:background="@drawable/btn_fav" android:layout_below="@id/show_count_mcount" android:layout_alignParentRight="true"/>
		<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"/>
	</RelativeLayout>
	<RelativeLayout android:layout_width="fill_parent" android:layout_height="40.0dip" android:layout_alignParentBottom="true">
		<Button android:id="@+id/show_back_btn" android:layout_width="40.0dip" android:drawableTop="@drawable/btn_back_selector" android:background="@drawable/bottom_back_bg"
			android:layout_height="40.0dip"  android:layout_alignParentLeft="true"/>
		<LinearLayout  android:layout_width="wrap_content" android:layout_height="wrap_content"	android:layout_marginLeft="70.0dip">
			<include android:id="@+id/weibo_detail_bottom_bar" layout="@layout/weibodetail_bottombar_3"/>
		</LinearLayout>
		<Button android:id="@+id/show_tohome_btn" android:layout_width="40.0dip"
			android:layout_height="40.0dip" android:drawableTop="@drawable/btn_home_selector" android:background="@drawable/bottom_home_bg" android:layout_alignParentRight="true"/>
	</RelativeLayout>
</RelativeLayout>


<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:orientation="horizontal" android:id="@id/bottom_bar" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <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" />
    <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" />
    <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" />
</LinearLayout>
  • Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
  • 大小: 57.9 KB
  • Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
  • 大小: 67.2 KB
  • Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
  • 大小: 42 KB
  • Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
  • 大小: 53.1 KB
  • Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
  • 大小: 25.1 KB
  • Android腾讯微薄客户端开发八:微博查看(转播,对话,点评)
            
    
    博客分类: 腾讯微博客户端 Android 
  • 大小: 52.7 KB
相关标签: Android