コード例 #1
0
 public void downloadApkFile(
     String url,
     String fileName,
     String pkg,
     int versionCode,
     String savePath,
     boolean autoResume,
     final RequestCallBack<File> callback)
     throws DbException {
   if (checkDownloaded(pkg, versionCode, savePath)) {
     PackageUtils.installApp(mContext, savePath);
     return;
   }
   String tmpApkPath = savePath + getMD5ApkTmpName(pkg, versionCode);
   String apkPath = savePath + getMD5ApkName(pkg, versionCode);
   final DownloadInfo downloadInfo = new DownloadInfo();
   downloadInfo.setDownloadUrl(url);
   downloadInfo.setAutoResume(autoResume);
   downloadInfo.setFileName(fileName);
   downloadInfo.setFileTmpPath(tmpApkPath);
   downloadInfo.setFileSavePath(apkPath);
   downloadInfo.setPkg(pkg);
   downloadInfo.setVersionCode(versionCode);
   downloadInfo.setAutoRenameTmp(true);
   HttpUtils http = new HttpUtils();
   http.configRequestThreadPoolSize(maxDownloadThread);
   HttpHandler<File> handler =
       http.download(url, tmpApkPath, autoResume, new ManagerCallBack(downloadInfo, callback));
   downloadInfo.setHandler(handler);
   downloadInfo.setState(handler.getState());
   downloadInfoList.add(downloadInfo);
   db.saveBindingId(downloadInfo);
 }
コード例 #2
0
 @Override
 public void onSuccess(ResponseInfo<File> responseInfo) {
   if (downloadInfo.getFileLength() != downloadInfo.getProgress()) { // 不一致 返回
     return;
   }
   if (downloadInfo.getAutoRenameTmp()) { // 成功后改名
     File tarFile = new File(downloadInfo.getFileTmpPath());
     if (tarFile.exists()) {
       File newFile = new File(downloadInfo.getFileSavePath());
       tarFile.renameTo(newFile);
     }
   }
   LogUtils.d(downloadInfo.getPkg() + " onSuccess");
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onSuccess(responseInfo);
   }
 }
コード例 #3
0
 public void removeDownload(DownloadInfo downloadInfo) throws DbException {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null && !handler.isCancelled()) {
     handler.cancel();
   }
   downloadInfoList.remove(downloadInfo);
   db.delete(downloadInfo);
 }
コード例 #4
0
 public void backupDownloadInfoList() throws DbException {
   for (DownloadInfo downloadInfo : downloadInfoList) {
     HttpHandler<File> handler = downloadInfo.getHandler();
     if (handler != null) {
       downloadInfo.setState(handler.getState());
     }
   }
   db.saveOrUpdateAll(downloadInfoList);
 }
コード例 #5
0
 public void stopDownload(DownloadInfo downloadInfo) throws DbException {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null && !handler.isCancelled()) {
     handler.cancel();
   } else {
     downloadInfo.setState(HttpHandler.State.CANCELLED);
   }
   db.saveOrUpdate(downloadInfo);
 }
コード例 #6
0
 public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack<File> callback)
     throws DbException {
   HttpUtils http = new HttpUtils();
   http.configRequestThreadPoolSize(maxDownloadThread);
   HttpHandler<File> handler =
       http.download(
           downloadInfo.getDownloadUrl(),
           downloadInfo.getFileSavePath(),
           downloadInfo.isAutoResume(),
           new ManagerCallBack(downloadInfo, callback));
   downloadInfo.setHandler(handler);
   downloadInfo.setState(handler.getState());
   db.saveOrUpdate(downloadInfo);
 }
コード例 #7
0
 @Override
 public void onCancelled() {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onCancelled();
   }
 }
コード例 #8
0
 @Override
 public void onFailure(HttpException error, String msg) {
   LogUtils.d(downloadInfo.getPkg() + " onFailure");
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onFailure(error, msg);
   }
 }
コード例 #9
0
 @Override
 public void onLoading(long total, long current, boolean isUploading) {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   downloadInfo.setFileLength(total);
   downloadInfo.setProgress(current);
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onLoading(total, current, isUploading);
   }
 }
コード例 #10
0
 public void addNewDownload(
     String url,
     String fileName,
     String target,
     boolean autoResume,
     boolean autoRename,
     final RequestCallBack<File> callback)
     throws DbException {
   final DownloadInfo downloadInfo = new DownloadInfo();
   downloadInfo.setDownloadUrl(url);
   downloadInfo.setAutoResume(autoResume);
   downloadInfo.setFileName(fileName);
   downloadInfo.setFileSavePath(target);
   downloadInfo.setAutoRenameTmp(autoRename);
   HttpUtils http = new HttpUtils();
   http.configRequestThreadPoolSize(maxDownloadThread);
   HttpHandler<File> handler =
       http.download(
           url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
   downloadInfo.setHandler(handler);
   downloadInfo.setState(handler.getState());
   downloadInfoList.add(downloadInfo);
   db.saveBindingId(downloadInfo);
 }