(droid分享)新浪微博开发系列【三】之好友微博信息

这部分为微博的主页部分,显示我的好友所发布的微博,,在此说明一下,可能代码里调用一些方法在本篇中没有,但是全部在我的代码里,也不要索取图片,要看全部代码的请移步http://blog.csdn.net/gaojin1991/article/details/8022213

<?xml version="1.0" encoding="utf-8"?>
<!-- 该布局文件为主页的布局文件 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <!-- 微博首页标题部分 -->


    <RelativeLayout
        android:id="@+id/rlTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#BB768e95" >


        <!-- android:background="@drawable/bg_title" -->


        <ImageButton
            android:id="@+id/saysomethingImgBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="8dp"
            android:contentDescription="@string/contnetdescription"
            android:src="@drawable/toolbar_saysomething_icon" />


        <TextView
            android:id="@+id/usernameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="#000"
            android:textSize="20sp"
            android:textStyle="bold" />


        <ImageButton
            android:id="@+id/refreshImgBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="6dp"
            android:layout_marginTop="8dp"
            android:contentDescription="@string/contnetdescription"
            android:src="@drawable/toolbar_refresh_icon" />
    </RelativeLayout>


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/bg_activitycontent"
        android:orientation="vertical" >


        <!-- 微博内容部分 -->


        <ListView
            android:id="@+id/msglistView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#BBFFFFFF"
            android:cacheColorHint="#000000"
            android:descendantFocusability="blocksDescendants"
            android:divider="@android:color/transparent"
            android:dividerHeight="1dp"
            android:fastScrollEnabled="true" >
        </ListView>
    </RelativeLayout>


</LinearLayout>



package com.czu.sinaweibo;


import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import com.czu.constdata.ConstDataSinaAPI;
import com.czu.sinaweibo.R;
import com.czu.utils.Global;
import com.czu.weiboHandler.WeiBoInfoPraser;
import com.czu.weiboadapter.WeiBoInfo;
import com.czu.weiboadapter.UserInfo;
import com.czu.weiboadapter.WeiBoAdapter;
import com.weibo.net.WeiboException;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;


public class HomeActivity extends Activity {
/* 显示微博信息的列表 */
private ListView msgListView = null;


/* 在标题栏设置当前登录用户名 */
private TextView userNameTextView = null;
/* 刷新按钮 */
private ImageButton refreshImageButton = null;


/* 发微博按钮 */
private ImageButton saysomethingImageButton = null;

/* SharedPreferences名 */
private String select_name = "userName";


private List<WeiBoInfo> weiBoInfos = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


/* 设置没有标题栏 */
this.requestWindowFeature(Window.FEATURE_NO_TITLE);


setContentView(R.layout.home_activity);


/* 保存当前用户名到SharedPreferences */
SharedPreferences preferences = getSharedPreferences(select_name,
MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("name", Global.getCurrentUserInfo().getUserName());


/* 通过id获得TextView对象 */
userNameTextView = (TextView) this.findViewById(R.id.usernameTextView);


/* 得到当前登录的用户信息 */
UserInfo userInfo = Global.getCurrentUserInfo();


// System.out.println("Home activity--->"+userInfo.getUserName());
// System.out.println("Home activity--->"+userInfo.getAccessToken());


/* 在标题显示当前用户的昵称 */
userNameTextView.setText(userInfo.getUserName());

new Thread(){


@Override
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.run();
}

}.start();


setListViewContent();


/* 得到刷新按钮对象 */
refreshImageButton = (ImageButton) this
.findViewById(R.id.refreshImgBtn);
/* 对刷新按钮的单击事件进行监听 */
refreshImageButton.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
Refrsh();
}


});
/* 得到发微博按钮对象 */
saysomethingImageButton = (ImageButton) this
.findViewById(R.id.saysomethingImgBtn);


/* 对发微博按钮进行监听 */
saysomethingImageButton
.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this,
ShareActivity.class);


startActivity(intent);
}


});


}


// method
private void Refrsh() {
setListViewContent();
}
// ///

private void setListViewContent(){

WeiBoInfoPraser informationParser = new WeiBoInfoPraser(this);


try {  

weiBoInfos = informationParser
.getWeiBoInfos(ConstDataSinaAPI.friends_timeline);



// progressDialog = new ProgressDialog(HomeActivity.this);
// progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// progressDialog.setMessage("正在努力为您加载,请稍侯......");
//
// /*设置是否可以按返回键返回*/
// progressDialog.setCancelable(false);
//
// progressDialog.show();


// System.out.println("weibo content"+weiBoInfos.get(0).getContent());
/* 新建一个WeiBoAdapter */
WeiBoAdapter weiBoAdapter = new WeiBoAdapter(this, weiBoInfos,
ConstDataSinaAPI.friends_timeline);


msgListView = (ListView) this.findViewById(R.id.msglistView);


msgListView.setAdapter(weiBoAdapter);


msgListView.setOnItemClickListener(new OnItemClickListener() {


@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long id) {


WeiBoInfo weiBoInfo = weiBoInfos.get(position);


Intent intent = new Intent(HomeActivity.this,
WeiBoDetailsActivity.class);

intent.putExtra("ArticleId",weiBoInfo.getArticleId());
intent.putExtra("BigImage", weiBoInfo.getBigImage());
intent.putExtra("CommentsCount", weiBoInfo.getCommentsCount());
intent.putExtra("Content", weiBoInfo.getContent());
intent.putExtra("Image", weiBoInfo.getImage());
intent.putExtra("PublisherIcon", weiBoInfo.getPublisherIcon());
intent.putExtra("PublisherId", weiBoInfo.getPublisherId());
intent.putExtra("PublisherName", weiBoInfo.getPublisherName());
intent.putExtra("RepostsCount", weiBoInfo.getRepostsCount());
intent.putExtra("Source", weiBoInfo.getSource());
intent.putExtra("SourceBigImage", weiBoInfo.getSourceBigImage());
intent.putExtra("SourceContent",weiBoInfo.getSourceContent());
intent.putExtra("SourceImage", weiBoInfo.getSourceImage());
intent.putExtra("SourceName", weiBoInfo.getSourceName());
intent.putExtra("HaveImage",String.valueOf(weiBoInfo.getHaveImage()));
intent.putExtra("HaveSourceImage", String.valueOf(weiBoInfo.getHaveSourceImage()));
intent.putExtra("HaveSourceStatus",String.valueOf(weiBoInfo.getHaveSourceStatus()));


startActivity(intent);
}


});


} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WeiboException e) {
e.printStackTrace();
}
}



}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值