Ejemplo n.º 1
0
 /**
  * 删除下载不完整的文件
  *
  * @param path
  */
 public static void deleteIntactFile(String path) {
   File file = new File(path);
   if (file.exists()) {
     file.delete();
     if (!file.exists()) {
       Logger.i(TAG, "下载不成功,已将文件删除--" + path);
     } else {
       Logger.e(TAG, "下载不成功,文件未成功删除--" + path);
     }
   }
 }
Ejemplo n.º 2
0
  private void getWifiList() {
    boolean isCanConnect = false;
    List<String> wifiSSIDList = new ArrayList<>();
    final List<ScanResult> scanResults = admin.getWifiList();
    if (newSacn != null) {
      newSacn.clear();
    } else {
      newSacn = new ArrayList<>();
    }
    for (ScanResult scanResult : scanResults) {
      if (WifiAdmin.isConnectCamera(getActivity(), scanResult.SSID, scanResult.BSSID)) {
        newSacn.add(scanResult);
        wifiSSIDList.add(scanResult.SSID.replace("\"", ""));
      }
    }

    wifiName =
        SpUtils.getInstance(mActivity)
            .getStringValue(com.leautolink.leautocamera.config.Constant.WIFI_SSID);
    String wifiPassword = "******";
    if (!TextUtils.isEmpty(wifiName)) {
      wifiPassword =
          SpUtils.getInstance(mActivity)
              .getStringValue(com.leautolink.leautocamera.config.Constant.WIFI_PWD);
    }

    Logger.d(
        TAG,
        "wifiName -->| "
            + wifiName
            + " wifipwd -->| "
            + wifiPassword
            + " isContains -->| "
            + wifiSSIDList.contains(wifiName));

    if (wifiSSIDList.contains(wifiName)) {
      isCanConnect = connectWifi(wifiName, wifiPassword);
      tempSSID = wifiName;
    } else if (newSacn.size() == 1) {
      inputWifiPassword(newSacn.get(0));
      return;
    }
    Logger.e(TAG, wifiName + " isCanConnect  -->| " + isCanConnect);
    if (!isCanConnect) {
      // TODO 显示wifi列表
      showWifiList(true);
    }
  }
Ejemplo n.º 3
0
  /**
   * base 的 get请求
   *
   * @param tag
   * @param url
   * @param headers
   * @param getCallBack
   */
  public static void get(
      Object tag, String url, Map<String, String> headers, final GetCallBack getCallBack) {
    Logger.i(TAG, "get url :" + url);
    setCancel(false);
    if (mClient != null) {
      Request.Builder requestBuilder = new Request.Builder();
      requestBuilder.tag(tag);
      requestBuilder.url(url);
      appendHeaders(requestBuilder, headers);
      Request request = requestBuilder.build();
      mCall = mClient.newCall(request);
      mCalls.add(mCall);
      mCall.enqueue(
          new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
              getCallBack.onFailure(call, e);
              Logger.e(TAG, "get onFailure:" + e.getMessage());
              EventBus.getDefault().post(new NetWorkBadEvent());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
              if (response.isSuccessful()) {
                getCallBack.onResponse(call, response);
              } else {
                getCallBack.onError(response.toString());
              }
            }
          });
    }
  }
Ejemplo n.º 4
0
  /** 发命令让记录仪切换为sta状态 */
  private void apStatrt() {
    final String password = "******";
    CameraMessage cameraMessage =
        new CameraMessage(
            1543,
            new CameraMessageCallback() {
              @Override
              public void onReceiveErrorMessage(
                  CameraMessage cameraMessage, JSONObject jsonObject) {}

              @Override
              public void onReceiveMessage(CameraMessage cameraMessage, JSONObject jsonObject) {
                //                wifiAp.startWifiAp(ssid, password);
                Constant.token = 0;
                RemoteCamHelper.getRemoteCam().closeChannel();
              }

              @Override
              public void onReceiveNotification(JSONObject jsonObject) {}
            });
    cameraMessage.put("type", "sta");
    cameraMessage.put("ssid", ssid);
    cameraMessage.put("password", password);
    cameraMessage.put("times", 30);
    remoteCamHelper.sendCommand(cameraMessage);
    Logger.e("Send 'sta' command to recorder!");
    //        CheckUDPService.chekUdpTimeOut();
  }
