/**============================================================
* 版权: 久其软件 版权所有 (c)
* 包: com.jiuqi.njt.ui
* 修改记录:
* 日期 作者 内容
* =============================================================
* 2013-7-30 liyue
* ============================================================*/
package com.jiuqi.njt.ui;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.jiuqi.njt.R;
import com.jiuqi.njt.model.NxwAppCategoryVo;
import com.jiuqi.njt.model.NxwAppVoManager;
import com.jiuqi.njt.util.Constants;
import com.jiuqi.njt.util.TitleBarUtil;
/**
* <p>农信网链接页面</p>
*
* <p>Copyright: 版权所有 (c)<br>
* Company: 久其</p>
*
* @author liyue
* @version 2013-7-30
*/
public class NxwAppLinksListViewActivity extends Activity{
private ListView listView;
private LinksListViewAdapter adapter;
private NxwAppVoManager nxwAppVoManager;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
doinit();
}
private void doinit(){
initParam();
initWidgets();
initListener();
initUI();
}
private void initParam(){
}
private void initWidgets(){
setContentView(R.layout.layout_template_listview);
String title;
if(TextUtils.isEmpty(getIntent().getStringExtra(Constants.PARAM_TITLE))){
if(null==getIntent().getSerializableExtra(Constants.PARAM_MODULEBEAN)){
title = "";
}else{
title = "常用工具";
}
}
else{
// title = getIntent().getStringExtra(Constants.PARAM_TITLE);
title = "常用工具";
}
View rlTitleBar = findViewById(R.id.titleBarStub);
TitleBarUtil.createTitleBar(this, rlTitleBar, title, "首页", new OnClickListener(){
@Override
public void onClick(View v){
NxwAppLinksListViewActivity.this.finish();
}
});
listView = (ListView)findViewById(R.id.listView);
ArrayList<NxwAppCategoryVo> _appCategories = new ArrayList<NxwAppCategoryVo>();
//去掉高德地图
nxwAppVoManager = NxwAppVoManager.getInstance(this);
ArrayList<NxwAppCategoryVo> appCategories = nxwAppVoManager.getAppCategories();
for(NxwAppCategoryVo vo : appCategories){
if(!"地图导航".equals(vo.getName())){
_appCategories.add(vo);
}
}
adapter = new LinksListViewAdapter(this, _appCategories);
listView.setAdapter(adapter);
}
private class LinksListViewAdapter extends BaseAdapter{
private Context context;
private ArrayList<NxwAppCategoryVo> items = new ArrayList<NxwAppCategoryVo>();
private LayoutInflater inflater;
public LinksListViewAdapter(Context context, ArrayList<NxwAppCategoryVo> items){
this.context = context;
if(null != items){
this.items = items;
}
inflater = LayoutInflater.from(context);
}
@Override
public int getCount(){
return items.size();
}
@Override
public Object getItem(int position){
return items.get(position);
}
@Override
public long getItemId(int position){
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
if(null == convertView){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.listview_item_link, null);
ImageView ivIco = (ImageView)convertView.findViewById(R.id.ivIco);
holder.setIco(ivIco);
TextView tvTitle = (TextView)convertView.findViewById(R.id.weatherTvTitle);
holder.setTvTitle(tvTitle);
convertView.setTag(holder);
}
else{
holder = (ViewHolder)convertView.getTag();
}
final NxwAppCategoryVo vo = items.get(position);
holder.getIco().setImageDrawable(vo.getIco());
holder.getTvTitle().setText(vo.getName());
convertView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
if("天气在线".equals(vo.getName())){
new CheckAppInstalledTask(NxwAppLinksListViewActivity.this).execute(nxwAppVoManager.getAppByName("墨迹天气"));
}else{
Intent intent = new Intent();
intent.setClass(context, NxwAppLinksGridViewActivity.class);
intent.putExtra(Constants.PARAM_TITLE, vo.getName());
intent.putExtra(Constants.PARAM_ID, vo.getId());
startActivity(intent);
}
}
});
return convertView;
}
}
class ViewHolder{
private TextView tvTitle;
private ImageView ico;
public TextView getTvTitle(){
return tvTitle;
}
public void setTvTitle(TextView tvTitle){
this.tvTitle = tvTitle;
}
public ImageView getIco(){
return ico;
}
public void setIco(ImageView ico){
this.ico = ico;
}
}
private void initListener(){
}
private void initUI(){
}
}