PageRenderTime 152ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/Android/src/com/drhelper/task/CheckTableTask.java

https://github.com/weiganyi/dr-helper
Java | 69 lines | 52 code | 14 blank | 3 comment | 10 complexity | b14d7d6ad476713e87f2a061324ec06b MD5 | raw file
  1. package com.drhelper.task;
  2. import java.util.List;
  3. import com.alibaba.fastjson.JSON;
  4. import com.drhelper.activity.CheckTableActivity;
  5. import com.drhelper.bean.com.EmptyTable;
  6. import com.drhelper.bean.com.EmptyTableList;
  7. import com.drhelper.util.HttpEngine;
  8. import android.app.Activity;
  9. import android.os.AsyncTask;
  10. import android.util.Log;
  11. public class CheckTableTask extends AsyncTask<String, Integer, Integer> {
  12. private static final String CHECK_TABLE_TASK_TAG = "CheckTableTask";
  13. private Activity act;
  14. private EmptyTableList emptyTableListResp = null;
  15. public static final int CHECK_TABLE_TASK_SUCCESS = 0;
  16. public static final int CHECK_TABLE_TASK_LOCAL_FALIURE = 1;
  17. public static final int CHECK_TABLE_TASK_REMOTE_FALIURE = 2;
  18. public CheckTableTask(Activity act) {
  19. //save the Activity that call this AsyncTask
  20. this.act = act;
  21. }
  22. protected void onPreExecute() {
  23. }
  24. protected void onProgressUpdate(Integer... progress) {
  25. }
  26. protected void onPostExecute(Integer result) {
  27. List<EmptyTable> emptyTableList = null;
  28. if (emptyTableListResp != null) {
  29. emptyTableList = emptyTableListResp.getList();
  30. }
  31. ((CheckTableActivity)act).doCheckTableResult(result, emptyTableList);
  32. }
  33. @Override
  34. protected Integer doInBackground(String... param) {
  35. try {
  36. //send the http post and recv response
  37. String specUrl = "checkTable.do";
  38. String respBody = HttpEngine.doPost(specUrl, null);
  39. if (respBody != null && respBody.length() != 0) {
  40. //unserialize from response string
  41. emptyTableListResp = JSON.parseObject(respBody, EmptyTableList.class);
  42. if (emptyTableListResp != null && emptyTableListResp.isResult() == true) {
  43. return CHECK_TABLE_TASK_SUCCESS;
  44. }else {
  45. return CHECK_TABLE_TASK_REMOTE_FALIURE;
  46. }
  47. }else {
  48. Log.e(CHECK_TABLE_TASK_TAG, "CheckTableTask.doInBackground(): respBody is null");
  49. }
  50. }catch(Exception e) {
  51. Log.e(CHECK_TABLE_TASK_TAG, "CheckTableTask.doInBackground(): json serialize or http post is failure");
  52. }
  53. return CHECK_TABLE_TASK_LOCAL_FALIURE;
  54. }
  55. }