Ejemplo n.º 5
0
  /** 从记录仪上获取突发视频的数据 */
  private void getEventDataFromCamera() {
    Logger.i(TAG, "getEventDataFromCamera()");
    CameraMessage getLSMessage =
        new CameraMessage(
            CommandID.AMBA_LS_NEW,
            new CameraMessageCallback() {
              @Override
              public void onReceiveErrorMessage(
                  CameraMessage cameraMessage, JSONObject jsonObject) {
                Logger.e(TAG, "onReceiveErrorMessage" + jsonObject.toString());
              }

              @Override
              public void onReceiveMessage(CameraMessage cameraMessage, JSONObject jsonObject) {
                Logger.e(TAG, "onReceiveMessage:" + jsonObject.toString());
                //                mEventListingInfo = GsonUtils.fromJson(jsonObject.toString(),
                // ListingInfo.class);
                //                Logger.i(TAG, "EventListingInfo:" + mEventListingInfo.toString());
                // 只初始化Event页的数据
              }

              @Override
              public void onReceiveNotification(JSONObject jsonObject) {}
            });
    getLSMessage.put("type", "event");

    remoteCamHelper.sendCommand(getLSMessage);
  }
Ejemplo n.º 6
0
 private void phoneIsAp() {
   ssid = admin.getSSID();
   Logger.e("PHONE IS AP   " + ssid);
   if (admin.isConnectCamera(ssid, admin.getBSSID())
       || WifiApAdmin.isWifiApEnabled(
           (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE))) {
     //            Logger.e("开始切换");
     ////            switchAp();
     if (!isPhoneIsAp) {
       isPhoneIsAp = true;
       if (timer == null) {
         timer = new Timer();
         TimerTask task =
             new TimerTask() {
               @Override
               public void run() {
                 loadingLenght++;
                 if (loadingLenght < 100) {
                   updateLoading(loadingLenght);
                 } else {
                   if (timer != null) {
                     timer.cancel();
                     timer = null;
                   }
                 }
               }
             };
         timer.scheduleAtFixedRate(task, 0, 200);
       }
       apStatrt();
     }
   }
 }
Ejemplo n.º 7
0
 @Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   mActivity = activity;
   inflater = LayoutInflater.from(activity);
   Logger.i(TAG, "onAttach");
 }
Ejemplo n.º 8
0
  @Override
  public void onDestroy() {

    releaseResources();
    super.onDestroy();
    Logger.i(TAG, "onDestroy");
  }
Ejemplo n.º 9
0
  /**
   * 将Json转为Bean
   *
   * @param tag
   * @param url
   * @param headers
   * @param beanClass
   * @param getBeanCallBack
   * @param <T>
   */
  public static <T> void getBean(
      Object tag,
      String url,
      Map<String, String> headers,
      final Class<T> beanClass,
      final GetBeanCallBack<T> getBeanCallBack) {
    Logger.i(TAG, "getBean url:" + url);
    setCancel(false);
    if (mClient != null) {
      Request.Builder requestBuilder = new Request.Builder();
      requestBuilder.tag(tag);
      requestBuilder.url(url);
      appendHeaders(requestBuilder, headers);
      Request request = requestBuilder.build();
      mCall = mClient.newCall(request);
      mCalls.add(mCall);
      mCall.enqueue(
          new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
              Logger.e(TAG, "getBean onFailure" + e.getMessage());
              EventBus.getDefault().post(new NetWorkBadEvent());
              getBeanCallBack.onFailure(call, e);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
              if (response.isSuccessful()) {
                getBeanCallBack.onResponse(GsonUtils.fromJson(response.body().string(), beanClass));
              }
            }
          });
    }
  }
Ejemplo n.º 10
0
 @Override
 public void onError(int what, String extra) {
   Logger.e("CDEOnError. what: " + what + "extra: " + extra);
   if (201 == what) {
     if (LeautoCameraAppLication.isConnectCamera) {
       stopAndStartPlay();
     }
   }
 }
