Android腾讯微薄客户端开发十三:提及篇(与我有关的微博)

[img]http://dl.iteye.com/upload/attachment/527605/0e778f48-cccb-3c3d-92cf-96df74d7295b.jpg[/img]
public class ReferActivity extends ListActivity implements OnItemClickListener,OnItemLongClickListener{

private DataHelper dataHelper;
private UserInfo user;
private MyWeiboSync weibo;
private ListView listView;
private ReferAdapter adapter;
private JSONArray array;
private AsyncImageLoader asyncImageLoader;
private Handler handler;
private ProgressDialog progressDialog;
private View top_panel;
private Button top_btn_left;
private Button top_btn_right;
private TextView top_title;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.refer);
setUpViews();
setUpListeners();

dataHelper = DataBaseContext.getInstance(getApplicationContext());
weibo = WeiboContext.getInstance();

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);
top_title.setText("提到我的");//顶部工具栏名称
}

/*weibo.setAccessTokenKey(user.getToken());
weibo.setAccessTokenSecrect(user.getTokenSecret());*/

progressDialog = new ProgressDialog(ReferActivity.this);// 生成一个进度条
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle("请稍等");
progressDialog.setMessage("正在读取数据中!");
handler = new GetReferHandler();

new GetReferThread().start();//耗时操作,开启一个新线程获取数据
progressDialog.show();
}

private void setUpViews(){
listView = getListView();
top_panel = (View)findViewById(R.id.refer_top);
top_btn_left = (Button)top_panel.findViewById(R.id.top_btn_left);
top_btn_right = (Button)top_panel.findViewById(R.id.top_btn_right);
top_title = (TextView)top_panel.findViewById(R.id.top_title);
}

private void setUpListeners(){
listView.setOnItemClickListener(this);
listView.setOnItemLongClickListener(this);
}

class GetReferHandler extends Handler {
@Override
public void handleMessage(Message msg) {
if(array!=null){
adapter = new ReferAdapter(ReferActivity.this, array);
listView.setAdapter(adapter);
}

progressDialog.dismiss();// 关闭进度条
}
}

class GetReferThread extends Thread {
@Override
public void run() {
String jsonStr = weibo.getRefers(weibo.getAccessTokenKey(), weibo.getAccessTokenSecrect(), PageFlag.PageFlag_First, 0, 20, 0);
try {
JSONObject dataObj = new JSONObject(jsonStr).getJSONObject("data");
if(dataObj!=null){
array = dataObj.getJSONArray("info");
}
} catch (JSONException e) {
e.printStackTrace();
}
Message msg = handler.obtainMessage();
handler.sendMessage(msg);
}
}


