merge code
This commit is contained in:
@ -92,69 +92,4 @@ public class DownloadModule extends BaseModule {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载广播过滤器
|
||||
*/
|
||||
public IntentFilter getDownloadFilter() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addDataScheme(getContext().getPackageName());
|
||||
filter.addAction(Aria.ACTION_PRE);
|
||||
filter.addAction(Aria.ACTION_POST_PRE);
|
||||
filter.addAction(Aria.ACTION_RESUME);
|
||||
filter.addAction(Aria.ACTION_START);
|
||||
filter.addAction(Aria.ACTION_RUNNING);
|
||||
filter.addAction(Aria.ACTION_STOP);
|
||||
filter.addAction(Aria.ACTION_CANCEL);
|
||||
filter.addAction(Aria.ACTION_COMPLETE);
|
||||
filter.addAction(Aria.ACTION_FAIL);
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Receiver
|
||||
*/
|
||||
public BroadcastReceiver createReceiver(final Handler handler) {
|
||||
|
||||
return new BroadcastReceiver() {
|
||||
long len = 0;
|
||||
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case Aria.ACTION_POST_PRE:
|
||||
DownloadEntity entity = intent.getParcelableExtra(Aria.DOWNLOAD_ENTITY);
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download onPre");
|
||||
handler.obtainMessage(SingleTaskActivity.DOWNLOAD_PRE, len).sendToTarget();
|
||||
break;
|
||||
case Aria.ACTION_START:
|
||||
L.d(TAG, "download start");
|
||||
break;
|
||||
case Aria.ACTION_RESUME:
|
||||
L.d(TAG, "download resume");
|
||||
long location = intent.getLongExtra(Aria.CURRENT_LOCATION, 1);
|
||||
handler.obtainMessage(SingleTaskActivity.DOWNLOAD_RESUME, location).sendToTarget();
|
||||
break;
|
||||
case Aria.ACTION_RUNNING:
|
||||
long current = intent.getLongExtra(Aria.CURRENT_LOCATION, 0);
|
||||
int progress = len == 0 ? 0 : (int) ((current * 100) / len);
|
||||
handler.obtainMessage(SingleTaskActivity.DOWNLOAD_RUNNING, progress).sendToTarget();
|
||||
break;
|
||||
case Aria.ACTION_STOP:
|
||||
L.d(TAG, "download stop");
|
||||
handler.sendEmptyMessage(SingleTaskActivity.DOWNLOAD_STOP);
|
||||
break;
|
||||
case Aria.ACTION_COMPLETE:
|
||||
handler.sendEmptyMessage(SingleTaskActivity.DOWNLOAD_COMPLETE);
|
||||
break;
|
||||
case Aria.ACTION_CANCEL:
|
||||
handler.sendEmptyMessage(SingleTaskActivity.DOWNLOAD_CANCEL);
|
||||
break;
|
||||
case Aria.ACTION_FAIL:
|
||||
handler.sendEmptyMessage(SingleTaskActivity.DOWNLOAD_FAILE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt";
|
||||
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";
|
||||
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
|
||||
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
|
||||
//"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt";
|
||||
//"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1";
|
||||
//不支持断点的链接
|
||||
@ -209,6 +209,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@Download.onTaskCancel(DOWNLOAD_URL) void taskCancel(DownloadTask task) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
|
||||
L.d(TAG, "task__cancel");
|
||||
//Aria.download(this)
|
||||
// .load(DOWNLOAD_URL)
|
||||
// .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
// .add();
|
||||
}
|
||||
|
||||
@Download.onTaskFail(DOWNLOAD_URL) void taskFail(DownloadTask task) {
|
||||
@ -242,7 +246,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
setBtState(false);
|
||||
}
|
||||
mSize.setText(target.getConvertFileSize());
|
||||
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
@ -257,6 +260,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
} else if (text.equals("恢复")) {
|
||||
Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
}
|
||||
//DownloadTarget target = Aria.download(this)
|
||||
// .load(DOWNLOAD_URL)
|
||||
// .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||
//target.add();
|
||||
//target.cancel();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
|
@ -106,10 +106,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning({
|
||||
"https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk",
|
||||
"http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk"
|
||||
}) void taskRunning(DownloadTask task) {
|
||||
@Download.onTaskRunning() void taskRunning(DownloadTask task) {
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user