- 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("提到我的");
- }
-
-
-
-
-
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();
- }
- }
-
- }
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"?>
<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>
- http://helloandroid.iteye.com/blog/1136767
分享到:
相关推荐
在新零售时代,小卖家面临着前所未有的机遇与挑战。新零售,顾名思义,是将线上与线下销售模式深度融合,利用大数据、云计算等技术提升零售效率和消费者体验的新业态。对于小卖家来说,要想在这个竞争激烈的市场中...
#### 题目十:面试技巧与准备建议 **题目描述**:给出一些面试技巧和准备建议。 **解析**: - **熟悉基础知识**:扎实的基础知识是面试成功的基石,包括数据结构、算法、操作系统原理等。 - **了解目标公司**:在...
在Eclipse中开发图形用户界面(GUI)时,SWT(Standard Widget Toolkit)和JFace是两个关键的库。SWT是Java的一个本地化GUI库,它直接与操作系统交互,提供与本机应用程序相似的外观、行为和性能。与Java Swing不同...
完全平方公式变形的应用练习题_2(转摘).doc
新零售时代,小卖家如何迅速做出销量(转摘)-知识杂货店.doc
根据中国公司法及相关规定,多数重大事项需要三分之二以上的股东表决权通过。 - **相对控股**:创始人虽然没有达到绝对控股的比例,但仍然是公司中持股比例最高的股东,通过这种方式也可以保持对公司的相对控制力。...
计算机科学中的算法是解决问题的核心工具,对于理解和应用各种技术至关重要。以下是一些在计算机科学领域最重要的算法及其详细解释: 1. A* 搜索算法:这是一个用于图搜索的问题,特别是路径查找,结合了最佳优先...
有很多的朋友给自己硬盘新建分区都喜欢用第三方软件,我想原因是在XP系统下只能在安装系统时才能进行分区,一旦系统做好之后要想新建分区就必须使用三方软件才行。但到了Vista系统和现下的win7系统时,这个问题就变...
一、开发环境:pb11.2 8669 二、pb的webservice程序必须置于英文目录下,含中文路径时部署会出错; 三、代码只要改一个地方: n_webservice对象的of_retrieve函数中 sqlca.logpass设置为你测试数据库的sa对应密码即可 四...
文件标题提及的是“网站编辑规范要求及标准”,而提供的部分内容却涉及到医疗问题,如乳腺癌的症状和急性乳腺炎等,这与网站编辑规范并不直接相关。然而,我可以基于您提供的“网站编辑规范要求及标准”这一主题来...
在新零售时代,小卖家面临的是一个充满挑战与机遇的市场环境。阿里巴巴定义的新零售四大趋势——消费即娱乐、交易全球一体化、线上线下全渠道融合、大数据构建个性化消费场景,揭示了现代商业的核心变化。这些趋势...
移动端开发(转摘jtyjty99999/mobileTech) ECMA-262,第 5 版 外链(即ES5) ECMAScript5.1中文版 外链(很详细教程) 前端技能汇总 外链(朴灵git) 在线预览word文档 颜色互转 MIME 类型 常用算法 async和defer...
申报书中提及的成果形式为一篇2.8千字的论文,发表于《中小学电教》杂志,成果完成时间为2008年10月。虽然未提供具体的引用、转摘或刊载评论情况,但可以推测该论文可能在教育领域内产生了影响,对其他教育工作者...
本文为转摘!!!!!!!!!!
本文为转摘的普及商事知识的笔记.md档,可以得到一些常识性的认知。从商业角度看,公司的最终目标无非就是赚钱,持续的赚钱,持续的赚更多的钱。为此划分了公司成长的三个阶段:产品阶段,规模扩张阶段,持续经营...
在当今快速的开发环境中,应用程序的测试总是处于次要地位。DataFactory是一种强的的数据产生器,它允许开发人员和QA很容易产生百万行有意义的正确的测试数据库, DataFactory 首先读取一个数据库方案,用户随后点击...
4. **联盟策略**:与其他同类网站建立合作,形成联盟,互相宣传推广,扩大影响力。加入论坛联盟、网摘联盟和图摘联盟,提高网站的曝光率。 5. **数据库策略**:收集和分析用户数据,进行网上调查、有奖活动、小测验...
标题中的“word源码java-csdn-blogs”表明这个压缩包内容可能包含了与Java编程相关的Word文档源代码,可能是为了在CSDN博客平台上分享技术文章而编写的。CSDN(China Software Developer Network)是中国的一个知名...