예제 #1
1
  // build query
  @Override
  protected String buildQueryUrl(RequestParams params) {
    String uri = params.getUri();
    StringBuilder queryBuilder = new StringBuilder(uri);
    if (!uri.contains("?")) {
      queryBuilder.append("?");
    } else if (!uri.endsWith("?")) {
      queryBuilder.append("&");
    }
    HashMap<String, String> queryParams = params.getQueryStringParams();
    if (queryParams != null) {
      for (Map.Entry<String, String> entry : queryParams.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) {
          queryBuilder.append(Uri.encode(name)).append("=").append(Uri.encode(value)).append("&");
        }
      }
      if (queryBuilder.charAt(queryBuilder.length() - 1) == '&') {
        queryBuilder.deleteCharAt(queryBuilder.length() - 1);
      }
    }

    if (queryBuilder.charAt(queryBuilder.length() - 1) == '?') {
      queryBuilder.deleteCharAt(queryBuilder.length() - 1);
    }
    return queryBuilder.toString();
  }
예제 #2
0
 /**
  * 下载文件
  *
  * @param params 请求参数
  * @param filepath 保存路径
  */
 public static File downloadFile(RequestParams params, String filepath) throws TaskException {
   // 设置断点续传
   params.setAutoResume(true);
   params.setSaveFilePath(filepath);
   try {
     return x.http().getSync(params, File.class);
   } catch (SocketTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (ConnectTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (UnknownHostException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (IOException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (Throwable throwable) {
     TaskException taskException = null;
     if (throwable.getCause() instanceof TaskException) {
       taskException = (TaskException) throwable.getCause();
     } else if (throwable instanceof TaskException) {
       taskException = (TaskException) throwable;
     }
     if (taskException != null) {
       throw taskException;
     }
     throw new TaskException(
         "", TextUtils.isEmpty(throwable.getMessage()) ? "服务器错误" : throwable.getMessage());
   }
 }
예제 #3
0
파일: BaseTask.java 프로젝트: akvsdk/Xutil3
 public Cancelable requestByPost(String url, Map<String, Object> map) {
   RequestParams params = new RequestParams(url);
   if (null != map) {
     for (Map.Entry<String, Object> entry : map.entrySet()) {
       params.addParameter(entry.getKey(), entry.getValue());
     }
   }
   Cancelable cancelable = x.http().post(params, this);
   return cancelable;
 }
예제 #4
0
  /** 发送注册请求 */
  private void register() {
    phone = phone_edittext.getText().toString();
    pwd = pwd_edittext.getText().toString();
    pwd_affirm = pwd_affirm_edittext.getText().toString();
    code = code_edittext.getText().toString();

    if (StringUtils.isPhone(phone)) {
      if (StringUtils.isNULL(code)) {
        ActivityUtils.toast(getActivity(), "请输入验证码!");
      } else {
        if ("1234".equals(code)) {
          if (StringUtils.isNULL(pwd)) {
            ActivityUtils.toast(getActivity(), "请输入密码!");
          } else {
            if (StringUtils.isNULL(pwd_affirm)) {
              ActivityUtils.toast(getActivity(), "请再次输入密码!");
            } else {
              if (pwd.equals(pwd_affirm)) {

                RequestParams params = new RequestParams("");
                params.addBodyParameter("img", new File("url"));
                x.http()
                    .post(
                        params,
                        new Callback.CommonCallback<String>() {

                          @Override
                          public void onSuccess(String result) {}

                          @Override
                          public void onError(Throwable ex, boolean isOnCallback) {}

                          @Override
                          public void onCancelled(CancelledException cex) {}

                          @Override
                          public void onFinished() {}
                        });
                ActivityUtils.toast(getActivity(), "修改成功!");
              } else {
                ActivityUtils.toast(getActivity(), "两次输入密码不同、请确认后再试!");
              }
            }
          }
        } else {
          ActivityUtils.toast(getActivity(), "验证码错误");
        }
      }
    } else {
      ActivityUtils.toast(getActivity(), "请输入正确的手机号!");
    }
  }
예제 #5
0
 public static <T> T uploadFile(RequestParams params, Class<T> responseCls) throws TaskException {
   try {
     params.setMultipart(true);
     return x.http().postSync(params, responseCls);
   } catch (SocketTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (ConnectTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (UnknownHostException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (IOException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (Throwable throwable) {
     TaskException taskException = null;
     if (throwable.getCause() instanceof TaskException) {
       taskException = (TaskException) throwable.getCause();
     } else if (throwable instanceof TaskException) {
       taskException = (TaskException) throwable;
     }
     if (taskException != null) {
       throw taskException;
     }
     throw new TaskException(
         "", TextUtils.isEmpty(throwable.getMessage()) ? "服务器错误" : throwable.getMessage());
   }
 }
  // 更新服务器用户信息
  private void updateServerUser(final String imgKey) {
    RequestParams params = new RequestParams(GlobalContants.UPDATE_AVATAR_URL);
    params.addQueryStringParameter("user_id", userID);
    params.addQueryStringParameter("image_key", imgKey);
    x.http()
        .post(
            params,
            new Callback.CommonCallback<String>() {
              @Override
              public void onSuccess(String result) {
                LogUtils.d("result", result);
                updateAvatarInJPush(imgKey);
              }

              @Override
              public void onError(Throwable ex, boolean isOnCallback) {}

              @Override
              public void onCancelled(CancelledException cex) {}

              @Override
              public void onFinished() {}
            });
  }
예제 #7
0
  private void initdata() {
    RequestParams params = new RequestParams(HttpIP.MainService + HttpIP.PhoneMan);
    params.addBodyParameter("parameter", "");
    params.setAsJsonContent(true);
    params.addBodyParameter(SaveMsg.TOKENID, sp.getString(SaveMsg.TOKENID, ""));
    x.http()
        .post(
            params,
            new Callback.CommonCallback<String>() {
              @Override
              public void onSuccess(String result) {
                String s = AES.desEncrypt(result.toString());
                Log.d("result", result.toString());
                try {
                  JSONObject object2 = new JSONObject(s);
                  int code = object2.getInt("ErrorCode");
                  if (code == 1) {
                    no_msg.setVisibility(View.VISIBLE);
                    list.setVisibility(View.GONE);
                    Toast.makeText(
                            getActivity(),
                            object2.getString("ErrorMsg").toString(),
                            Toast.LENGTH_SHORT)
                        .show();
                  } else if (code == 0) {
                    no_msg.setVisibility(View.GONE);
                    list.setVisibility(View.VISIBLE);
                    String resultman = object2.getString("Result").toString();
                    JSONArray array = new JSONArray(resultman);
                    JSONObject object3 = array.getJSONObject(0);
                    String UnitBook = object3.getString("UnitBook").toString();
                    String UnitInfo = object3.getString("UnitInfo").toString();
                    String UserBook = object3.getString("UserBook").toString();
                    MsgUnitInfo(UnitInfo);
                    MsgUserBook(UserBook);
                    MsgUnitBook(UnitBook);
                  }
                } catch (JSONException e) {
                  no_msg.setVisibility(View.VISIBLE);
                  list.setVisibility(View.GONE);
                  e.printStackTrace();
                } catch (DbException e) {
                  no_msg.setVisibility(View.VISIBLE);
                  list.setVisibility(View.GONE);
                  e.printStackTrace();
                }
              }

              @Override
              public void onError(Throwable ex, boolean isOnCallback) {
                no_msg.setVisibility(View.VISIBLE);
                list.setVisibility(View.GONE);
              }

              @Override
              public void onCancelled(CancelledException cex) {}

              @Override
              public void onFinished() {}
            });
  }
        @Override
        public void handleMessage(Message message) {
          // TODO Auto-generated method stub
          super.handleMessage(message);
          final String zhuangtai = (String) message.obj;
          switch (message.what) {
            case UPDATE_TIME:
              RequestParams params = new RequestParams(UrlData.URL_UPDATE_TIME);
              params.addBodyParameter("授权用户", UrlData.ADMIN_UID);
              params.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
              params.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
              params.addBodyParameter("设备ID", mTeamViewData.mIdText);
              params.addBodyParameter("使用时间", mTeamViewData.BEGIN_TIME);
              log(
                  "用户ID="
                      + mTeamViewData.mPCIDTEXT
                      + ";设备ID="
                      + mTeamViewData.mIdText
                      + "连接判断="
                      + "使用时间="
                      + mTeamViewData.BEGIN_TIME);
              x.http()
                  .post(
                      params,
                      new CommonCallback<String>() {
                        @Override
                        public void onSuccess(String result) {
                          InputStream sbs = new ByteArrayInputStream(result.getBytes());
                          try {
                            String response = XMLParse.parseResponseCheck(sbs);
                            log("连接判断 response=" + response);
                            if (response.equals("成功")) {
                              handler.removeMessages(UPDATE_TIME);
                              handler.sendEmptyMessageDelayed(UPDATE_TIME, UPDATE_TIME_TIME);
                            } else {
                              handler.removeMessages(UPDATE_TIME);
                              handler.sendEmptyMessageDelayed(UPDATE_TIME, UPDATE_TIME_TIME);
                            }
                          } catch (Exception e) {
                          }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                          log("连接判断 error" + ex.getMessage());
                        }

                        @Override
                        public void onCancelled(CancelledException cex) {}

                        @Override
                        public void onFinished() {}
                      });

              break;
            case SHUT_DOWN_TEAM:
              if (state == STATC_CONNECTION_SUCCESS) {
                handler.removeMessages(SHUT_DOWN_CONNECTION);
                handler.sendEmptyMessage(SHUT_DOWN_CONNECTION);
              }

              break;
            case UPDATE_STARTEAM:
              startTeamView();
              break;
            case OPEN:
              log("restart state=" + state);
              if (state != STATC_CONNECTION_SUCCESS) {
                Intent mIntent = new Intent();
                mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                ComponentName comp = new ComponentName(paName, MAIN_ACTIVITY);
                mIntent.setComponent(comp);
                mIntent.setAction("android.intent.action.VIEW");
                startActivity(mIntent);
              }
              handler.removeMessages(OPEN);
              handler.sendEmptyMessageDelayed(OPEN, RESTART);
              break;
            case SHUT_DOWN_CONNECTION:
              state = STATC_CONNECTION_OVER;
              handler.removeCallbacksAndMessages(null);
              // 杀死进程,重启teamview
              log("kill killBackgroundProcesses");
              try {
                Process suProcess = Runtime.getRuntime().exec("su");
                DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
                os.writeBytes("adb shell" + "\n");
                os.flush();
                os.writeBytes("am force-stop " + paName + "\n");
                os.flush();
              } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                log(e.getMessage());
              }
              if (processWatcher != null) {
                processWatcher.stop();
              }
              handler.removeMessages(UPDATE_STARTEAM);
              handler.sendEmptyMessageDelayed(UPDATE_STARTEAM, 1000 * 8);

              RequestParams params2 = new RequestParams(UrlData.URL_UPDATE_TIME_END);
              params2.addBodyParameter("授权用户", UrlData.ADMIN_UID);
              params2.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
              params2.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
              params2.addBodyParameter("设备ID", mTeamViewData.mIdText);
              params2.addBodyParameter("使用时间", mTeamViewData.BEGIN_TIME);
              log(
                  "用户ID="
                      + mTeamViewData.mPCIDTEXT
                      + ";设备ID="
                      + mTeamViewData.mIdText
                      + "使用时间="
                      + mTeamViewData.BEGIN_TIME);
              x.http()
                  .post(
                      params2,
                      new CommonCallback<String>() {
                        @Override
                        public void onSuccess(String result) {
                          InputStream sbs = new ByteArrayInputStream(result.getBytes());
                          try {
                            String response = XMLParse.parseResponseCheck(sbs);
                            log("结束时间 response=" + response);
                            if (response.equals("成功")) { // 结束的时候不用更改状态写入结束信息即可
                              // Message msg = new Message();
                              // msg.what = UPDATE_ZHUANGTAI;
                              // msg.obj = (String) "空闲";
                              // handler.removeMessages(UPDATE_ZHUANGTAI);
                              // handler.sendMessage(msg);
                              handler.removeMessages(UPDATE_SHUTDOWN_ZHUANGTAI);
                              handler.sendEmptyMessage(UPDATE_SHUTDOWN_ZHUANGTAI);
                            }
                          } catch (Exception e) {

                          }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                          log("结束时间 error" + ex.getMessage());
                        }

                        @Override
                        public void onCancelled(CancelledException cex) {}

                        @Override
                        public void onFinished() {}
                      });

              break;
            case UPDATE_ZHUANGTAI:
              log("连接状态=" + zhuangtai);
              RequestParams params3 = new RequestParams(UrlData.URL_UPDATE_ZHUANGTAI);
              params3.addBodyParameter("授权用户", UrlData.ADMIN_UID);
              params3.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
              params3.addBodyParameter("连接状态", zhuangtai);
              params3.addBodyParameter("设备ID", mTeamViewData.mIdText);
              log("连接状态=" + zhuangtai + ";设备ID=" + mTeamViewData.mIdText);
              x.http()
                  .post(
                      params3,
                      new CommonCallback<String>() {
                        @Override
                        public void onSuccess(String result) {
                          InputStream sbs = new ByteArrayInputStream(result.getBytes());
                          try {
                            String response = XMLParse.parseResponseCheck(sbs);
                            log("更新状态 response=" + response);
                            if (response.equals("成功")) {
                              zhuangtaiTimes = 0;
                            } else {
                              if (zhuangtaiTimes < TIMES) {
                                Message msg = new Message();
                                msg.what = UPDATE_ZHUANGTAI;
                                msg.obj = zhuangtai;
                                handler.removeMessages(UPDATE_ZHUANGTAI);
                                handler.sendMessageDelayed(msg, TRY_TIME);
                                zhuangtaiTimes++;
                              }
                            }
                          } catch (Exception e) {
                            log("ZHUANGTAI=" + e.getMessage());
                          }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                          log("更新状态 error" + ex.getMessage());
                        }

                        @Override
                        public void onCancelled(CancelledException cex) {}

                        @Override
                        public void onFinished() {}
                      });

              break;
            case UPDATE_SHUTDOWN_ZHUANGTAI:
              RequestParams params4 = new RequestParams(UrlData.URL_SHUT_DOWN_ZHUANGTAI);
              params4.addBodyParameter("授权用户", UrlData.ADMIN_UID);
              params4.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
              params4.addBodyParameter("设备ID", mTeamViewData.mIdText);
              log("设备ID=" + mTeamViewData.mIdText);
              x.http()
                  .post(
                      params4,
                      new CommonCallback<String>() {
                        @Override
                        public void onSuccess(String result) {
                          InputStream sbs = new ByteArrayInputStream(result.getBytes());
                          try {
                            String response = XMLParse.parseResponseCheck(sbs);
                            log("更新结束信息 response=" + response);
                            if (response.equals("成功")) {
                              shutDownTimes = 0;
                              mTeamViewData.mPCIDTEXT = "";
                              state = STATE_BEGIN;
                            } else {
                              if (shutDownTimes < TIMES) {
                                handler.removeMessages(UPDATE_SHUTDOWN_ZHUANGTAI);
                                handler.sendEmptyMessageDelayed(
                                    UPDATE_SHUTDOWN_ZHUANGTAI, TRY_TIME);
                                shutDownTimes++;
                              }
                            }
                          } catch (Exception e) {
                          }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                          log("更新结束信息 error" + ex.getMessage());
                        }

                        @Override
                        public void onCancelled(CancelledException cex) {}

                        @Override
                        public void onFinished() {}
                      });

              break;
            case UPDATE_BEGIN_ZHUANGTAI: // 写状态时直接调用状态的handler即可
              log("UPDATE_BEGIN_ZHUANGTAI=" + state + ";id=" + mTeamViewData.mIdText);
              if (state == STATE_BEGIN || state == STATE_ACTIVATIONING) // 没有获取到id,正在激活,离线状态
              {
                // 没有获取到id,写入离线状态,并同时再次进行此handler
                // 如果没有获取到id,如何写离线状态?怎么找到对应id的记录写呢?
                mTeamViewData.mIdText = Dbmanager.getUserId();
                Message msg = new Message();
                msg.what = UPDATE_ZHUANGTAI;
                msg.obj = (String) "离线";
                handler.removeMessages(UPDATE_ZHUANGTAI);
                handler.sendMessage(msg);
                handler.removeMessages(UPDATE_BEGIN_ZHUANGTAI);
                handler.sendEmptyMessageDelayed(UPDATE_BEGIN_ZHUANGTAI, UPDATE_BEGIN_TIME_TIME);
              } else if (state == STATE_GET_ID_SUCCESS) // 获取到id,正在空闲状态
              {
                // 成功获取到id,写入空闲状态,并停止handler
                Message msg = new Message();
                msg.what = UPDATE_ZHUANGTAI;
                msg.obj = (String) "空闲";
                handler.removeMessages(UPDATE_ZHUANGTAI);
                handler.sendMessage(msg);
                handler.removeMessages(UPDATE_BEGIN_ZHUANGTAI);
                handler.sendEmptyMessageDelayed(UPDATE_BEGIN_ZHUANGTAI, UPDATE_BEGIN_TIME_TIME);
              }
              break;
            case BEGIN_BEGIN:
              state = STATC_CONNECTION_SUCCESS;
              log("connection success");

              RequestParams params5 = new RequestParams(UrlData.URL_BEGIN_CONNECT);
              params5.addBodyParameter("授权用户", UrlData.ADMIN_UID);
              params5.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
              params5.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
              params5.addBodyParameter("设备ID", mTeamViewData.mIdText);
              params5.addBodyParameter("使用时间", mTeamViewData.BEGIN_TIME);
              log(
                  "用户ID="
                      + mTeamViewData.mPCIDTEXT
                      + ";设备ID="
                      + mTeamViewData.mIdText
                      + "使用时间="
                      + mTeamViewData.BEGIN_TIME);
              x.http()
                  .post(
                      params5,
                      new CommonCallback<String>() {
                        @Override
                        public void onSuccess(String result) {
                          InputStream sbs = new ByteArrayInputStream(result.getBytes());
                          try {
                            String response = XMLParse.parseResponseCheck(sbs);
                            Log.d("DemoLog", "开始时间 response=" + response);
                            if (response.equals("成功")) {
                              // 点击自动允许
                              if (mTeamViewData.allowButton != null) {
                                mTeamViewData.allowButton.performAction(
                                    AccessibilityNodeInfo.ACTION_CLICK);
                                // state = STATE_ALLOW;
                              } else {
                                log("allowButton==null");
                              }
                              Message msg = new Message();
                              msg.what = UPDATE_ZHUANGTAI;
                              msg.obj = (String) "忙碌";
                              handler.removeMessages(UPDATE_ZHUANGTAI);
                              handler.sendMessage(msg);
                              handler.removeMessages(UPDATE_TIME);
                              handler.sendEmptyMessageDelayed(UPDATE_TIME, UPDATE_TIME_TIME);
                              handler.removeMessages(SHUT_DOWN_TEAM);
                              handler.sendEmptyMessageDelayed(SHUT_DOWN_TEAM, SHUT_DOWN_TEAM_TIME);
                              Intent i = new Intent(Intent.ACTION_MAIN);
                              i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                              i.addCategory(Intent.CATEGORY_HOME);
                              startActivity(i);
                            }
                          } catch (Exception e) {
                            log(e.getMessage());
                          }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                          Log.d("DemoLog", "开始时间 error" + ex.getMessage());
                        }

                        @Override
                        public void onCancelled(CancelledException cex) {}

                        @Override
                        public void onFinished() {}
                      });

              break;
          }
        }
  @SuppressLint("NewApi")
  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    // TODO Auto-generated method stub
    int eventType = event.getEventType();
    // AccessibilityNodeInfo my = event.getSource();
    AccessibilityNodeInfo rowNode = getRootInActiveWindow();
    if (rowNode == null) {
      log("noteInfo is null", 1);
      return;
    } else {
      log("class=" + event.getClassName().toString(), 1);
      // List<AccessibilityNodeInfo> nodeInfos = rowNode
      // .findAccessibilityNodeInfosByText("稍后再说");
      // for (AccessibilityNodeInfo nodeInfo : nodeInfos) {
      // nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
      // }
      recycle(rowNode);
    }
    String eventText = "";
    if (mTeamViewData.pidId == 0) {
      getProcessPid();
    }
    log("==============Start====================", 1);
    switch (eventType) {
      case AccessibilityEvent.TYPE_VIEW_CLICKED:
        eventText = "TYPE_VIEW_CLICKED";
        break;
      case AccessibilityEvent.TYPE_VIEW_FOCUSED:
        eventText = "TYPE_VIEW_FOCUSED";
        break;
      case AccessibilityEvent.TYPE_VIEW_LONG_CLICKED:
        eventText = "TYPE_VIEW_LONG_CLICKED";
        break;
      case AccessibilityEvent.TYPE_VIEW_SELECTED:
        eventText = "TYPE_VIEW_SELECTED";
        break;
      case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
        eventText = "TYPE_VIEW_TEXT_CHANGED";
        break;
      case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        eventText = "TYPE_WINDOW_STATE_CHANGED";
        if (event.getClassName().toString().equals(MAIN_ACTIVITY)) {
          int hash = findIDTextView(rowNode);
          if (hash != 0) {
            log("have hash success=" + mTeamViewData.mIdTextHash);
            state = STATE_ACTIVATIONING;
          }
        }
        if (event.getClassName().toString().equals(GET_UID_PC)) {
          if (ReadyPCID(rowNode)) {
            log("have pcid success=" + mTeamViewData.mPCIDTEXT);
            // state = STATE_PC_ID_SUCCESS;
            RequestParams params = new RequestParams(UrlData.URL_CHECK_ID);
            params.addBodyParameter("授权用户", UrlData.ADMIN_UID);
            params.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
            params.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
            params.addBodyParameter("设备ID", mTeamViewData.mIdText);
            log("用户ID=" + mTeamViewData.mPCIDTEXT + ";设备ID=" + mTeamViewData.mIdText);
            x.http()
                .post(
                    params,
                    new Callback.CommonCallback<String>() {
                      @Override
                      public void onSuccess(String result) {
                        log("success");
                        InputStream sbs = new ByteArrayInputStream(result.getBytes());
                        try {
                          String response = XMLParse.parseResponseCheck(sbs);
                          log("response=" + response);
                          if (!response.equals("失败")) {
                            mTeamViewData.BEGIN_TIME = WatchService.toTime2(response);
                            log("mTeamViewData.BEGIN_TIME=" + mTeamViewData.BEGIN_TIME);
                            // 写开始时间
                            handler.removeMessages(BEGIN_BEGIN);
                            handler.sendEmptyMessage(BEGIN_BEGIN);
                          } else {
                            if (mTeamViewData.rejectButton != null) {
                              mTeamViewData.rejectButton.performAction(
                                  AccessibilityNodeInfo.ACTION_CLICK);
                              // state = STATE_REJECT;
                              Message msg = new Message();
                              msg.what = UPDATE_ZHUANGTAI;
                              msg.obj = (String) "空闲";
                              handler.removeMessages(UPDATE_ZHUANGTAI);
                              handler.sendMessage(msg);
                            } else {
                              log("rejectButton==null");
                            }
                          }
                        } catch (Exception e) {
                          log(e.getMessage());
                        }
                      }

                      @Override
                      public void onError(Throwable ex, boolean isOnCallback) {
                        log("error" + ex.getMessage());
                        Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();
                      }

                      @Override
                      public void onCancelled(CancelledException cex) {
                        Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
                      }

                      @Override
                      public void onFinished() {}
                    });
          }
        }
        break;
      case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
        eventText = "TYPE_NOTIFICATION_STATE_CHANGED";
        Notification notification = (Notification) event.getParcelableData();
        List<String> textList = getText(notification);
        if (null != textList && textList.size() > 0) {
          for (String text : textList) {
            if (!TextUtils.isEmpty(text)) {
              log("Notification=" + text);
            }
            if (!TextUtils.isEmpty(text) && text.contains("会话已结束")) {
              log("会话已结束Service");
              handler.removeMessages(SHUT_DOWN_CONNECTION);
              handler.sendEmptyMessage(SHUT_DOWN_CONNECTION);
              break;
            }
          }
        }
        break;
      case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END:
        eventText = "TYPE_TOUCH_EXPLORATION_GESTURE_END";
        break;
      case AccessibilityEvent.TYPE_ANNOUNCEMENT:
        eventText = "TYPE_ANNOUNCEMENT";
        break;
      case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START:
        eventText = "TYPE_TOUCH_EXPLORATION_GESTURE_START";
        break;
      case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER:
        eventText = "TYPE_VIEW_HOVER_ENTER";
        break;
      case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT:
        eventText = "TYPE_VIEW_HOVER_EXIT";
        break;
      case AccessibilityEvent.TYPE_VIEW_SCROLLED:
        eventText = "TYPE_VIEW_SCROLLED";
        break;
      case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
        eventText = "TYPE_VIEW_TEXT_SELECTION_CHANGED";
        break;
      case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        eventText = "TYPE_WINDOW_CONTENT_CHANGED";
        log("event.getClassName().toString()=" + event.getClassName().toString());
        if (event.getClassName().toString().equals(GET_ID_CLASS)
            || event.getClassName().toString().equals(FRAMELAYOUT)
            || event.getClassName().toString().equals("android.widget.EditText")) {
          // if (mTeamViewData.mIdText.equals("")) {// 为空才判断
          if (ReadyID(rowNode)) {
            state = STATE_GET_ID_SUCCESS;
            log("have id success=" + mTeamViewData.mIdText);
            User user = new User();
            user.setmIdText(mTeamViewData.mIdText);
            Dbmanager.saveUser(user);
          }
          // }
        }
        if (event.getClassName().toString().equals("android.widget.FrameLayout")
            || event.getClassName().toString().equals(GET_ID_CLASS)) {
          if (state == STATE_ALLOW) {
            log("connection ing");
            if (ReadyLoad(rowNode)) // 连接成功
            {}
          }
        }
        break;
    }
    eventText = eventText + ":" + eventType;
    log(eventText, 1);
    log("=============END=====================", 1);
  }
예제 #10
0
  @Override
  public void onDestroy() {
    super.onDestroy();
    if (mWakeLock != null) {
      mWakeLock.release();
    }
    if (!TextUtils.isEmpty(mTeamViewData.mIdText) && !TextUtils.isEmpty(mTeamViewData.mPCIDTEXT)) {
      RequestParams params = new RequestParams(UrlData.URL_SHUT_DOWN_OWN);
      params.addBodyParameter("授权用户", UrlData.ADMIN_UID);
      params.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
      params.addBodyParameter("设备ID", mTeamViewData.mIdText);
      params.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
      log("违例结束   设备ID=" + mTeamViewData.mIdText + "用户id=" + mTeamViewData.mPCIDTEXT);
      x.http()
          .post(
              params,
              new CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                  InputStream sbs = new ByteArrayInputStream(result.getBytes());
                  String response = "";
                  try {
                    response = XMLParse.parseResponseCheck(sbs);
                    log("违例结束=" + response);
                  } catch (Exception e) {

                  }
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
                  log("违例结束   error" + ex.getMessage());
                }

                @Override
                public void onCancelled(CancelledException cex) {}

                @Override
                public void onFinished() {}
              });
    }
    if (handler != null) {
      handler.removeCallbacksAndMessages(null);
    }
    try {
      Process suProcess = Runtime.getRuntime().exec("su");
      DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
      os.writeBytes("adb shell" + "\n");
      os.flush();
      os.writeBytes("am force-stop " + paName + "\n");
      os.flush();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      log(e.getMessage());
    }
    if (processWatcher != null) {
      processWatcher.stop();
    }
    if (settingUtils != null) {
      settingUtils.reset();
    }
  }