|
@@ -407,22 +407,26 @@ public class ActDownloadMgr extends BaseCompatActivity {
|
|
|
}
|
|
}
|
|
|
//在这里处理任务执行中的状态,如进度进度条的刷新
|
|
//在这里处理任务执行中的状态,如进度进度条的刷新
|
|
|
@Download.onTaskRunning protected void running(DownloadTask task) {
|
|
@Download.onTaskRunning protected void running(DownloadTask task) {
|
|
|
- int p = task.getPercent(); //任务进度百分比
|
|
|
|
|
// downloadTaskService.setDownloadTaskPercent(p, task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d,0,task.getKey());
|
|
// downloadTaskService.setDownloadTaskPercent(p, task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d,0,task.getKey());
|
|
|
- String speed = task.getConvertSpeed(); //转换单位后的下载速度,单位转换需要在配置文件中打开
|
|
|
|
|
- System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
|
|
|
|
|
- String url = task.getKey();
|
|
|
|
|
- KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
|
|
|
|
|
- ProgressBar pbProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_PROGRESS + url);
|
|
|
|
|
- TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + url);
|
|
|
|
|
- if (tvProgress == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- tvProgress.setText(strFormat(this,task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d));
|
|
|
|
|
- pbProgress.setProgress(task.getPercent());
|
|
|
|
|
- targetBtn.setText(R.string.downloading);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ int p = task.getPercent(); //任务进度百分比
|
|
|
|
|
+ String speed = task.getConvertSpeed(); //转换单位后的下载速度,单位转换需要在配置文件中打开
|
|
|
|
|
+ System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
|
|
|
|
|
+ String url = task.getKey();
|
|
|
|
|
+ KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
|
|
|
|
|
+ ProgressBar pbProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_PROGRESS + url);
|
|
|
|
|
+ TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + url);
|
|
|
|
|
+ if (tvProgress == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ tvProgress.setText(strFormat(this,task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d));
|
|
|
|
|
+ pbProgress.setProgress(task.getPercent());
|
|
|
|
|
+ targetBtn.setText(R.string.downloading);
|
|
|
|
|
|
|
|
- setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_ING, task.getDownloadPath());
|
|
|
|
|
|
|
+ setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_ING, task.getDownloadPath());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Download.onTaskStop void taskStop(DownloadTask task) {
|
|
@Download.onTaskStop void taskStop(DownloadTask task) {
|
|
@@ -435,35 +439,47 @@ public class ActDownloadMgr extends BaseCompatActivity {
|
|
|
|
|
|
|
|
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
|
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
|
|
// downloadTaskService.deleteDownloadTaskByDownloadUrl(task.getKey());
|
|
// downloadTaskService.deleteDownloadTaskByDownloadUrl(task.getKey());
|
|
|
- String url = task.getKey();
|
|
|
|
|
- int iTempPosition = -1;
|
|
|
|
|
- for (int position = 0; position < downloadTasks.size(); position++) {
|
|
|
|
|
- DownLoadInfo downLoadInfo = downloadTasks.get(position);
|
|
|
|
|
- if (url.equals(downLoadInfo.getMDownloadUrl())) {
|
|
|
|
|
- iTempPosition = position;
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ String url = task.getKey();
|
|
|
|
|
+ int iTempPosition = -1;
|
|
|
|
|
+ for (int position = 0; position < downloadTasks.size(); position++) {
|
|
|
|
|
+ DownLoadInfo downLoadInfo = downloadTasks.get(position);
|
|
|
|
|
+ if (url.equals(downLoadInfo.getMDownloadUrl())) {
|
|
|
|
|
+ iTempPosition = position;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ if (iTempPosition < 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ removeTask(iTempPosition);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- if (iTempPosition < 0) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- removeTask(iTempPosition);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Download.onTaskFail void taskFail(DownloadTask task) {
|
|
@Download.onTaskFail void taskFail(DownloadTask task) {
|
|
|
// downloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadTaskService.STATUS_FAIL);
|
|
// downloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadTaskService.STATUS_FAIL);
|
|
|
- String url = task.getKey();
|
|
|
|
|
- KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
|
|
|
|
|
- targetBtn.setText(R.string.download_fail);
|
|
|
|
|
- setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_FAIL, task.getDownloadPath());
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ String url = task.getKey();
|
|
|
|
|
+ KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
|
|
|
|
|
+ targetBtn.setText(R.string.download_fail);
|
|
|
|
|
+ setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_FAIL, task.getDownloadPath());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
|
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
|
|
// downloadTaskService.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
|
|
// downloadTaskService.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
|
|
|
- TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + task.getKey());
|
|
|
|
|
- tvProgress.setText(R.string.download_completed);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + task.getKey());
|
|
|
|
|
+ tvProgress.setText(R.string.download_completed);
|
|
|
|
|
|
|
|
- setTaskStatusByDownloadUrl(task.getKey(), DownloadTaskService.STATUS_FINISH, task.getDownloadPath());
|
|
|
|
|
|
|
+ setTaskStatusByDownloadUrl(task.getKey(), DownloadTaskService.STATUS_FINISH, task.getDownloadPath());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
ApkUtils.installApk(ActDownloadMgr.this, task.getDownloadPath());
|
|
ApkUtils.installApk(ActDownloadMgr.this, task.getDownloadPath());
|
|
|
}
|
|
}
|
|
|
|
|
|