Ejemplo n.º 11
0
 /** 取消当前的Call */
 public static void cancelCurrentCall() {
   if (mCall != null && !mCall.isCanceled()) {
     mCall.cancel();
     if (mCall.isCanceled()) {
       setCancel(true);
       Logger.i(TAG, "cancelCurrentCall:" + isCancel);
       mCall = null;
     }
   }
 }
 private void initData() {
   if (mFileInfo != null) {
     if (!TextUtils.isEmpty(mFileInfo.getLocalFileUrl())) { // 本地
       Logger.i(TAG, mI + "---initData local url :" + mFileInfo.getLocalFileUrl());
       Glide.with(this)
           .load(mFileInfo.getLocalFileUrl())
           .placeholder(R.drawable.img_default)
           .into(mIvListThumb);
     } else {
       Logger.i(
           TAG,
           mI
               + "---initData httpThumbUrl :"
               + UrlUtils.getCameraHttpThumbUrl(mType, mFileInfo.getFileThumbname()));
       Glide.with(this)
           .load(UrlUtils.getCameraHttpThumbUrl(mType, mFileInfo.getFileThumbname()))
           .placeholder(R.drawable.img_default)
           .into(mIvListThumb);
     }
   }
 }
Ejemplo n.º 13
0
 /**
  * 初始化成功 startSession成功 , 获取sd卡的状态成功
  *
  * @param event
  */
 public void onEventMainThread(ConnectToCameraEvent event) {
   Logger.e("onEventMainThread isConnectCamera=" + event.isConnectCamera());
   if (event.isConnectCamera() && admin.isWifiEnabled()) {
     statrtPlay();
     connectSuccess();
     startReFreshAnimation();
     DeviceInfo.getInstance()
         .setContext(new WeakReference<Context>(CameraFragment.this.getActivity()));
     DeviceInfo.getInstance().getDeviceInfo();
     bt_take_photo.setEnabled(true);
     bt_go_photo.setEnabled(true);
     Logger.e("onEventMainThread FRAGMENTISHIDEN=" + FRAGMENTISHIDEN);
     autoDownLoadDataTask();
   } else {
     resumeConnectPage();
     if (mPlayer != null) {
       //                if (mPlayer.isPlaying()){
       mPlayer.stop();
       //                }
     }
   }
 }
Ejemplo n.º 14
0
  @UiThread
  void stopAndStartPlay() {
    Logger.e(TAG, "stopAndStartPlay");

    if (mPlayer != null) {
      mPlayer.stop();
      mPlayer.play(liveUrl);
    }

    //        mPlayer.play(mActivity, video_layout, liveUrl, LeHighPlayer.PLAY_TYPE_RTSP,
    // LeHighPlayer.ENCODE_TYPE_SOFT);
    //        mPlayer.play(mActivity, video_layout, liveUrl, MedIaPlayerManager.PLAY_TYPE_LIVE,
    // MedIaPlayerManager.ENCODE_TYPE_SOFT);

  }
Ejemplo n.º 15
0
 public void onEventBackgroundThread(EventOrPhotoRemovedNotificationEvent event) {
   Logger.e(TAG, "删除event 或者  photo了 param :" + event.getParam());
   Logger.e(TAG, "list :" + homePhotoInfos.toString());
   if (!TextUtils.isEmpty(event.getParam())) {
     String jsonStr = event.getParam().replace("[", "").replace("]", "");
     FileRemovedInfo removedInfo = GsonUtils.fromJson(jsonStr, FileRemovedInfo.class);
     String thumbName = removedInfo.getFilename();
     if (thumbName.endsWith("A.MP4")) {
       thumbName = thumbName.replace("A.MP4", "T.JPG");
     } else if (thumbName.endsWith("A.JPG")) {
       thumbName = thumbName.replace("A.JPG", "T.JPG");
     }
     if (homePhotoInfos != null && homePhotoInfos.size() > 0) {
       for (HomePhotoInfo info : homePhotoInfos) {
         if (info.getOrginalName().equals(thumbName)) {
           remoevdHomeInfos.add(info);
         }
       }
       Logger.e(TAG, "removedHomeInfos :" + remoevdHomeInfos.toString());
       homePhotoInfos.removeAll(remoevdHomeInfos);
       remoevdHomeInfos.clear();
     }
   }
 }
Ejemplo n.º 16
0
  /**
   * post请求
   *
   * @param tag
   * @param url
   * @param headers
   * @param params
   * @param postCallBack
   */
  public static void post(
      Object tag,
      String url,
      Map<String, String> headers,
      Map<String, String> params,
      final PostCallBack postCallBack) {
    Logger.i(TAG, "post url :" + url);
    setCancel(false);
    RequestBody requestBody = null;
    FormBody.Builder formBodyBuilder = new FormBody.Builder();
    if (params == null || params.size() == 0) {
      requestBody = formBodyBuilder.build();
    } else {
      for (Map.Entry<String, String> me : params.entrySet()) {
        formBodyBuilder.add(me.getKey(), me.getValue());
      }
      requestBody = formBodyBuilder.build();
    }
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.tag(tag);
    requestBuilder.url(url);
    appendHeaders(requestBuilder, headers);
    requestBuilder.post(requestBody);
    Request request = requestBuilder.build();
    mCall = mClient.newCall(request);
    mCalls.add(mCall);
    mCall.enqueue(
        new Callback() {
          @Override
          public void onFailure(Call call, IOException e) {
            Logger.e(TAG, "post onFailure :" + e.toString());
            postCallBack.onFailure(call, e);
            EventBus.getDefault().post(new NetWorkBadEvent());
          }

          @Override
          public void onResponse(Call call, Response response) throws IOException {
            if (response.isSuccessful()) {
              Logger.i(TAG, "post onResponse");
              postCallBack.onResponse(call, response);
            } else {
              Logger.i(TAG, "post onError: " + response.code());
              postCallBack.onError(response.code());
            }
          }
        });
  }
Ejemplo n.º 17
0
 /**
  * 取消相同的tag请求
  *
  * @param tag
  */
 public static void cancelSameTagCall(Object tag) {
   if (mClient != null) {
     Dispatcher dispatcher = mClient.dispatcher();
     for (Call call : dispatcher.queuedCalls()) {
       if (tag.equals(call.request().tag())) {
         call.cancel();
       }
     }
     for (Call call : dispatcher.runningCalls()) {
       if (tag.equals(call.request().tag())) {
         call.cancel();
       }
     }
     setCancel(true);
   } else {
     Logger.e(TAG, "cancelSameTagCall mClient 为 null");
   }
 }
Ejemplo n.º 18
0
 public void onEventMainThread(AddEventFileEvent event) {
   Logger.e("记录仪有新文件产生了");
   if (!TextUtils.isEmpty(event.getParam())) {
     String jsonStr = event.getParam().replace("[", "").replace("]", "");
     AddFileInfo addfileInfo = GsonUtils.fromJson(jsonStr, AddFileInfo.class);
     String thumbPhoto;
     HomePhotoInfo homePhotoInfo;
     if (addfileInfo.getFilename().contains("MP4")) {
       thumbPhoto = addfileInfo.getFilename().replace("A.MP4", "T.JPG");
       homePhotoInfo = new HomePhotoInfo(thumbPhoto, HomePhotoInfo.EVENT_PIC);
     } else {
       thumbPhoto = addfileInfo.getFilename().replace("A.JPG", "T.JPG");
       homePhotoInfo = new HomePhotoInfo(thumbPhoto, HomePhotoInfo.NORMAL_PIC);
     }
     homePhotoInfos.add(0, homePhotoInfo);
     showPhoto();
   }
 }
Ejemplo n.º 19
0
  @Override
  public void onPause() {
    super.onPause();
    Logger.e(TAG, "onPause");
    Log.e(TAG, " <==============    onPause");

    FRAGMENTISHIDEN = true;
    hideReFreshAnimation();

    cameraStatus = "";
    initRecordedIcon();
    //        mPlayer.suspend();
    /* if (this.mPlayController != null) {
        //Modify by donghongwei 20160405 for LECAMERA-402 begin
        this.mPlayController.stopPlayback();
        //Modify by donghongwei 20160405 for LECAMERA-402 begin
    }*/
    DeviceDiscovery.getInstance().stopDiscovery();
  }
