PageRenderTime 604ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/sinonetwork/zhonghua/Soil_Test.java

https://gitlab.com/zwp/Zhonghua
Java | 459 lines | 315 code | 61 blank | 83 comment | 23 complexity | 9ce6b0b9be0eff3d2231e46fb3118651 MD5 | raw file
  1. package com.sinonetwork.zhonghua;
  2. import java.util.ArrayList;
  3. import java.util.Calendar;
  4. import java.util.List;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. import android.app.Activity;
  8. import android.app.AlertDialog;
  9. import android.content.DialogInterface;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.view.Gravity;
  13. import android.view.LayoutInflater;
  14. import android.view.View;
  15. import android.view.View.OnClickListener;
  16. import android.view.WindowManager;
  17. import android.view.animation.AnticipateOvershootInterpolator;
  18. import android.widget.ArrayAdapter;
  19. import android.widget.Button;
  20. import android.widget.EditText;
  21. import android.widget.ImageView;
  22. import android.widget.RelativeLayout;
  23. import android.widget.Spinner;
  24. import android.widget.TextView;
  25. import android.widget.Toast;
  26. import com.alibaba.fastjson.JSON;
  27. import com.alibaba.fastjson.JSONObject;
  28. import com.android.volley.Request.Method;
  29. import com.android.volley.Response;
  30. import com.android.volley.error.VolleyError;
  31. import com.android.volley.request.FastJsonRequest;
  32. import com.lidroid.xutils.HttpUtils;
  33. import com.lidroid.xutils.exception.HttpException;
  34. import com.lidroid.xutils.http.RequestParams;
  35. import com.lidroid.xutils.http.ResponseInfo;
  36. import com.lidroid.xutils.http.callback.RequestCallBack;
  37. import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
  38. import com.sinonetwork.zhonghua.model.ShengFenModel;
  39. import com.sinonetwork.zhonghua.model.ShengFenModel.ShengFenModels;
  40. import com.sinonetwork.zhonghua.model.ZHAccount;
  41. import com.sinonetwork.zhonghua.net.RequestManager;
  42. import com.sinonetwork.zhonghua.utils.URLAddress;
  43. import com.sinonetwork.zhonghua.utils.ZhAccountPrefUtil;
  44. import com.sinonetwork.zhonghua.utils.log.Logger;
  45. import com.sinonetwork.zhonghua.wheel.StrericWheelAdapter;
  46. import com.sinonetwork.zhonghua.wheel.WheelView;
  47. public class Soil_Test extends Activity {
  48. private ImageView back;
  49. private WheelView yearWheel, monthWheel, dayWheel;
  50. public static String[] yearContent = null;
  51. public static String[] monthContent = null;
  52. public static String[] dayContent = null;
  53. public static String[] hourContent = null;
  54. public static String[] minuteContent = null;
  55. public static String[] secondContent = null;
  56. private RelativeLayout relativeLayout;
  57. private TextView soil_shijian; // 时间
  58. private Spinner soil_diqu; // 地区
  59. private Button soil_bt1; // 预约按钮
  60. private EditText soil_lianxi; // 联系人
  61. private EditText soil_dianhua; // 联系电话
  62. private TextView yonghu_diqu;
  63. private List<ShengFenModels> sdata;
  64. private List<String> list;
  65. private String name;
  66. private String shengId;
  67. private String yhdq;
  68. private final int DATE_DIALOG = 1;
  69. private final int TIME_DIALOG = 2;
  70. protected void onCreate(Bundle savedInstanceState) {
  71. // TODO Auto-generated method stub
  72. super.onCreate(savedInstanceState);
  73. setContentView(R.layout.soil_test);
  74. //默认情况下软件盘不自动弹出
  75. getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  76. //寻找控件
  77. soil_shijian = (TextView) findViewById(R.id.soil_shijian);
  78. relativeLayout = (RelativeLayout) findViewById(R.id.soil_rl3);
  79. soil_diqu = (Spinner) findViewById(R.id.soil_diqu);
  80. soil_bt1 = (Button) findViewById(R.id.soil_bt1);
  81. soil_lianxi = (EditText) findViewById(R.id.soil_lianxi);
  82. soil_dianhua = (EditText) findViewById(R.id.soil_dianhua);
  83. yonghu_diqu = (TextView) findViewById(R.id.yonghu_diqu);
  84. //保存账户信息
  85. ZHAccount currentAccount = ZhAccountPrefUtil
  86. .getZHAccount(Soil_Test.this.getApplicationContext());
  87. name = currentAccount.getUserName();
  88. shengId = String.valueOf(currentAccount.getParent_areaId());
  89. yhdq = String.valueOf(currentAccount.getParent_areaName());
  90. yonghu_diqu.setText(yhdq);
  91. Sehng(); // 省份
  92. initContent();
  93. back = (ImageView) findViewById(R.id.back);
  94. //向服务端提交数据
  95. soil_bt1.setOnClickListener(new OnClickListener() {
  96. @Override
  97. public void onClick(View arg0) {
  98. // TODO Auto-generated method stub //张三为临时测试app用户名
  99. if(isMobileNO(soil_dianhua.getText().toString())){
  100. register("orderTestSoil", name, soil_lianxi.getText()
  101. .toString(), soil_dianhua.getText().toString(),
  102. soil_shijian.getText().toString(),shengId,yhdq );}else{
  103. Toast.makeText(getApplicationContext(), "输入号码错误,请重新输入", 0).show();
  104. soil_dianhua.setText("");
  105. }
  106. //soil_diqu.getSelectedItem().toString()
  107. Logger.e("省ID========="+shengId);
  108. }
  109. });
  110. back.setOnClickListener(new OnClickListener() {
  111. @Override
  112. public void onClick(View v) {
  113. // TODO Auto-generated method stub
  114. finish();
  115. }
  116. });
  117. // ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
  118. // R.array.planets, android.R.layout.simple_spinner_item);
  119. // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  120. // soil_diqu.setAdapter(adapter);
  121. //时间选取模块
  122. relativeLayout.setOnClickListener(new OnClickListener() {
  123. @Override
  124. public void onClick(View v) {
  125. // TODO Auto-generated method stub
  126. View view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
  127. .inflate(R.layout.time_picker, null);
  128. Calendar calendar = Calendar.getInstance();
  129. int curYear = calendar.get(Calendar.YEAR);
  130. int curMonth = calendar.get(Calendar.MONTH) + 1;
  131. int curDay = calendar.get(Calendar.DAY_OF_MONTH);
  132. // int curHour = calendar.get(Calendar.HOUR_OF_DAY);
  133. // int curMinute = calendar.get(Calendar.MINUTE);
  134. // int curSecond = calendar.get(Calendar.SECOND);
  135. yearWheel = (WheelView) view.findViewById(R.id.yearwheel);
  136. monthWheel = (WheelView) view.findViewById(R.id.monthwheel);
  137. dayWheel = (WheelView) view.findViewById(R.id.daywheel);
  138. // hourWheel = (WheelView) view.findViewById(R.id.hourwheel);
  139. // minuteWheel = (WheelView) view.findViewById(R.id.minutewheel);
  140. // secondWheel = (WheelView) view.findViewById(R.id.secondwheel);
  141. //选取时间
  142. AlertDialog.Builder builder = new AlertDialog.Builder(
  143. Soil_Test.this);
  144. builder.setView(view);
  145. yearWheel.setAdapter(new StrericWheelAdapter(yearContent));
  146. yearWheel.setCurrentItem(curYear - 2013);
  147. yearWheel.setCyclic(true);
  148. yearWheel
  149. .setInterpolator(new AnticipateOvershootInterpolator());
  150. monthWheel.setAdapter(new StrericWheelAdapter(monthContent));
  151. monthWheel.setCurrentItem(curMonth - 1);
  152. monthWheel.setCyclic(true);
  153. monthWheel
  154. .setInterpolator(new AnticipateOvershootInterpolator());
  155. dayWheel.setAdapter(new StrericWheelAdapter(dayContent));
  156. dayWheel.setCurrentItem(curDay - 1);
  157. dayWheel.setCyclic(true);
  158. dayWheel.setInterpolator(new AnticipateOvershootInterpolator());
  159. // hourWheel.setAdapter(new StrericWheelAdapter(hourContent));
  160. // hourWheel.setCurrentItem(curHour);
  161. // hourWheel.setCyclic(true);
  162. // hourWheel
  163. // .setInterpolator(new AnticipateOvershootInterpolator());
  164. //
  165. // minuteWheel.setAdapter(new StrericWheelAdapter(minuteContent));
  166. // minuteWheel.setCurrentItem(curMinute);
  167. // minuteWheel.setCyclic(true);
  168. // minuteWheel
  169. // .setInterpolator(new AnticipateOvershootInterpolator());
  170. //
  171. // secondWheel.setAdapter(new StrericWheelAdapter(secondContent));
  172. // secondWheel.setCurrentItem(curSecond);
  173. // secondWheel.setCyclic(true);
  174. // secondWheel
  175. // .setInterpolator(new AnticipateOvershootInterpolator());
  176. builder.setTitle("选取时间");
  177. builder.setPositiveButton("确 定",
  178. new DialogInterface.OnClickListener() {
  179. @Override
  180. public void onClick(DialogInterface dialog,
  181. int which) {
  182. StringBuffer sb = new StringBuffer();
  183. int xyear = Integer.valueOf(yearWheel.getCurrentItemValue());//获取年份
  184. int xmonth=Integer.valueOf(monthWheel.getCurrentItemValue());//获取月份
  185. int xday=Integer.valueOf(dayWheel.getCurrentItemValue());//获取日
  186. sb.append(yearWheel.getCurrentItemValue())
  187. .append("-")
  188. .append(monthWheel
  189. .getCurrentItemValue())
  190. .append("-")
  191. .append(dayWheel.getCurrentItemValue());
  192. Calendar ca = Calendar.getInstance();
  193. int year = ca.get(Calendar.YEAR);//获取年份
  194. int month=ca.get(Calendar.MONTH);//获取月份
  195. int day=ca.get(Calendar.DATE);//获取日
  196. // Toast.makeText(Soil_Test.this, "-----"+year+"-"+(month+1)+"-"+day, Toast.LENGTH_SHORT).show();
  197. if((xyear>=year&&xmonth>(month+1))||(xyear>=year&&xmonth==(month+1)&&xday>=day)||xyear>year){
  198. soil_shijian.setText(sb);
  199. }else{
  200. Toast.makeText(Soil_Test.this, "时间不能为以前!", Toast.LENGTH_SHORT).show();
  201. }
  202. // sb.append(" ");
  203. // sb.append(hourWheel.getCurrentItemValue())
  204. // .append(":")
  205. // .append(minuteWheel
  206. // .getCurrentItemValue())
  207. // .append(":")
  208. // .append(secondWheel
  209. // .getCurrentItemValue());
  210. dialog.cancel();
  211. }
  212. });
  213. builder.show();
  214. }
  215. });
  216. }
  217. //判断一个号码是否为电话号码
  218. public boolean isMobileNO(String mobiles){
  219. Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
  220. Matcher m = p.matcher(mobiles);
  221. return m.matches();
  222. }
  223. // ------------------------------------------------------------------------------------------------------------------
  224. /**
  225. * 测土(解决方案中的)
  226. * 向服务器端提交数据
  227. * @param method
  228. * @param userName
  229. * @param contactName
  230. * @param phoneNumber
  231. * @param orderTimeStr
  232. * @param regionName
  233. */
  234. private void register(String method, String userName, String contactName,
  235. String phoneNumber, String orderTime, String regionId,
  236. String regionName) {
  237. RequestParams params = new RequestParams();
  238. params.addBodyParameter("method", method);
  239. params.addBodyParameter("userName", userName);//App登录用户名
  240. params.addBodyParameter("contactName", contactName);//联系人
  241. params.addBodyParameter("phoneNumber", phoneNumber);//联系电话
  242. params.addBodyParameter("orderTime", orderTime);//预约时间
  243. params.addBodyParameter("regionId", regionId);
  244. params.addBodyParameter("regionName", regionName);//地区ƒ
  245. Logger.e("weather===" + method + "----" + userName + "-----"
  246. + contactName + "------" + phoneNumber + "------" + orderTime
  247. + "-----" + regionName);
  248. HttpUtils http = new HttpUtils();
  249. http.send(HttpMethod.POST, URLAddress.orderTestSoilURL, params,
  250. new RequestCallBack<String>() {
  251. @Override
  252. public void onLoading(long total, long current,
  253. boolean isUploading) {
  254. // testTextView.setText(current + "/" + total);
  255. // Toast.makeText(ItemActivity.this, "卸载",
  256. // Toast.LENGTH_SHORT).show();
  257. }
  258. @Override
  259. public void onSuccess(ResponseInfo<String> responseInfo) {
  260. // Toast.makeText(ItemActivity.this, "进来",
  261. // Toast.LENGTH_SHORT).show();
  262. JSONObject resultcode = JSON
  263. .parseObject(responseInfo.result);
  264. String result = resultcode.getString("resultcode");
  265. // String msg = object.getString("message");
  266. // Toast.makeText(Soil_Test.this, result,
  267. // Toast.LENGTH_SHORT).show();
  268. if ("ok".equals(result)) {// 成功
  269. // Toast.makeText(Soil_Test.this, "提交成功",
  270. // Toast.LENGTH_SHORT).show();
  271. initToast();
  272. new Handler().postDelayed(new Runnable() {
  273. @Override
  274. public void run() {
  275. finish();
  276. }
  277. }, 2000);
  278. } else {
  279. Toast.makeText(Soil_Test.this, "提交失败",
  280. Toast.LENGTH_SHORT).show();
  281. }
  282. }
  283. @Override
  284. public void onStart() {
  285. // Toast.makeText(ItemActivity.this, "开始",
  286. // Toast.LENGTH_SHORT).show();
  287. }
  288. @Override
  289. public void onFailure(HttpException error, String msg) {
  290. Toast.makeText(Soil_Test.this, "A服务器异常!",
  291. Toast.LENGTH_SHORT).show();
  292. }
  293. });
  294. }
  295. /**
  296. * 自定义Tost
  297. */
  298. private void initToast() {
  299. View toastRoot = getLayoutInflater().inflate(R.layout.custom_layout,
  300. null);
  301. TextView message = (TextView) toastRoot.findViewById(R.id.tvToast);
  302. message.setText("预约成功");
  303. Toast toastStart = new Toast(this);
  304. toastStart.setGravity(Gravity.CENTER, 0, 10);
  305. toastStart.setDuration(2000);
  306. toastStart.setView(toastRoot);
  307. toastStart.show();
  308. }
  309. /**
  310. * 获取省
  311. */
  312. public void Sehng() {
  313. sdata = new ArrayList<ShengFenModels>();
  314. Logger.e("No1s");
  315. FastJsonRequest<ShengFenModel> fastJson = new FastJsonRequest<ShengFenModel>(
  316. Method.POST, URLAddress.SomeAreaURL, ShengFenModel.class, null,
  317. null, new Response.Listener<ShengFenModel>() {
  318. @Override
  319. public void onResponse(ShengFenModel weather) {
  320. // 赋值
  321. sdata.addAll(weather.getResultdata());
  322. if (sdata.size() == 0 || sdata == null) {
  323. Toast.makeText(Soil_Test.this, "省份没有数据",
  324. Toast.LENGTH_SHORT).show();
  325. } else {
  326. // Toast.makeText(Comprehensive_list.this,
  327. // "省份数量"+String.valueOf(sdata.size())+"===="+sdata.get(1).getAREANAME().toString(),
  328. // Toast.LENGTH_SHORT).show();
  329. // adapter.notifyDataSetChanged();
  330. list = new ArrayList<String>();
  331. for (int i = 0; i < sdata.size(); i++) {
  332. list.add(sdata.get(i).getAREANAME().toString());
  333. }
  334. ArrayAdapter<String> adapters = new ArrayAdapter<String>(
  335. Soil_Test.this, R.layout.guojia_item,
  336. R.id.tvCateItem, list);
  337. soil_diqu.setAdapter(adapters);
  338. }
  339. }
  340. }, new Response.ErrorListener() {
  341. @Override
  342. public void onErrorResponse(VolleyError arg0) {
  343. // TODO Auto-generated method stub
  344. Logger.e("No3");
  345. Logger.e("VolleyError===" + arg0.getMessage());
  346. Toast.makeText(Soil_Test.this, "服务器异常!",
  347. Toast.LENGTH_SHORT).show();
  348. }
  349. });
  350. Logger.e("No4" + fastJson);
  351. RequestManager.addRequest(fastJson, this);
  352. }
  353. public void initContent() {
  354. yearContent = new String[10];
  355. for (int i = 0; i < 10; i++)
  356. yearContent[i] = String.valueOf(i + 2013);
  357. monthContent = new String[12];
  358. for (int i = 0; i < 12; i++) {
  359. monthContent[i] = String.valueOf(i + 1);
  360. if (monthContent[i].length() < 2) {
  361. monthContent[i] = "0" + monthContent[i];
  362. }
  363. }
  364. dayContent = new String[31];
  365. for (int i = 0; i < 31; i++) {
  366. dayContent[i] = String.valueOf(i + 1);
  367. if (dayContent[i].length() < 2) {
  368. dayContent[i] = "0" + dayContent[i];
  369. }
  370. }
  371. hourContent = new String[24];
  372. for (int i = 0; i < 24; i++) {
  373. hourContent[i] = String.valueOf(i);
  374. if (hourContent[i].length() < 2) {
  375. hourContent[i] = "0" + hourContent[i];
  376. }
  377. }
  378. minuteContent = new String[60];
  379. for (int i = 0; i < 60; i++) {
  380. minuteContent[i] = String.valueOf(i);
  381. if (minuteContent[i].length() < 2) {
  382. minuteContent[i] = "0" + minuteContent[i];
  383. }
  384. }
  385. secondContent = new String[60];
  386. for (int i = 0; i < 60; i++) {
  387. secondContent[i] = String.valueOf(i);
  388. if (secondContent[i].length() < 2) {
  389. secondContent[i] = "0" + secondContent[i];
  390. }
  391. }
  392. }
  393. public void buttonClick(View v) {
  394. int id = v.getId();
  395. if (id == R.id.soil_rl3) {
  396. }
  397. }
  398. }