1 package com
.weibo
.view
;
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";
24 public StatusCursorAdapter(Context context
, Cursor c
,final int layout
) {
31 public StatusCursorAdapter(Context context
, Cursor c
, boolean autoRequery
,final int layout
) {
32 super(context
, c
, autoRequery
);
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();
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();
54 tag
.setId(cursor
.getLong(cursor
.getColumnIndex(HomeTable
._ID
)));
55 tag
.setRt_id(cursor
.getLong(cursor
.getColumnIndex(HomeTable
.RTROOTID
)));
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();
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
);
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
));
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);
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
);
136 linkImageView
.setImageResource(R
.drawable
.preview_pic_loading
);
139 linkImageView
.setVisibility(View
.GONE
);
143 // duration = System.currentTimeMillis() - start;
144 // Log.e(TAG, "duration = "+duration+"cursor="+cursor.getPosition());
147 public static class StatusObj
{
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
;
168 public long getId() {
172 public void setId(long id
) {
176 public String
getNick() {
180 public void setNick(String nick
) {
184 public String
getRt_nick() {
188 public void setRt_nick(String rt_nick
) {
189 this.rt_nick
= rt_nick
;
192 public String
getContent() {
196 public void setContent(String content
) {
197 this.content
= content
;
200 public String
getRt_reason() {
204 public void setRt_reason(String rt_reason
) {
205 this.rt_reason
= rt_reason
;
208 public long getRt_id() {
212 public void setRt_id(long rt_id
) {
216 public String
getFace_url() {
220 public void setFace_url(String face_url
) {
221 this.face_url
= face_url
;
224 public String
getRt_face_url() {
228 public void setRt_face_url(String rt_face_url
) {
229 this.rt_face_url
= rt_face_url
;
238 public View
getDropDownView(int position
, View convertView
, ViewGroup parent
) {
239 // TODO Auto-generated method stub