package com.txsc.activity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.txsc.MyApplication;
import com.txsc.NetActivity;
import com.txsc.R;
import com.txsc.adapter.Add_CityAdapter;
import com.txsc.bean.AreaListBean;
import com.txsc.bean.AryNetResultBean;
import com.txsc.constants.Url;
import com.txsc.utils.JsonUtils;
import com.txsc.utils.MD5;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
/**
* 地区选择类
*
* @author linshao 弃用
*
* @data 2015年4月14日 上午11:01:27
*
*/
public class Area_AddAty extends NetActivity implements
android.view.View.OnClickListener {
private ImageView imgBack;
private ListView listView;
private List<AreaListBean.AreaBean> list;
private TextView textTitle;
private int i = 1;
private String Id;
private Add_CityAdapter adapter;
public static String areaId, cityId, provId, areaName, proName, cityName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyApplication.getInstance().addActivity(this);
setContentView(R.layout.layout_data_check);
imgBack = (ImageView) findViewById(R.id.btn_data_check_back);
listView = (ListView) findViewById(R.id.list_data_check);
textTitle = (TextView) findViewById(R.id.text_data_check_title);
list = new ArrayList<AreaListBean.AreaBean>();
adapter = new Add_CityAdapter(this, list);
listView.setAdapter(adapter);
getNetData(0 + "");
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Id = list.get(arg2).getTAreaID();
if (i == 1) {
provId = Id;
} else if (i == 2) {
cityId = Id;
} else if (i == 3) {
areaId = Id;
}
i++;
// 添加城市
if (i == 2) {
proName = list.get(arg2).getAreaCaption();
adapter.clearData();
list.clear();
getNetData(Id);
adapter.addData(list);
adapter.notifyDataSetChanged();
textTitle.setText("选择城市");
} else if (i == 3) {
cityName = list.get(arg2).getAreaCaption();
getNetData(Id);
adapter.notifyDataSetChanged();
textTitle.setText("选择地区");
} else if (i == 4) {
Intent intent = new Intent();
intent.putExtra("areaId", areaId);
intent.putExtra("areaName", proName + "-" + cityName + "-"
+ list.get(arg2).getAreaCaption());
setResult(100, intent);
Area_AddAty.this.finish();
}
}
});
imgBack.setOnClickListener(this);
}
private void getNetData(String parentId) {
HashMap<String, String> params = new HashMap<String, String>();
params.put("agent_id", "TRest5763cd2d5b3745ccww56");
params.put("parent_id", parentId);
params.put("port_password",
MD5.getMD5ofStr(Url.KET + "TRest5763cd2d5b3745ccww56"));
asynNet(Url.Area_Get, params, 0);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (i == 1) {
Area_AddAty.this.finish();
} else if (i == 2) {
getNetData(0 + "");
textTitle.setText("选择省份");
i = 1;
} else if (i == 3) {
getNetData(provId);
textTitle.setText("选择城市");
i = 2;
}
} else {
return super.onKeyDown(keyCode, event);
}
return false;
}
@Override
public void onClick(View v) {
if (v == imgBack) {
if (i == 1) {
Area_AddAty.this.finish();
} else if (i == 2) {
getNetData(0 + "");
textTitle.setText("选择省份");
i = 1;
} else if (i == 3) {
getNetData(provId);
textTitle.setText("选择城市");
i = 2;
}
}
}
@Override
public void success(String result, int tag) {
AryNetResultBean bean = JsonUtils.parseAryNetResult(result);
if (bean.getStatus().getCode() == 200) {
AreaListBean beans = JsonUtils.parseAreaList(result);
list.clear();
list = beans.getBackinfo();
adapter.clearData();
adapter.addData(list);
adapter.notifyDataSetChanged();
}
}
@Override
public void onclick(View v) {
}
}