PageRenderTime 1534ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/sinonetwork/zhonghua/QixiangSolid.java

https://gitlab.com/zwp/Zhonghua
Java | 197 lines | 153 code | 41 blank | 3 comment | 6 complexity | 48df76db506ebd0ffb7fa8424ce1d494 MD5 | raw file
  1. package com.sinonetwork.zhonghua;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import java.util.Locale;
  5. import org.apache.http.Header;
  6. import com.alibaba.fastjson.JSON;
  7. import com.loopj.android.http.AsyncHttpClient;
  8. import com.loopj.android.http.AsyncHttpResponseHandler;
  9. import android.app.Activity;
  10. import android.app.AlertDialog;
  11. import android.app.DatePickerDialog;
  12. import android.app.DatePickerDialog.OnDateSetListener;
  13. import android.app.TimePickerDialog;
  14. import android.app.TimePickerDialog.OnTimeSetListener;
  15. import android.graphics.Bitmap;
  16. import android.graphics.BitmapFactory;
  17. import android.os.Bundle;
  18. import android.util.Base64;
  19. import android.util.Log;
  20. import android.view.View;
  21. import android.view.View.OnClickListener;
  22. import android.widget.Button;
  23. import android.widget.DatePicker;
  24. import android.widget.ImageView;
  25. import android.widget.ProgressBar;
  26. import android.widget.TextView;
  27. import android.widget.TimePicker;
  28. public class QixiangSolid extends Activity {
  29. private ImageView iv;
  30. private ImageView back;
  31. private int year;
  32. private int month;
  33. private int day;
  34. private int h;
  35. private int mi;
  36. private String date = "";
  37. private String time = "";
  38. private TextView tv_date;
  39. private TextView tv_time;
  40. private Button bt_search;
  41. private ProgressBar pb;
  42. @Override
  43. protected void onCreate(Bundle savedInstanceState) {
  44. super.onCreate(savedInstanceState);
  45. setContentView(R.layout.qixiang_solid);
  46. iv = (ImageView) findViewById(R.id.qixiang_solid_iv);
  47. back = (ImageView) findViewById(R.id.back);
  48. tv_date = (TextView) findViewById(R.id.tv_date);
  49. tv_time = (TextView) findViewById(R.id.tv_time);
  50. bt_search = (Button) findViewById(R.id.bt_search);
  51. pb=(ProgressBar) findViewById(R.id.qixiang_solid_progressBar);
  52. initTime();
  53. setDefault();
  54. setListener();
  55. }
  56. private void setDefault() {
  57. tv_date.setText(date);
  58. tv_time.setText(time);
  59. }
  60. private void setListener() {
  61. back.setOnClickListener(new OnClickListener() {
  62. @Override
  63. public void onClick(View v) {
  64. finish();
  65. }
  66. });
  67. tv_date.setOnClickListener(new OnClickListener() {
  68. @Override
  69. public void onClick(View v) {
  70. new DatePickerDialog(QixiangSolid.this,
  71. AlertDialog.THEME_HOLO_LIGHT, new OnDateSetListener() {
  72. @Override
  73. public void onDateSet(DatePicker view, int year,
  74. int monthOfYear, int dayOfMonth) {
  75. monthOfYear++;
  76. date = "" + year;
  77. if (monthOfYear < 10) {
  78. date += "0" + monthOfYear;
  79. } else {
  80. date += monthOfYear;
  81. }
  82. if (dayOfMonth < 10) {
  83. date += "0" + dayOfMonth;
  84. } else {
  85. date += dayOfMonth;
  86. }
  87. tv_date.setText(date);
  88. }
  89. }, year, month, day).show();
  90. }
  91. });
  92. tv_time.setOnClickListener(new OnClickListener() {
  93. @Override
  94. public void onClick(View v) {
  95. new TimePickerDialog(QixiangSolid.this,
  96. AlertDialog.THEME_HOLO_LIGHT, new OnTimeSetListener() {
  97. @Override
  98. public void onTimeSet(TimePicker view,
  99. int hourOfDay, int minute) {
  100. time = "" + hourOfDay + minute;
  101. tv_time.setText(time);
  102. }
  103. }, h, mi, true).show();
  104. }
  105. });
  106. bt_search.setOnClickListener(new OnClickListener() {
  107. @Override
  108. public void onClick(View v) {
  109. pb.setVisibility(View.VISIBLE);
  110. iv.setVisibility(View.INVISIBLE);
  111. loadData();
  112. }
  113. });
  114. }
  115. private void initTime() {
  116. Calendar mycalendar = Calendar.getInstance(Locale.CHINA);
  117. year = mycalendar.get(Calendar.YEAR);
  118. month = mycalendar.get(Calendar.MONTH);
  119. day = mycalendar.get(Calendar.DAY_OF_MONTH);
  120. h = mycalendar.get(Calendar.HOUR_OF_DAY);
  121. mi = mycalendar.get(Calendar.MINUTE);
  122. date = new SimpleDateFormat("yyyyMMdd").format(mycalendar.getTime());
  123. time = new SimpleDateFormat("HH:mm").format(mycalendar.getTime());
  124. }
  125. private void loadData() {
  126. String url = " http://211.94.93.238/zhnyxxgc/httpservice.action?method=searchTAsmm&date=" + date + time;
  127. // Log.i("lk", "url:" + url);
  128. // Log.i("gxx", "土壤url:" + url);
  129. new AsyncHttpClient().get(url, new AsyncHttpResponseHandler() {
  130. @Override
  131. public void onStart() {
  132. }
  133. @Override
  134. public void onSuccess(int statusCode, Header[] headers,
  135. byte[] response) {
  136. String x = new String(response);
  137. JsonTuRang shuju = JSON.parseObject(x, JsonTuRang.class);
  138. // Log.i("lk", "code:" + shuju.getResultcode());
  139. if (shuju.getResultdata() != null) {
  140. byte[] array = Base64.decode(shuju.getResultdata().getD2(), Base64.DEFAULT);
  141. Bitmap bm = BitmapFactory.decodeByteArray(array, 0, array.length);
  142. pb.setVisibility(View.INVISIBLE);
  143. iv.setVisibility(View.VISIBLE);
  144. iv.setImageBitmap(bm);
  145. }
  146. }
  147. @Override
  148. public void onFailure(int statusCode, Header[] headers,
  149. byte[] errorResponse, Throwable e) {
  150. }
  151. @Override
  152. public void onRetry(int retryNo) {
  153. }
  154. });
  155. }
  156. }