Ejemplo n.º 20
0
  public void onEventMainThread(NotificationEvent event) {

    if (event.getType() == NotificationEvent.IDLE) {
      mPlayer.stop();
      /*  if (this.mPlayController != null) {
          this.mPlayController.stopPlayback();
      }*/
      cameraStatus = "idle";
      initRecordedIcon();
    } else {
      if (event.getType() == NotificationEvent.VF || event.getType() == NotificationEvent.RECORD) {
        if (!mPlayer.isPlaying()) {
          mPlayer.play(liveUrl);
        }
        if (event.getType() == NotificationEvent.VF) {
          cameraStatus = "vf";
        }
        if (event.getType() == NotificationEvent.RECORD) {
          cameraStatus = "record";
        }
        initRecordedIcon();
      }
    }

    if (event.getType() == NotificationEvent.SD_INSERTED) {
      getPhotoDataFromCamera();
    }
    if (event.getType() == NotificationEvent.GET_FILE_FAIL) {
      Logger.e("失败!!!!!!!!!!!!!!!!!!!!!!!!!!!");
      hideLoading();
      showToastSafe(getResources().getString(R.string.download_to_phone_error));
      if (runnable != null) {
        handler_.removeCallbacks(runnable);
      }
    }
    if (event.getType() == NotificationEvent.GET_FILE_COMPLETE) {
      hideLoading();
      showToastSafe(getResources().getString(R.string.take_photo_and_download));
      if (runnable != null) {
        handler_.removeCallbacks(runnable);
      }
    }
  }
Ejemplo n.º 21
0
  /**
   * 文件上传
   *
   * @param tag
   * @param url
   * @param filePath
   * @param headers
   * @param params
   * @param uploadFileCallBack
   */
  public static void uploadFile(
      Object tag,
      String url,
      String filePath,
      Map<String, String> headers,
      Map<String, String> params,
      final UploadFileCallBack uploadFileCallBack) {
    Logger.i(TAG, "uploadFile url :" + url);
    setCancel(false);
    File file = new File(filePath);
    MultipartBody.Builder multipartBuilder =
        new MultipartBody.Builder().setType(MultipartBody.FORM);
    addParams(multipartBuilder, params);
    addFiles(multipartBuilder, new Pair<String, File>("file", file));
    progerssRequestBody = new ProgressRequestBody(multipartBuilder.build(), uploadFileCallBack);
    Request.Builder builder = new Request.Builder();
    appendHeaders(builder, headers);
    Request request = builder.tag(tag).url(url).post(progerssRequestBody).build();

    mCall = mClient.newCall(request);
    mCalls.add(mCall);
    mCall.enqueue(
        new Callback() {
          @Override
          public void onFailure(Call call, IOException e) {
            Logger.e(TAG, "uploadFile onFailure :" + e.toString());
            uploadFileCallBack.onFailure(call, e);
            EventBus.getDefault().post(new NetWorkBadEvent());
          }

          @Override
          public void onResponse(Call call, Response response) throws IOException {
            if (response.isSuccessful()) {
              Logger.i(TAG, "uploadFile onResponse");
              uploadFileCallBack.onResponse(call, response);
            } else {
              Logger.i(TAG, "uploadFile onError: " + response.code());
              uploadFileCallBack.onError(response.code());
            }
          }
        });
  }
Ejemplo n.º 22
0
  /** 从记录仪上获取手动记录的数据 */
  private void getPhotoDataFromCamera() {
    Logger.i(TAG, "getPhotoDataFromCamera()");
    CameraMessage getLSMessage =
        new CameraMessage(
            CommandID.AMBA_LS_NEW,
            new CameraMessageCallback() {
              @Override
              public void onReceiveErrorMessage(
                  CameraMessage cameraMessage, JSONObject jsonObject) {
                Logger.e(TAG, "onReceiveErrorMessage" + jsonObject.toString());
              }

              @Override
              public void onReceiveMessage(CameraMessage cameraMessage, JSONObject jsonObject) {
                Logger.e(TAG, "onReceiveMessage:" + jsonObject.toString());
                mPhotoListingInfo = GsonUtils.fromJson(jsonObject.toString(), ListingInfo.class);
                // shimeng add for protect null point,20160416,begin
                if (null != mPhotoListingInfo) {
                  List<ListingInfo.FileInfo> fileInfos = mPhotoListingInfo.getListing();
                  int count = Math.min(3, fileInfos.size());
                  homePhotoInfos.clear();
                  for (int i = fileInfos.size(); i > fileInfos.size() - 3 && i > 0; i--) {
                    String thumbName = fileInfos.get(i - 1).getFilename().replace("A", "T");
                    HomePhotoInfo homePI = new HomePhotoInfo(thumbName, HomePhotoInfo.NORMAL_PIC);
                    homePhotoInfos.add(homePI);
                  }
                  showPhoto();
                  Logger.i(TAG, "PhotoListingInfo:" + mPhotoListingInfo.toString());
                }
                // shimeng add for protect null point,20160416,end
              }

              @Override
              public void onReceiveNotification(JSONObject jsonObject) {}
            });
    getLSMessage.put("type", "photo");

    RemoteCamHelper.getRemoteCam().sendCommand(getLSMessage);
  }
Ejemplo n.º 23
0
  /**
   * post提交Json
   *
   * @param tag
   * @param url
   * @param headers
   * @param json
   * @param postCallBack
   */
  public static void postJson(
      Object tag,
      String url,
      Map<String, String> headers,
      String json,
      final PostCallBack postCallBack) {
    Logger.i(TAG, "postJson url :" + url);
    setCancel(false);
    RequestBody postBody =
        RequestBody.create(MediaType.parse("application/json;charset=utf-8"), json);
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.tag(tag);
    requestBuilder.url(url);
    appendHeaders(requestBuilder, headers);
    requestBuilder.post(postBody);
    Request request = requestBuilder.build();
    mCall = mClient.newCall(request);
    mCalls.add(mCall);
    mCall.enqueue(
        new Callback() {
          @Override
          public void onFailure(Call call, IOException e) {
            Logger.e(TAG, "postJson onFailure :" + e.toString());
            postCallBack.onFailure(call, e);
            EventBus.getDefault().post(new NetWorkBadEvent());
          }

          @Override
          public void onResponse(Call call, Response response) throws IOException {
            if (response.isSuccessful()) {
              Logger.i(TAG, "postJson onResponse");
              postCallBack.onResponse(call, response);
            } else {
              Logger.i(TAG, "postJson onError: " + response.code());
              postCallBack.onError(response.code());
            }
          }
        });
  }
Ejemplo n.º 24
0
  public void onEventMainThread(UDPTimeOutEvent event) {
    Logger.e(
        "CameraFragment UDPTimeOutEvent CheckUDPServiceIsOk="
            + LeautoCameraAppLication.CheckUDPServiceIsOk);
    isPhoneIsAp = false;
    FRAGMENTISHIDEN = false;

    SpUtils.getInstance(mActivity.getApplicationContext())
        .getStringValue(com.leautolink.leautocamera.config.Constant.WIFI_SSID);

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                admin.forget(ssid);
              }
            })
        .start();

    if (LeautoCameraAppLication.CheckUDPServiceIsOk) {
      //            mActivity.stopService(new Intent(mActivity, CheckUDPService.class));
    }
  }
Ejemplo n.º 25
0
 @Override
 public void onResume() {
   super.onResume();
   showPhoto();
   if (LeautoCameraAppLication.isConnectCamera) {
     startReFreshAnimation();
     DeviceDiscovery.getInstance().startDiscovery();
     if (mPlayer != null) {
       mPlayer.start();
       if (TextUtils.isEmpty(cameraStatus)) {
         getCameraStatus();
       } else {
         initRecordedIcon();
       }
     }
   } else {
     mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
     if (mPlayer != null) {
       mPlayer.stop();
     }
   }
   Logger.e("onResume  ------------->");
 }
Ejemplo n.º 26
0
 public void onEventMainThread(AutoConnectToCameraEvent event) {
   Logger.e("onEventMainThread isConnectCamera=" + event.isConnectCamera());
   if (event.isConnectCamera() == 0) {
     //            admin.closeWifi();
   }
 }
Ejemplo n.º 27
0
 @Override
 public void onResume() {
   super.onResume();
   Logger.e(TAG, "onResume");
   StatisticsUtil.getInstance().recordActivityStart(this.getClass().getSimpleName());
 }
Ejemplo n.º 28
0
 @Override
 public void setUserVisibleHint(boolean isVisibleToUser) {
   super.setUserVisibleHint(isVisibleToUser);
   Logger.i(TAG, "setUserVisibleHint");
   onUserVisibleHint(isVisibleToUser);
 }
Ejemplo n.º 29
0
 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   Logger.i(TAG, "onActivityCreated");
 }
Ejemplo n.º 30
0
  /**
   * 下载
   *
   * @param tag
   * @param url
   * @param targetPath
   * @param fileName
   * @param avaiable
   * @param downLoadCallBack
   */
  public static void downLoad(
      Object tag,
      final String url,
      final String targetPath,
      final String fileName,
      final long avaiable,
      final DownLoadCallBack downLoadCallBack) {
    Logger.i(TAG, "downLoad url:" + url);
    setCancel(false);
    if (TextUtils.isEmpty(url)) throw new NullPointerException("url can't be null");
    if (TextUtils.isEmpty(targetPath)) throw new NullPointerException("targetPath can't be null");
    if (mClient != null) {
      Logger.i(TAG, "-----");
      final Request request = new Request.Builder().tag(tag).url(url).build();
      mCall = mClient.newCall(request);
      mCalls.add(mCall);
      Logger.i(TAG, "-----url=" + url + ",targetPath=" + targetPath + ",fileName=" + fileName);
      mCall.enqueue(
          new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
              Logger.e(TAG, "downLoad onFailure:" + e.getMessage());
              downLoadCallBack.onFailure(call, e);
              EventBus.getDefault().post(new NetWorkBadEvent());
            }

            @Override
            public void onResponse(Call call, Response response) {
              Logger.i(TAG, "-----response.isSuccessful()=" + response.isSuccessful());
              if (response.isSuccessful()) {
                File targetFile = new File(targetPath);
                if (!targetFile.exists()) {
                  targetFile.mkdirs();
                }
                Logger.i(TAG, "-----targetFile=" + targetFile);
                long total = response.body().contentLength();
                int current = 0;
                BufferedInputStream bis = null;
                BufferedOutputStream bos = null;
                // 判断内存卡剩余内存的大小
                if (avaiable > total) {
                  try {
                    Logger.i(TAG, "downLoad onStart total:" + total);
                    downLoadCallBack.onStart(total);

                    InputStream is = response.body().byteStream();
                    bis = new BufferedInputStream(is);
                    FileOutputStream fos =
                        new FileOutputStream(targetFile.getAbsolutePath() + "/" + fileName);
                    Logger.i(TAG, "文件存储:" + targetFile.getAbsolutePath() + "/" + fileName);
                    bos = new BufferedOutputStream(fos);
                    byte[] buffer = new byte[1024];
                    int len = 0;
                    while (!isCancel && ((len = bis.read(buffer)) != -1)) {
                      current += len;
                      Logger.i(TAG, "downLoad onLoading current:" + current);
                      bos.write(buffer, 0, len);
                      downLoadCallBack.onLoading(current, total);
                    }
                    if (current < total) {
                      Logger.i(TAG, "downLoad onCancel");
                      downLoadCallBack.onCancel();
                    }
                  } catch (IOException e) {
                    Logger.e(TAG, "读写流出错:" + e.getMessage());
                    downLoadCallBack.onError(e);
                  } finally {
                    try {
                      if (bos != null) {
                        bos.close();
                        bos = null;
                      }
                    } catch (IOException e) {
                      e.printStackTrace();
                      downLoadCallBack.onError(e);
                    }
                    try {
                      if (bis != null) {
                        bis.close();
                        bis = null;
                      }
                    } catch (IOException e) {
                      e.printStackTrace();
                      downLoadCallBack.onError(e);
                    }
                    if (current == total) {
                      Logger.i(TAG, "downLoad onSucceed" + "文件保存在" + targetPath + "/" + fileName);
                      downLoadCallBack.onSucceed();
                    }
                  }
                } else {
                  Logger.i(TAG, "downLoad onSdCardLackMemory");
                  downLoadCallBack.onSdCardLackMemory(total, avaiable);
                }
              }
            }
          });
    }
  }