|
|
|
@ -133,15 +133,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
@Download.onPre void onPre(DownloadTask task) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Download.onTaskStart |
|
|
|
|
void onStart(DownloadTask task){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置start 和 stop 按钮状态 |
|
|
|
|
*/ |
|
|
|
@ -152,7 +143,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> { |
|
|
|
|
|
|
|
|
|
@Override protected void onResume() { |
|
|
|
|
super.onResume(); |
|
|
|
|
Aria.download(this).addSchedulerListener(new MySchedulerListener()); |
|
|
|
|
Aria.download(this).register(); |
|
|
|
|
//Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
|
|
|
|
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -172,63 +164,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override protected int setLayoutId() { |
|
|
|
|
return R.layout.activity_single; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override protected void init(Bundle savedInstanceState) { |
|
|
|
|
super.init(savedInstanceState); |
|
|
|
|
setTitle("单任务下载"); |
|
|
|
|
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); |
|
|
|
|
mPb.setProgress(target.getPercent()); |
|
|
|
|
if (target.getTaskState() == IEntity.STATE_STOP) { |
|
|
|
|
mStart.setText("恢复"); |
|
|
|
|
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); |
|
|
|
|
setBtState(true); |
|
|
|
|
} else if (target.isDownloading()) { |
|
|
|
|
setBtState(false); |
|
|
|
|
} |
|
|
|
|
mSize.setText(target.getConvertFileSize()); |
|
|
|
|
Aria.get(this).getDownloadConfig().setOpenBreadCast(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void onClick(View view) { |
|
|
|
|
switch (view.getId()) { |
|
|
|
|
case R.id.start: |
|
|
|
|
String text = ((TextView) view).getText().toString(); |
|
|
|
|
if (text.equals("重新开始?") || text.equals("开始")) { |
|
|
|
|
Aria.download(this) |
|
|
|
|
.load(DOWNLOAD_URL) |
|
|
|
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") |
|
|
|
|
.start(); |
|
|
|
|
} else if (text.equals("恢复")) { |
|
|
|
|
Aria.download(this).load(DOWNLOAD_URL).resume(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case R.id.stop: |
|
|
|
|
Aria.download(this).load(DOWNLOAD_URL).pause(); |
|
|
|
|
break; |
|
|
|
|
case R.id.cancel: |
|
|
|
|
Aria.download(this).load(DOWNLOAD_URL).cancel(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class MySchedulerListener extends Aria.DownloadSchedulerListener { |
|
|
|
|
|
|
|
|
|
@Override public void onPre(DownloadTask task) { |
|
|
|
|
@Download.onPre protected void onPre(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()) |
|
|
|
|
.sendToTarget(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onNoSupportBreakPoint(DownloadTask task) { |
|
|
|
|
super.onNoSupportBreakPoint(task); |
|
|
|
|
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskStart(DownloadTask task) { |
|
|
|
|
@Download.onTaskStart void taskStart(DownloadTask task) { |
|
|
|
|
//通过下载地址可以判断任务是否是你指定的任务
|
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getDownloadEntity().getFileSize()) |
|
|
|
@ -236,40 +179,87 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskResume(DownloadTask task) { |
|
|
|
|
@Download.onTaskRunning protected void running(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Download.onTaskResume void taskResume(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getFileSize()).sendToTarget(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskStop(DownloadTask task) { |
|
|
|
|
@Download.onTaskStop void taskStop(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskCancel(DownloadTask task) { |
|
|
|
|
@Download.onTaskCancel void taskCancel(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskFail(DownloadTask task) { |
|
|
|
|
@Download.onTaskFail void taskFail(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskComplete(DownloadTask task) { |
|
|
|
|
@Download.onTaskComplete void taskComplete(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override public void onTaskRunning(DownloadTask task) { |
|
|
|
|
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { |
|
|
|
|
if (task.getKey().equals(DOWNLOAD_URL)) { |
|
|
|
|
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget(); |
|
|
|
|
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override protected int setLayoutId() { |
|
|
|
|
return R.layout.activity_single; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override protected void init(Bundle savedInstanceState) { |
|
|
|
|
super.init(savedInstanceState); |
|
|
|
|
setTitle("单任务下载"); |
|
|
|
|
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); |
|
|
|
|
mPb.setProgress(target.getPercent()); |
|
|
|
|
if (target.getTaskState() == IEntity.STATE_STOP) { |
|
|
|
|
mStart.setText("恢复"); |
|
|
|
|
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); |
|
|
|
|
setBtState(true); |
|
|
|
|
} else if (target.isDownloading()) { |
|
|
|
|
setBtState(false); |
|
|
|
|
} |
|
|
|
|
mSize.setText(target.getConvertFileSize()); |
|
|
|
|
Aria.get(this).getDownloadConfig().setOpenBreadCast(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void onClick(View view) { |
|
|
|
|
switch (view.getId()) { |
|
|
|
|
case R.id.start: |
|
|
|
|
String text = ((TextView) view).getText().toString(); |
|
|
|
|
if (text.equals("重新开始?") || text.equals("开始")) { |
|
|
|
|
Aria.download(this) |
|
|
|
|
.load(DOWNLOAD_URL) |
|
|
|
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") |
|
|
|
|
.start(); |
|
|
|
|
} else if (text.equals("恢复")) { |
|
|
|
|
Aria.download(this).load(DOWNLOAD_URL).resume(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case R.id.stop: |
|
|
|
|
Aria.download(this).load(DOWNLOAD_URL).pause(); |
|
|
|
|
break; |
|
|
|
|
case R.id.cancel: |
|
|
|
|
Aria.download(this).load(DOWNLOAD_URL).cancel(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |