Exemplo n.º 1
0
 @Override
 public synchronized void onStop(DLThreadInfo threadInfo) {
   // DLDBManager.getInstance(context).updateThreadInfo(threadInfo);
   try {
     mDLThreadInfoDao.update(threadInfo);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   count++;
   if (count >= info.threads.size()) {
     LogUtils.e("All the threads was stopped.");
     info.currentBytes = totalProgress;
     info.state = DLState.PAUSE;
     DLManager.getInstance(context).addStopTask(info).removeDLTask(info.baseUrl);
     // DLDBManager.getInstance(context).updateTaskInfo(info);
     try {
       mDLInfoDao.update(info);
     } catch (SQLException e) {
       e.printStackTrace();
     }
     count = 0;
     if (info.hasListener) info.listener.onStop(info);
     EventBus.getDefault().post(info, "onStop");
   }
 }
Exemplo n.º 2
0
  @Override
  public synchronized void onProgress(int progress) {
    // 已下载大小
    totalProgress += progress;
    info.progress = totalProgress;
    info.currentBytes = totalProgress;

    // 计算下载速度
    long totalTime = (System.currentTimeMillis() - mPreviousTime) / 1000;
    if (totalTime == 0) {
      totalTime += 1;
    }
    long networkSpeed = totalProgress / totalTime;
    info.networkSpeed = networkSpeed;

    long currentTime = System.currentTimeMillis();
    if (currentTime - lastTime > 1000 || totalProgress == info.totalBytes) {
      // LogUtils.e(info.appName + "  下载进度:" + totalProgress);
      try {
        mDLInfoDao.update(info);
      } catch (SQLException e) {
        e.printStackTrace();
      }
      if (info.hasListener) info.listener.onProgress(info);
      EventBus.getDefault().post(info, "onProgress");
      lastTime = currentTime;
    }
  }