PageRenderTime 64ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/sinonetwork/zhonghua/Price_information.java

https://gitlab.com/zwp/Zhonghua
Java | 397 lines | 276 code | 75 blank | 46 comment | 26 complexity | 2ecc138798f2782b6e5d593645e5b039 MD5 | raw file
  1. package com.sinonetwork.zhonghua;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import android.location.Location;
  7. import android.location.LocationManager;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.AdapterView;
  12. import android.widget.AdapterView.OnItemSelectedListener;
  13. import android.widget.ArrayAdapter;
  14. import android.widget.ImageView;
  15. import android.widget.ListView;
  16. import android.widget.ProgressBar;
  17. import android.widget.Spinner;
  18. import com.alibaba.fastjson.JSONArray;
  19. import com.alibaba.fastjson.JSONObject;
  20. import com.amap.api.location.AMapLocation;
  21. import com.amap.api.location.AMapLocationListener;
  22. import com.amap.api.location.LocationManagerProxy;
  23. import com.amap.api.location.LocationProviderProxy;
  24. import com.lidroid.xutils.exception.HttpException;
  25. import com.lidroid.xutils.http.RequestParams;
  26. import com.lidroid.xutils.http.ResponseInfo;
  27. import com.lidroid.xutils.http.callback.RequestCallBack;
  28. import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
  29. import com.sinonetwork.zhonghua.adapter.Price_InformationAdapter;
  30. import com.sinonetwork.zhonghua.model.PriceHangqing.PriceHangqings;
  31. import com.sinonetwork.zhonghua.model.ShengFenModel.ShengFenModels;
  32. import com.sinonetwork.zhonghua.utils.HttpHelp;
  33. import com.sinonetwork.zhonghua.utils.URLAddress;
  34. public class Price_information extends LandBaseActivity implements AMapLocationListener,
  35. Runnable {
  36. private Spinner com_spinner1;
  37. private Spinner sp2;
  38. private AMapLocation aMapLocation;// 用于判断定位超时
  39. private int index;
  40. private double getLat;
  41. private double getLng;
  42. private LocationManagerProxy aMapLocManager = null;
  43. private ListView listView;
  44. private Price_InformationAdapter adapter;
  45. private ImageView back;
  46. // private String[] name = { "紫苏", "土鸡蛋", "猪五花肉", "紫苏", "土鸡蛋" };
  47. // private String[] jiage = { "56.76", "55", "67.65", "44", "22" };
  48. // private String[] shichang = { "老虎沟市场", "老虎沟市场", "老虎沟市场", "老虎沟市场", "老虎沟市场"
  49. // };
  50. // private String[] shijian = { "2015-07-02", "2015-07-02", "2015-07-02",
  51. // "2015-07-02", "2015-07-02" };
  52. private List<ShengFenModels> sdata;
  53. private List<String> list;
  54. private List<String> diquList;
  55. private String sheng, diqu;
  56. private List<PriceHangqings> dataList;
  57. private List<Map<String, Object>> data;
  58. private ArrayAdapter<String> adapters, adapters1;
  59. private double latitude=0.0;
  60. private double longitude =0.0;
  61. private String dqdiqu;
  62. private ProgressBar load_progressBar;
  63. private LocationManager locationManager;
  64. // protected ArrayList<Warning> list;
  65. protected void onCreate(Bundle savedInstanceState) {
  66. // TODO Auto-generated method stub
  67. super.onCreate(savedInstanceState);
  68. setContentView(R.layout.price_information);
  69. com_spinner1 = (Spinner) findViewById(R.id.price_sp1);
  70. sp2 = (Spinner) findViewById(R.id.price_sp2);
  71. load_progressBar = (ProgressBar) findViewById(R.id.load_progressBar);
  72. listView = (ListView) findViewById(R.id.price_lv);
  73. back = (ImageView) findViewById(R.id.back);
  74. index = 0;
  75. init();
  76. list = new ArrayList<String>();
  77. adapters = new ArrayAdapter<String>(Price_information.this,
  78. R.layout.guojia_item, R.id.tvCateItem, list);
  79. com_spinner1.setAdapter(adapters);
  80. diquList = new ArrayList<String>();
  81. adapters1 = new ArrayAdapter<String>(Price_information.this,
  82. R.layout.guojia_item, R.id.tvCateItem, diquList);
  83. sp2.setAdapter(adapters1);
  84. data = new ArrayList<Map<String, Object>>();
  85. adapter = new Price_InformationAdapter(Price_information.this, data);
  86. listView.setAdapter(adapter);
  87. setMonitor();
  88. }
  89. private void init() {
  90. aMapLocManager = LocationManagerProxy.getInstance(this);
  91. /*
  92. * mAMapLocManager.setGpsEnable(false);//
  93. * 1.0.2版本新增方法,设置true表示混合定位中包含gps定位,false表示纯网络定位,默认是true Location
  94. * API定位采用GPS和网络混合定位方式
  95. * ,第一个参数是定位provider,第二个参数时间最短是2000毫秒,第三个参数距离间隔单位是米,第四个参数是定位监听者
  96. */
  97. aMapLocManager.requestLocationData(LocationProviderProxy.AMapNetwork,
  98. 2000, 10, this);
  99. handler.postDelayed(this, 12000);// 设置超过12秒还没有定位到就停止定位
  100. }
  101. public void setMonitor() {
  102. back.setOnClickListener(new OnClickListener() {
  103. @Override
  104. public void onClick(View v) {
  105. // TODO Auto-generated method stub
  106. finish();
  107. }
  108. });
  109. com_spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
  110. @Override
  111. public void onItemSelected(AdapterView<?> parent, View view,
  112. int position, long id) {
  113. // TODO Auto-generated method stub
  114. if (!list.equals("") && list != null && list.size() != 0) {
  115. sheng = list.get(position);
  116. dqdiqu = sheng;
  117. // Log.v("zhong","dqdiqu--"+dqdiqu);
  118. searchQuotationData();
  119. }
  120. }
  121. @Override
  122. public void onNothingSelected(AdapterView<?> parent) {
  123. // TODO Auto-generated method stub
  124. }
  125. });
  126. sp2.setOnItemSelectedListener(new OnItemSelectedListener() {
  127. @Override
  128. public void onItemSelected(AdapterView<?> parent, View view,
  129. int position, long id) {
  130. // TODO Auto-generated method stub
  131. if (!diquList.equals("") && diquList != null
  132. && diquList.size() != 0) {
  133. diqu = diquList.get(position);
  134. initData(diqu);
  135. }
  136. }
  137. @Override
  138. public void onNothingSelected(AdapterView<?> parent) {
  139. // TODO Auto-generated method stub
  140. }
  141. });
  142. }
  143. @Override
  144. public void run() {
  145. if (aMapLocation == null) {
  146. stopLocation();// 销毁掉定位12秒内还没有定位成功,停止定位
  147. }
  148. }
  149. /**
  150. * 方法必须重写
  151. */
  152. @Override
  153. protected void onPause() {
  154. super.onPause();
  155. stopLocation();// 停止定位
  156. }
  157. /**
  158. * 混合定位回调函数
  159. */
  160. @Override
  161. public void onLocationChanged(AMapLocation location) {
  162. if (location != null) {
  163. // mListener.onLocationChanged(location);// 显示系统小蓝点
  164. this.aMapLocation = location;// 判断超时机制
  165. getLat = location.getLatitude();
  166. getLng = location.getLongitude();
  167. String cityCode = "";
  168. String desc = "";
  169. Bundle locBundle = location.getExtras();
  170. if (locBundle != null) {
  171. cityCode = locBundle.getString("citycode");
  172. desc = locBundle.getString("desc");
  173. }
  174. String str = ("定位成功:(" + getLat + "," + getLng + ")"
  175. + "\n精 度 :" + location.getAccuracy() + "米"
  176. + "\n定位方式:" + location.getProvider() + "\n定位时间:"
  177. + "\n城市编码:" + cityCode + "\n位置描述:" + desc + "\n省:"
  178. + location.getProvince() + "\n市:" + location.getCity()
  179. + "\n区(县):" + location.getDistrict() + "\n区域编码:" + location
  180. .getAdCode());
  181. // Log.v(TAG, "定位" + str);
  182. // 初次定位成功去接口请求数据
  183. if (index == 0) {
  184. index++;
  185. dqdiqu = location.getProvince();
  186. // Log.v("zhong","dqdiqu--"+dqdiqu);
  187. getProvinceData();
  188. }
  189. }
  190. }
  191. //拿到所有的省,默认显示根据定位省
  192. public void getProvinceData() {
  193. showLoadProgressBar();
  194. RequestParams params = new RequestParams();
  195. HttpHelp.getInstance().send(HttpMethod.POST, URLAddress.SomeAreaURL,
  196. params, new RequestCallBack<String>() {
  197. @Override
  198. public void onFailure(HttpException arg0, String arg1) {
  199. hideLoadProgressBar();
  200. showShortToast("获取数据失败");
  201. }
  202. @Override
  203. public void onSuccess(ResponseInfo<String> resultInfo) {
  204. JSONObject json = JSONObject
  205. .parseObject(resultInfo.result);
  206. // Log.v("zhong","json--"+json);
  207. JSONArray sdata = json.getJSONArray("resultData");
  208. for (int i = 0; i < sdata.size(); i++) {
  209. JSONObject jObject = JSONObject
  210. .parseObject(sdata.get(i)
  211. .toString());
  212. String str= jObject.getString("AREANAME");
  213. list.add(str);
  214. if(list.get(i).contains(dqdiqu)){
  215. com_spinner1.setSelection(i);
  216. //com_spinner1.setSelection(18,true);
  217. }
  218. }
  219. adapters.notifyDataSetChanged();
  220. searchQuotationData();
  221. }
  222. });
  223. }
  224. //根据省获取区
  225. public void searchQuotationData() {
  226. RequestParams params = new RequestParams();
  227. params.addBodyParameter("method", "searchQuotationMarket");
  228. params.addBodyParameter("regionName", dqdiqu);
  229. HttpHelp.getInstance().send(HttpMethod.POST, URLAddress.URLER,
  230. params, new RequestCallBack<String>() {
  231. @Override
  232. public void onFailure(HttpException arg0, String arg1) {
  233. hideLoadProgressBar();
  234. showShortToast("获取数据失败");
  235. }
  236. @Override
  237. public void onSuccess(ResponseInfo<String> resultInfo) {
  238. JSONObject json = JSONObject
  239. .parseObject(resultInfo.result);
  240. // Log.v("zhong","json--"+json);
  241. if(json.getString("resultcode").equals("error")){
  242. }else{
  243. diquList.clear();
  244. JSONArray a = json.getJSONArray("resultdata");
  245. String d = (String) a.get(0);
  246. for(int i=0;i<a.size();i++){
  247. diquList.add((String) a.get(i));
  248. }
  249. initData(diquList.get(0));
  250. adapters1.notifyDataSetChanged();
  251. // Log.v("zhong","json--"+d);
  252. }
  253. }
  254. });
  255. }
  256. //根据省和区拿到市场价格
  257. public void initData(String diqu){
  258. showLoadProgressBar();
  259. RequestParams params = new RequestParams();
  260. params.addBodyParameter("method", "searchQuotation");
  261. params.addBodyParameter("regionName", dqdiqu);
  262. params.addBodyParameter("marketName", diqu);
  263. HttpHelp.getInstance().send(HttpMethod.POST, URLAddress.URLER,
  264. params, new RequestCallBack<String>() {
  265. @Override
  266. public void onFailure(HttpException arg0, String arg1) {
  267. hideLoadProgressBar();
  268. }
  269. @Override
  270. public void onSuccess(ResponseInfo<String> resultInfo) {
  271. hideLoadProgressBar();
  272. JSONObject json = JSONObject
  273. .parseObject(resultInfo.result);
  274. // Log.v("zhong","initDatajson--"+json);
  275. if(json.getString("resultcode").equals("error")){
  276. }else{
  277. JSONArray dataList = json.getJSONArray("resultdata");
  278. // Log.v("zhong","a.size()--"+dataList.size());
  279. data.clear();
  280. for (int i = 0; i < dataList.size(); i++) {
  281. JSONObject jObject = JSONObject
  282. .parseObject(dataList.get(i)
  283. .toString());
  284. Map<String, Object> map = new HashMap<String, Object>();
  285. map.put("name", jObject.getString("d2"));
  286. map.put("jiage", jObject.getString("d3"));
  287. map.put("shichang", jObject.getString("d7"));
  288. map.put("shijian", jObject.getString("publishTime"));
  289. data.add(map);
  290. }
  291. adapter.notifyDataSetChanged();
  292. }
  293. }
  294. });
  295. }
  296. /**
  297. * 销毁定位
  298. */
  299. private void stopLocation() {
  300. if (aMapLocManager != null) {
  301. aMapLocManager.removeUpdates(this);
  302. aMapLocManager.destroy();
  303. }
  304. aMapLocManager = null;
  305. }
  306. @Override
  307. public void onLocationChanged(Location arg0) {
  308. // TODO Auto-generated method stub
  309. }
  310. @Override
  311. public void onProviderDisabled(String arg0) {
  312. // TODO Auto-generated method stub
  313. }
  314. @Override
  315. public void onProviderEnabled(String arg0) {
  316. // TODO Auto-generated method stub
  317. }
  318. @Override
  319. public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
  320. // TODO Auto-generated method stub
  321. }
  322. }