class ReferAdapter extends BaseAdapter {
private Context context;
private LayoutInflater inflater;
private JSONArray array;

public ReferAdapter(Context context, JSONArray array) {
super();
this.context = context;
this.array = array;
this.inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
return array.length();
}

@Override
public Object getItem(int position) {
return array.opt(position);
}

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

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
asyncImageLoader = new AsyncImageLoader();
ReferViewHolder viewHolder = new ReferViewHolder();
JSONObject data = (JSONObject)array.opt(position);
JSONObject source = null;
convertView = inflater.inflate(R.layout.refer_list_item, null);
try {
source = data.getJSONObject("source");
} catch (JSONException e1) {
e1.printStackTrace();
}
viewHolder.refer_headicon = (ImageView) convertView.findViewById(R.id.refer_headicon);
viewHolder.refer_nick = (TextView) convertView.findViewById(R.id.refer_nick);
viewHolder.refer_hasimage = (ImageView) convertView.findViewById(R.id.refer_hasimage);
viewHolder.refer_timestamp = (TextView) convertView.findViewById(R.id.refer_timestamp);
viewHolder.refer_origtext = (TextView) convertView.findViewById(R.id.refer_origtext);
viewHolder.refer_source = (TextView) convertView.findViewById(R.id.refer_source);

if(data!=null){
try {
convertView.setTag(data.get("id"));
viewHolder.refer_nick.setText(data.getString("nick"));
viewHolder.refer_timestamp.setText(TimeUtil.converTime(Long.parseLong(data.getString("timestamp"))));
viewHolder.refer_origtext.setText(data.getString("origtext"), TextView.BufferType.SPANNABLE);

if(source!=null){
viewHolder.refer_source.setText(source.getString("nick")+":"+source.getString("origtext"));
viewHolder.refer_source.setBackgroundResource(R.drawable.source_bg);
}
//异步加载图片
Drawable cachedImage = asyncImageLoader.loadDrawable(data.getString("head")+"/100",viewHolder.refer_headicon, new ImageCallback(){
@Override
public void imageLoaded(Drawable imageDrawable,ImageView imageView, String imageUrl) {
imageView.setImageDrawable(imageDrawable);
}
});
if (cachedImage == null) {
viewHolder.refer_headicon.setImageResource(R.drawable.icon);
} else {
viewHolder.refer_headicon.setImageDrawable(cachedImage);
}
if(data.getJSONArray("image")!=null){
viewHolder.refer_hasimage.setImageResource(R.drawable.hasimage);
}
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return convertView;
}
}

static class ReferViewHolder {
private ImageView refer_headicon;
private TextView refer_nick;
private TextView refer_timestamp;
private TextView refer_origtext;
private TextView refer_source;
private ImageView refer_hasimage;
}

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position,long arg3) {
CharSequence [] items = null;
try {
items= new CharSequence[]{"转播","对话","点评","收藏",((JSONObject)array.opt(position)).getString("nick"),"取消"};
} catch (JSONException e) {
e.printStackTrace();
}
new AlertDialog.Builder(ReferActivity.this).setTitle("选项").setItems(items,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0: {
}
break;
case 1: {
}
break;
case 2: {
}
break;
case 3: {
}
break;
case 4: {
}
break;
case 5: {
}
break;
default:
break;
}
}
}).show();
return false;
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
JSONObject weiboInfo = (JSONObject)array.opt(position);
Intent intent = new Intent(ReferActivity.this, WeiboDetailActivity.class);
try {
intent.putExtra("weiboid", weiboInfo.getString("id"));
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}

}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#ffffffff" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<include android:id="@+id/refer_top" layout="@layout/top_panel" android:layout_alignParentTop="true"/>
<ListView android:layout_below="@id/refer_top" android:id="@id/android:list" android:layout_width="fill_parent" android:cacheColorHint="#00000000"
android:layout_height="wrap_content" android:layout_weight="1" android:divider="@drawable/list_divider"/>
</RelativeLayout>




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="3.0dip" android:orientation="horizontal" android:background="@drawable/listitem_selector" android:layout_width="fill_parent" android:layout_height="wrap_content">
<RelativeLayout android:layout_width="50.0dip" android:layout_height="50.0dip" android:layout_weight="0.0">
<ImageView android:id="@+id/refer_headicon" android:layout_width="45.0dip" android:layout_height="45.0dip" android:scaleType="fitCenter" android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4.0dip" android:layout_weight="1.0">
<TextView android:id="@+id/refer_nick" android:textColor="#000000" android:layout_width="wrap_content" android:layout_height="32.0dip" android:textSize="14.0sp" android:layout_alignParentLeft="true"/>
<TextView android:id="@+id/refer_timestamp" android:textColor="#ff000000" android:layout_width="wrap_content" android:layout_height="32.0dip" android:textSize="8.0sp" android:layout_alignParentRight="true"/>
<ImageView android:id="@+id/refer_hasimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/refer_timestamp"/>
<TextView android:id="@+id/refer_origtext" android:textColor="#081008" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12.0sp" android:layout_below="@id/refer_nick"/>
<TextView android:layout_marginLeft="6.0dip" android:id="@+id/refer_source" android:textColor="#101810" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10.0sp" android:layout_below="@id/refer_origtext" android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
技术选型 【后端】:Java 【框架】:springboot 【前端】:vue 【JDK版本】:JDK1.8 【服务器】:tomcat7+ 【数据库】:mysql 5.7+ 项目包含前后台完整源码。 项目都经过严格调试,确保可以运行! 具体项目介绍可查看博主文章或私聊获取 助力学习实践,提升编程技能,快来获取这份宝贵的资源吧! 在当今快速发展的信息技术领域,技术选型是决定一个项目成功与否的重要因素之一。基于以下的技术栈,我们为您带来了一份完善且经过实践验证的项目资源,让您在学习和提升编程技能的道路上事半功倍。以下是该项目的技术选型和其组件的详细介绍。 在后端技术方面,我们选择了Java作为编程语言。Java以其稳健性、跨平台性和丰富的库支持,在企业级应用中处于领导地位。项目采用了流行的Spring Boot框架,这个框架以简化Java企业级开发而闻名。Spring Boot提供了简洁的配置方式、内置的嵌入式服务器支持以及强大的生态系统,使开发者能够更高效地构建和部署应用。 前端技术方面,我们使用了Vue.js,这是一个用于构建用户界面的渐进式JavaScript框架。Vue以其易上手、灵活和性能出色而受到开发者的青睐,它的组件化开发思想也有助于提高代码的复用性和可维护性。 项目的编译和运行环境选择了JDK 1.8。尽管Java已经推出了更新的版本,但JDK 1.8依旧是一种成熟且稳定的选择,广泛应用于各类项目中,确保了兼容性和稳定性。 在服务器方面,本项目部署在Tomcat 7+之上。Tomcat是Apache软件基金会下的一个开源Servlet容器,也是应用最为广泛的Java Web服务器之一。其稳定性和可靠的性能表现为Java Web应用提供了坚实的支持。 数据库方面,我们采用了MySQL 5.7+。MySQL是一种高效、可靠且使用广泛的关系型数据库管理系统,5.7版本在性能和功能上都有显著的提升。 值得一提的是,该项目包含了前后台的完整源码,并经过严格调试,确保可以顺利运行。通过项目的学习和实践,您将能更好地掌握从后端到前端的完整开发流程,提升自己的编程技能。欢迎参考博主的详细文章或私信获取更多信息,利用这一宝贵资源来推进您的技术成长之路!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值