`
helloandroid
  • 浏览: 272274 次
  • 性别: Icon_minigender_1
  • 来自: 成都
博客专栏
107f8db3-b009-3b79-938a-dafddb49ea79
Android腾讯微博客户...
浏览量:94462
社区版块
存档分类
最新评论

Android腾讯微薄客户端开发九:博主详情界面篇(广播,听众,收听)

阅读更多

点击顶部的标题栏,界面跳转到此博主的关注界面

关注界面,此界面下面的对话和点评以及上面的广播,听众和收听丑了点,没时间了,今天时间比较紧,美化的事情交给你们了。
public class UserInfoActivity extends Activity implements OnItemClickListener{
	private String currentNick;
	private String name;
	private String origtext;
	private String timestamp;
	private DataHelper dataHelper;
	private UserInfo user;
	private MyWeiboSync weibo;
	private Handler handler;
	private AsyncImageLoader asyncImageLoader; 
	private UserInfoThread thread;
	private String weiboid;
	private String returnJsonStr;
	private JSONObject dataObj ;
	private ImageView user_headicon;
	private TextView user_nick;
	private TextView user_name;
	private TextView user_origtext;
	private TextView user_time;
	private TextView user_sex;
	private TextView user_age;
	private TextView user_location;
	private TextView user_verifyinfo;
	private Button user_back_btn;
	private Button user_dialog_btn;
	private Button user_message_btn;
	private GridView gridView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_info);
		setUpViews();//设置view
		setUpListeners();//设置listenter
		asyncImageLoader = new AsyncImageLoader();
		dataHelper = new DataHelper(UserInfoActivity.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());
		
		//获取从上一界面传递过来的数据
		Intent intent = getIntent();
		name = intent.getStringExtra("name");
		currentNick = intent.getStringExtra("nick");//昵称
		origtext = intent.getStringExtra("origtext");
		timestamp = intent.getStringExtra("timestamp");
		user_name.setText("@"+name);
		user_origtext.setText(origtext);
		user_time.setText(timestamp);
		
		handler = new UserInfoHandler();
		thread = new UserInfoThread();
		thread.start();//开启一个线程获取数据
	}
	
	private void setUpViews(){
		user_headicon = (ImageView) findViewById(R.id.user_headicon);
		user_nick = (TextView) findViewById(R.id.user_nick);
		user_name = (TextView) findViewById(R.id.user_name);
		user_origtext = (TextView) findViewById(R.id.user_origtext);
		user_time = (TextView) findViewById(R.id.user_time);
		user_sex = (TextView) findViewById(R.id.user_sex);
		user_age = (TextView) findViewById(R.id.user_age);
		user_location = (TextView) findViewById(R.id.user_location);
		user_verifyinfo = (TextView) findViewById(R.id.user_verifyinfo);
		user_back_btn = (Button) findViewById(R.id.user_back_btn);
		user_dialog_btn = (Button) findViewById(R.id.user_dialog_btn);
		user_message_btn = (Button) findViewById(R.id.user_message_btn);
		gridView = (GridView)findViewById(R.id.user_grid);
	}
	
	private void setUpListeners(){
		gridView.setOnItemClickListener(this);
	}
	
	class UserInfoThread extends Thread {
		@Override
		public void run() {
			returnJsonStr = weibo.getUserInfoByName(weibo.getAccessTokenKey(), weibo.getAccessTokenSecrect(), name);
			//通知handler处理数据
			Message msg = handler.obtainMessage();
			handler.sendMessage(msg);
		}
	}
	
	class UserInfoHandler extends Handler { 
		@Override
		public void handleMessage(Message msg){
			Drawable cachedImage;
			try {
				dataObj = new JSONObject(returnJsonStr).getJSONObject("data");
				cachedImage = asyncImageLoader.loadDrawable(dataObj.getString("head")+"/100",user_headicon, new ImageCallback(){
	                @Override
	                public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {
	                    imageView.setImageDrawable(imageDrawable);
	                }
	            });
				if (cachedImage == null) {
					user_headicon.setImageResource(R.drawable.icon);
				} else {
					user_headicon.setImageDrawable(cachedImage);
				}
				user_nick.setText(dataObj.getString("nick"));
				user_sex.setText(dataObj.getInt("sex")==1?"男":"女");
				if(dataObj.getInt("birth_year")!=0){
					user_age.setText((Calendar.getInstance().get(Calendar.YEAR)-dataObj.getInt("birth_year"))+"岁");
				}
				user_location.setText(dataObj.getString("location"));
				String verifyinfo = dataObj.getString("verifyinfo");
				if(verifyinfo==null||"".equals(verifyinfo)){
					user_verifyinfo.setText("这家伙很懒,没留什么");
				}else{
					user_verifyinfo.setText(verifyinfo);
				}
				final List<String> numsList = new ArrayList<String>();
				numsList.add(dataObj.getString("tweetnum"));
				numsList.add(dataObj.getString("fansnum"));
				numsList.add(dataObj.getString("idolnum"));
				gridView.setAdapter(new GridAdapter(UserInfoActivity.this, numsList));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}
	
	class GridAdapter extends BaseAdapter {
		private Context context;
		private LayoutInflater inflater;
		List<String> numList;
		
		public GridAdapter(Context context, List<String> numList) {
			super();
			this.context = context;
			this.numList = numList;
			this.inflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			return numList.size();
		}

		@Override
		public Object getItem(int position) {
			return numList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent){
			convertView = inflater.inflate(R.layout.userinfo_grid_item, null);
			TextView num = (TextView)convertView.findViewById(R.id.userinfo_grid_num);
			TextView title = (TextView)convertView.findViewById(R.id.userinfo_grid_title);
			ImageView image = (ImageView)convertView.findViewById(R.id.userinfo_grid_image);
			switch (position) {
			case 0:
				num.setText(numList.get(0));
				title.setText("广播");
				image.setVisibility(View.VISIBLE);
				break;
			case 1:
				num.setText(numList.get(1));
				title.setText("听众");
				image.setVisibility(View.VISIBLE);
				break;
			case 2:
				num.setText(numList.get(2));
				title.setText("收听");
				break;

			default:
				break;
			}
			return convertView;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3){
		switch (position) {
		case 0:
			Intent intent = new Intent(UserInfoActivity.this,TweetsActivity.class);
			intent.putExtra("name", name);
			intent.putExtra("nick",currentNick);
			startActivity(intent);
			break;
		case 1:
			Intent intent2 = new Intent(UserInfoActivity.this,FansActivity.class);
			intent2.putExtra("name", name);
			intent2.putExtra("nick",currentNick);
			startActivity(intent2);
			break;
		case 2:
			Intent intent3 = new Intent(UserInfoActivity.this,IdolActivity.class);
			intent3.putExtra("name", name);
			intent3.putExtra("nick",currentNick);
			startActivity(intent3);
			break;
		default:
			break;
		}
		
	}
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#c0c8d0"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<RelativeLayout android:id="@+id/user_top" android:paddingTop="5.0dip" android:layout_width="fill_parent" android:layout_height="60.0dip" android:layout_alignParentTop="true" android:layout_centerHorizontal="true">
		<ImageView android:id="@+id/user_headicon" android:layout_marginLeft="8.0dip" android:layout_width="45.0dip" android:layout_height="45.0dip" android:layout_alignParentLeft="true"/>
		<TextView android:id="@+id/user_nick" android:layout_marginLeft="5.0dip" android:layout_width="wrap_content" android:layout_toRightOf="@id/user_headicon" android:textColor="#384050"
			android:layout_height="wrap_content"/>
		<TextView android:id="@+id/user_name" android:layout_width="wrap_content" android:layout_marginLeft="10.0dip" android:layout_toRightOf="@id/user_headicon" android:textColor="#687888"
			android:layout_height="wrap_content" android:layout_below="@id/user_nick"/>
	</RelativeLayout>
	<LinearLayout android:paddingLeft="10.0dip" android:paddingRight="10.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_below="@id/user_top">
		<ImageView android:background="#a0b0b0" android:layout_width="fill_parent" android:layout_height="1.0dip" android:scaleType="fitCenter"/>
		<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip">
			<GridView android:gravity="center" android:listSelector="@drawable/listitem_selector" android:id="@+id/user_grid" android:background="@drawable/userinfo_grid_bg" android:layout_width="fill_parent" android:layout_height="wrap_content" android:numColumns="3"/>
		</RelativeLayout>
		<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:background="@drawable/panel_bg">
			<TextView android:id="@+id/user_sex" android:layout_marginLeft="5.0dip" android:layout_alignParentLeft="true" android:layout_width="wrap_content"  android:textSize="12.0sp" android:textColor="#788080"
				android:layout_height="wrap_content"/>
			<TextView android:id="@+id/user_age" android:layout_toRightOf="@id/user_sex" android:layout_width="wrap_content"  android:textSize="12.0sp" android:textColor="#788080"
				android:layout_height="wrap_content"/>
			<TextView  android:id="@+id/user_location" android:layout_toRightOf="@id/user_age" android:layout_width="wrap_content" android:textSize="12.0sp" android:textColor="#788080"
				android:layout_height="wrap_content"/>
			<TextView  android:id="@+id/user_verifyinfo" android:layout_marginLeft="5.0dip" android:layout_alignParentLeft="true" android:layout_below="@id/user_sex" android:layout_width="fill_parent" android:textSize="12.0sp" android:textColor="#788080"
				android:layout_height="wrap_content"/>
		</RelativeLayout>
		<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:background="@drawable/panel_bg">
			<TextView android:text="最新广播:" android:layout_width="fill_parent" android:layout_marginLeft="5.0dip" android:textSize="12.0sp" android:textColor="#788080"
				android:layout_height="wrap_content"/>
			<TextView android:id="@+id/user_time" android:layout_width="wrap_content" android:layout_marginLeft="3.0dip" android:layout_marginTop="10.0dip" android:textSize="8.0sp" android:textColor="#788080"
				android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
			<TextView android:id="@+id/user_origtext" android:layout_width="fill_parent" android:layout_marginLeft="5.0dip" android:textSize="12.0sp" android:textColor="#788080" 
				android:layout_height="wrap_content" android:layout_below="@id/user_time" android:layout_alignParentLeft="true"/>
		</RelativeLayout>
	</LinearLayout>
	<RelativeLayout android:layout_width="fill_parent" android:layout_height="40.0dip" android:layout_alignParentBottom="true">
		<Button android:id="@+id/user_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:id="@+id/widget41" android:layout_marginLeft="60.0dip" android:layout_alignParentBottom="true"
			android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_toRightOf="@id/user_back_btn">
			<ImageView android:background="#f8f8f8" android:layout_width="1.0dip" android:layout_height="20.0dip" android:scaleType="fitCenter"/>
			<Button android:id="@+id/user_dialog_btn" android:layout_width="wrap_content" android:background="@drawable/bottom_bar_bg"
				android:layout_height="wrap_content" android:text="对话"/>
			<ImageView android:background="#f8f8f8" android:layout_width="1.0dip" android:layout_height="20.0dip" android:scaleType="fitCenter"/>
			<Button android:id="@+id/user_message_btn" android:layout_width="wrap_content" android:background="@drawable/bottom_bar_bg"
				android:layout_height="wrap_content" android:text="点评"/>
		</LinearLayout>
		<Button android:id="@+id/user_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 xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:paddingTop="3.0dip" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
	<LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">
		<TextView android:id="@+id/userinfo_grid_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#586068"/>
		<TextView android:id="@+id/userinfo_grid_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#98a0a0"/>
	</LinearLayout>
	<ImageView android:id="@+id/userinfo_grid_image" android:src="#d0d0d8" android:visibility="invisible" android:layout_width="1.0dip" android:layout_height="30.0dip" android:layout_marginLeft="30.0dip"/>
</LinearLayout>
  • 大小: 57.9 KB
  • 大小: 46.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics