public static void ObtenerDispositivo(
      Context context, String mac, final ServiceCallBack<Devices> callback) {

    HttpAsyncTask task =
        new HttpAsyncTask(
            context,
            new CallBack() {

              @Override
              public void onPostExecute(String json) {
                try {
                  JSONObject root = new JSONObject(json);
                  JSONObject comercioJson = root.getJSONObject("dispositivo");
                  JSONObject empresaJson = root.getJSONObject("empresa");
                  JSONArray opcionesListJson = root.getJSONArray("opciones");

                  Type typeDevice = new TypeToken<Devices>() {}.getType();
                  Type typeEmpresa = new TypeToken<Empresa>() {}.getType();
                  Type typeOpcion = new TypeToken<Opciones>() {}.getType();

                  Devices deviceEntity = new Gson().fromJson(comercioJson.toString(), typeDevice);

                  Empresa empresaEntity = new Gson().fromJson(empresaJson.toString(), typeEmpresa);
                  deviceEntity.empresaObject = empresaEntity;

                  for (int i = 0; i < opcionesListJson.length(); i++) {
                    JSONObject item = opcionesListJson.getJSONObject(i);
                    Opciones opcion = new Gson().fromJson(item.toString(), typeOpcion);
                    deviceEntity.opcionesList.add(opcion);
                  }

                  callback.onPostExecute(deviceEntity);
                } catch (Exception ex) {
                  callback.onException(ex);
                }
              }

              @Override
              public void onException(Exception ex) {
                callback.onException(ex);
              }
            });

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("mac", mac);
    String url = Common.RootServiceUrl + "/api/Dispositivos/ObtenerDispositivo";
    task.execute(new HttpAsyncTaskParameters(url, "GET", parameters));
  }
  /**
   * * 获取更新信息
   *
   * @param context 上下文
   * @param pOnResponseListener 响应监听
   * @return 是否有更新版本
   */
  public void checkUpdate(final Context context, final OnResponseListener pOnResponseListener) {

    // 先检查是否缓存过更新信息
    VersionInfo vi = new VersionInfo();
    StringBuffer savePath = new StringBuffer();
    if (checkCache(context, vi, savePath)) {
      pOnResponseListener.onCache(vi, savePath.toString());
      return;
    }

    if (task == null)
      task =
          new HttpAsyncTask() {
            @Override
            protected void onPostExecute(Boolean result) {
              super.onPostExecute(result);
              task = null;
            }
          };
    else {
      Log.d(tag, "正在进行更新检查");
      return;
    }
    task.execute(
        new IAsyncCallBack() {

          VersionInfo vi;
          VersionInfo newVi;

          @Override
          public boolean workToDo() {
            vi = getCurrentVersionInfo(context);
            newVi = getNewestVersionInfo();

            if (vi == null || newVi == null) return false;
            return true;
          }

          @Override
          public void onComplete() {
            if (newVi.getVersionCode() <= vi.getVersionCode()) {
              updateCache(context, vi);
              if (pOnResponseListener != null) pOnResponseListener.onResponse(true, vi);
            } else {
              updateCache(context, newVi);
              if (pOnResponseListener != null) pOnResponseListener.onResponse(false, newVi);
            }
          }

          @Override
          public void onError() {
            if (pOnResponseListener != null) pOnResponseListener.onError();
          }
        });
  }
 @SuppressLint({"NewApi"})
 protected Map sendAnalyticsRequest(Event event, String str, Map map) {
   Map hashMap = new HashMap();
   hashMap.putAll(this.baseParams);
   if (map != null) {
     hashMap.putAll(map);
   }
   if (!hashMap.containsKey("account")) {
     return null;
   }
   Video video = (Video) event.properties.get(Event.VIDEO);
   if (video != null) {
     int duration = video.getDuration();
     String stringProperty =
         video.getStringProperty(com.brightcove.player.model.Video.Fields.NAME);
     if (duration > 0) {
       hashMap.put("video_duration", AdTrackerConstants.BLANK + (duration / 1000));
     }
     if (!(stringProperty == null || stringProperty == AdTrackerConstants.BLANK)) {
       hashMap.put("video_name", stringProperty);
     }
   }
   hashMap.put(DataLayer.EVENT_KEY, str);
   hashMap.put("domain", domain);
   hashMap.put("device_os", deviceOS);
   hashMap.put("device_type", this.deviceType);
   hashMap.put("device_os_version", VERSION.RELEASE);
   hashMap.put(CuePointFields.TIME, AdTrackerConstants.BLANK + new Date().getTime());
   hashMap.put("embed", this.playerName);
   hashMap.put("player_name", this.playerName);
   hashMap.put("destination", this.destination);
   HttpAsyncTask httpAsyncTask = new HttpAsyncTask();
   HashMap[] hashMapArr = new HashMap[] {hashMap};
   if (VERSION.SDK_INT >= 14) {
     httpAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, hashMapArr);
   } else {
     httpAsyncTask.execute(hashMapArr);
   }
   return hashMap;
 }
Beispiel #4
0
 public void refresh() {
   rawStringFromURL = "";
   HttpAsyncTask httpAsyncTask = new HttpAsyncTask();
   httpAsyncTask.execute(url);
 }
Beispiel #5
0
 /**
  * 发送网络请求
  *
  * @param datas 请求参数集合
  * @param context 上下文
  * @param dialogStr 进度文字
  * @param callback 回调
  * @return
  */
 public static HttpAsyncTask sendRequest(
     HttpDatas datas, Context context, String dialogStr, TaskCallBack callback) {
   HttpAsyncTask task = new HttpAsyncTask(callback, context, dialogStr);
   task.execute(datas);
   return task;
 }