update ui layout
[freespace.git] / weibosrc / com / weibo / view / StatusCursorAdapter.java
blob4e113dc743d3644a65b93f77e89f7073cbd53dbb
1 package com.weibo.view;
3 import java.util.Date;
5 import android.content.Context;
6 import android.database.Cursor;
7 import android.graphics.drawable.Drawable;
8 import android.util.Log;
9 import android.view.LayoutInflater;
10 import android.view.View;
11 import android.view.ViewGroup;
12 import android.widget.CursorAdapter;
13 import android.widget.ImageView;
14 import android.widget.TextView;
16 import com.weibo.db.HomeTable;
17 import com.weibo.sina.R;
18 import com.weibo.util.MD5;
19 import com.weibo.util.Util;
21 public class StatusCursorAdapter extends CursorAdapter {
22 private static final String TAG = "StatusCursorAdapter";
23 private int mLayout;
24 public StatusCursorAdapter(Context context, Cursor c,final int layout) {
25 super(context, c);
26 mLayout = layout;
31 public StatusCursorAdapter(Context context, Cursor c, boolean autoRequery,final int layout) {
32 super(context, c, autoRequery);
33 mLayout = layout;
37 @Override
38 public View newView(Context context, Cursor cursor, ViewGroup parent) {
39 //Log.e(TAG, "get new View");
40 LayoutInflater inflater = (LayoutInflater) context
41 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
42 View view = inflater.inflate(mLayout, parent, false);
43 StatusObj tag = new StatusObj();
44 view.setTag(tag);
45 return view;
48 @Override
49 public void bindView(View view, Context context, Cursor cursor) {
50 //long start = System.currentTimeMillis();
51 StatusView statuView = (StatusView)view;
52 StatusObj tag =(StatusObj) statuView.getTag();
53 tag.clear();
54 tag.setId(cursor.getLong(cursor.getColumnIndex(HomeTable._ID)));
55 tag.setRt_id(cursor.getLong(cursor.getColumnIndex(HomeTable.RTROOTID)));
56 String tmpString="";
57 view.setTag(tag);
58 //TODO: view.findViewById用的时间很长, 这里可以把View修改成自定义的类提供get方法提高性能。
59 TextView tmp = statuView.getUser_name();
60 tmpString = cursor.getString(cursor.getColumnIndex(HomeTable.NICK));
61 tmp.setText("@" +tmpString);
62 tag.setNick(tmpString);
63 //Log.e(TAG, "user_name = "+tmp.getText());
64 Util.addLink(tmp, true);
65 tmp = statuView.getPost_time();
69 tmp.setText(Util.getPastTime(new Date(cursor.getLong(cursor.getColumnIndex(HomeTable.TIME)))));
70 tmp = statuView.getContent();
71 tmp.setTag(tag);
72 tmpString=cursor.getString(cursor.getColumnIndex(HomeTable.CONTENT));
73 // tmpString = tmpString+ " "+cursor.getString(cursor.getColumnIndex(HomeTable.LONGITUDE));
74 // tmpString = tmpString+ " "+cursor.getString(cursor.getColumnIndex(HomeTable.LATITUDE));
75 tmp.setText(tmpString);
76 tag.setContent(tmpString);
77 Util.addLink(tmp, true);
79 // long start1=System.currentTimeMillis();
80 // long duration = start1 - start;
81 // Log.e(TAG, "duration = "+duration);
84 ImageView imageView =null;
85 Drawable imageDrawable=null;
86 imageView = statuView.getFace();
87 String profileImage = cursor.getString(cursor.getColumnIndex(HomeTable.PORTRAIT));
88 tag.setFace_url(profileImage);
89 String key = MD5.getMD5(profileImage.getBytes());
90 imageDrawable = Util.loadImage(key, profileImage,context,this);
91 if (imageDrawable != null)
92 imageView.setBackgroundDrawable(imageDrawable);
93 else {
94 imageView.setBackgroundResource(R.drawable.face);
96 // long start2 = System.currentTimeMillis();
97 // duration = start2 - start1;
98 // Log.e(TAG, "duration = "+duration);
99 //Log.e(TAG, "rtrootid = "+cursor.getLong(cursor.getColumnIndex(HomeTable.RTROOTID)));
100 View t = view.findViewById(R.id.rt_layout);
101 long rtrootid = cursor.getLong(cursor.getColumnIndex(HomeTable.RTROOTID));
102 if(rtrootid!=0){
103 t.setVisibility(View.VISIBLE);
104 tmp = statuView.getRt_nick();
105 tmpString=cursor.getString(cursor.getColumnIndex(HomeTable.RTROOTNICK));
106 tmp.setText("@" +tmpString);
107 tag.setRt_nick(tmpString);
108 tag.setRt_face_url(cursor.getString(cursor.getColumnIndex(HomeTable.RTPORTRAIT)));
109 Util.addLink(tmp, false);
110 tmp = statuView.getRt_reason();
111 tmpString=cursor.getString(cursor.getColumnIndex(HomeTable.RTREASON));
112 tmp.setText(tmpString);
113 tag.setRt_reason(tmpString);
114 Util.addLink(tmp, false);
115 tmp.setTag(tag);
116 }else {
117 t.setVisibility(View.GONE);
121 // duration = System.currentTimeMillis() - start2;
122 // Log.e(TAG, "duration = "+duration);
124 String pic = cursor.getString(cursor.getColumnIndex(HomeTable.PIC));
125 //Log.e(TAG, "pic = "+pic);
126 LinkImageView linkImageView = statuView.getImage();
127 if (pic!=null &&pic.trim().length()>0) {
128 linkImageView.setVisibility(View.VISIBLE);
130 linkImageView.setUrl(cursor.getString(cursor.getColumnIndex(HomeTable.OPIC)));
131 key = MD5.getMD5(pic.getBytes());
132 imageDrawable = Util.loadImage(key, pic,context,this);
133 if (imageDrawable != null)
134 linkImageView.setImageDrawable(imageDrawable);
135 else{
136 linkImageView.setImageResource(R.drawable.preview_pic_loading);
138 } else {
139 linkImageView.setVisibility(View.GONE);
143 // duration = System.currentTimeMillis() - start;
144 // Log.e(TAG, "duration = "+duration+"cursor="+cursor.getPosition());
147 public static class StatusObj {
148 private long id;
149 private long rt_id;
150 private String nick;
151 private String rt_nick;
152 private String content;
153 private String rt_reason;
154 private String face_url;
155 private String rt_face_url;
157 public void clear(){
158 id=0;
159 rt_id=0;
160 nick=null;
161 rt_nick=null;
162 content=null;
163 rt_reason=null;
164 face_url=null;
165 rt_face_url=null;
168 public long getId() {
169 return id;
172 public void setId(long id) {
173 this.id = id;
176 public String getNick() {
177 return nick;
180 public void setNick(String nick) {
181 this.nick = nick;
184 public String getRt_nick() {
185 return rt_nick;
188 public void setRt_nick(String rt_nick) {
189 this.rt_nick = rt_nick;
192 public String getContent() {
193 return content;
196 public void setContent(String content) {
197 this.content = content;
200 public String getRt_reason() {
201 return rt_reason;
204 public void setRt_reason(String rt_reason) {
205 this.rt_reason = rt_reason;
208 public long getRt_id() {
209 return rt_id;
212 public void setRt_id(long rt_id) {
213 this.rt_id = rt_id;
216 public String getFace_url() {
217 return face_url;
220 public void setFace_url(String face_url) {
221 this.face_url = face_url;
224 public String getRt_face_url() {
225 return rt_face_url;
228 public void setRt_face_url(String rt_face_url) {
229 this.rt_face_url = rt_face_url;
237 @Override
238 public View getDropDownView(int position, View convertView, ViewGroup parent) {
239 // TODO Auto-generated method stub
240 return null;