Aria 重构,Readme编写
This commit is contained in:
@ -7,8 +7,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 58
|
||||
versionName "2.3.0"
|
||||
versionCode 79
|
||||
versionName "2.3.1"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -18,6 +18,7 @@ package com.arialyy.aria.core;
|
||||
import com.arialyy.aria.core.scheduler.OnSchedulerListener;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/12/5.
|
||||
* AM 接收器
|
||||
*/
|
||||
public class AMReceiver {
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
import com.arialyy.aria.core.command.CmdFactory;
|
||||
@ -9,7 +24,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by utstarcom on 2016/12/5.
|
||||
* Created by lyy on 2016/12/5.
|
||||
* https://github.com/AriaLyy/Aria
|
||||
*/
|
||||
public class AMTarget {
|
||||
private AMReceiver receiver;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -26,6 +26,7 @@ import android.os.Build;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/12/1.
|
||||
* https://github.com/AriaLyy/Aria
|
||||
* Aria启动,管理全局任务
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
@ -8,10 +23,12 @@ import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.command.CmdFactory;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.core.command.IDownloadCmd;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -20,6 +37,7 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/12/1.
|
||||
* https://github.com/AriaLyy/Aria
|
||||
* Aria管理器,任务操作在这里执行
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
|
||||
@ -48,6 +66,24 @@ import java.util.Set;
|
||||
return getTarget(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载列表
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadList(){
|
||||
return DownloadEntity.findAllData(DownloadEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载链接获取下载实体
|
||||
*/
|
||||
public DownloadEntity getDownloadEntity(String downloadUrl) {
|
||||
if (TextUtils.isEmpty(downloadUrl)) {
|
||||
throw new IllegalArgumentException("下载链接不能为null");
|
||||
}
|
||||
return DownloadEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
|
||||
new String[] { downloadUrl });
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止所有正在执行的任务
|
||||
*/
|
||||
@ -62,11 +98,37 @@ import java.util.Set;
|
||||
mManager.setCmds(stopCmds).exe();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载超时时间
|
||||
*/
|
||||
@Deprecated
|
||||
private AriaManager setTimeOut(int timeOut) {
|
||||
Configuration.getInstance().setTimeOut(timeOut);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载失败重试次数
|
||||
*/
|
||||
public AriaManager setReTryNum(int reTryNum) {
|
||||
Configuration.getInstance().setReTryNum(reTryNum);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载失败重试间隔
|
||||
*/
|
||||
public AriaManager setReTryInterval(int interval) {
|
||||
Configuration.getInstance().setReTryInterval(interval);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否打开下载广播
|
||||
*/
|
||||
public void openBroadcast(boolean open) {
|
||||
|
||||
public AriaManager openBroadcast(boolean open) {
|
||||
Configuration.getInstance().setOpenBroadcast(open);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,12 +136,13 @@ import java.util.Set;
|
||||
*
|
||||
* @param maxDownloadNum 最大下载数
|
||||
*/
|
||||
public void setMaxDownloadNum(int maxDownloadNum) {
|
||||
if (maxDownloadNum < 1){
|
||||
public AriaManager setMaxDownloadNum(int maxDownloadNum) {
|
||||
if (maxDownloadNum < 1) {
|
||||
Log.w(TAG, "最大任务数不能小于 1");
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
mManager.getTaskQueue().setDownloadNum(maxDownloadNum);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core.command;
|
||||
|
||||
import android.util.Log;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -25,6 +25,7 @@ import com.arialyy.aria.core.DownloadManager;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/11.
|
||||
@ -325,7 +326,9 @@ public class Task {
|
||||
if (location != -1) {
|
||||
intent.putExtra(DownloadManager.CURRENT_LOCATION, location);
|
||||
}
|
||||
//context.sendBroadcast(intent);
|
||||
if (Configuration.isOpenBreadCast) {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.util;
|
||||
|
||||
import android.util.Log;
|
||||
@ -36,6 +51,7 @@ public class Configuration {
|
||||
* 超时时间,默认 10000 ms
|
||||
*/
|
||||
private static final String DOWNLOAD_TIME_OUT = "DOWNLOAD_TIME_OUT";
|
||||
public static boolean isOpenBreadCast = false;
|
||||
|
||||
private static Configuration INSTANCE = null;
|
||||
private File mConfigFile = null;
|
||||
@ -57,6 +73,8 @@ public class Configuration {
|
||||
mConfigFile.getParentFile().mkdirs();
|
||||
mConfigFile.createNewFile();
|
||||
init();
|
||||
}else {
|
||||
isOpenBreadCast = isOpenBroadcast();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -123,7 +141,7 @@ public class Configuration {
|
||||
/**
|
||||
* 设置重试间隔
|
||||
*/
|
||||
public void setReTryreTryInterval(int reTryInterval) {
|
||||
public void setReTryInterval(int reTryInterval) {
|
||||
if (reTryInterval < 4000) {
|
||||
Log.w(TAG, "重试间隔不能小于4000ms");
|
||||
return;
|
||||
@ -184,6 +202,7 @@ public class Configuration {
|
||||
* 设置是否打开下载广播
|
||||
*/
|
||||
public void setOpenBroadcast(boolean openBroadcast) {
|
||||
isOpenBreadCast = openBroadcast;
|
||||
save(OPEN_BROADCAST, openBroadcast + "");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
148
README.md
148
README.md
@ -1,39 +1,88 @@
|
||||
# DownloadUtil
|
||||
# Aria
|
||||
</br>
|
||||
这是一个 android 智能切换多任务断点续传工具,使用该工具,你可以很容易实现`多线程下载功能和复杂的任务自动切换功能`</br>
|
||||
+ 该工具具有以下特点:
|
||||
- 通过命令控制下载
|
||||
- 可在广播中接收任务的各种下载状态
|
||||
Aria,致力于让下载傻瓜化</br>
|
||||
+ Aria有以下特点:
|
||||
- 简单
|
||||
- 可自定义是否使用广播
|
||||
- 支持多线程、多任务下载
|
||||
- 支持任务自动切换
|
||||
- 支持下载速度直接获取
|
||||
|
||||
如果你觉得我的代码对你有帮助,您的star和issues将是对我最大支持.`^_^`
|
||||
[Aria怎样使用?](#使用)
|
||||
|
||||
#下载
|
||||
[](https://bintray.com/arialyy/maven/MTDownloadUtil/_latestVersion)<br/>
|
||||
compile 'com.arialyy.downloadutil:DownloadUtil:2.1.1'
|
||||
如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^`
|
||||
|
||||
## 下载
|
||||
[](https://bintray.com/arialyy/maven/Aria/_latestVersion)</br>
|
||||
compile 'com.arialyy.aria:Aria:2.3.1'
|
||||
|
||||
|
||||
#示例
|
||||
## 示例
|
||||

|
||||

|
||||
|
||||
# 性能展示
|
||||
## 性能展示
|
||||

|
||||
|
||||
# 使用
|
||||
* 一、在Application注册下载器
|
||||
***
|
||||
## 使用
|
||||
### 一、Aria 是实体驱动型的工具,所以,第一步,你需要创建一个下载实体
|
||||
```java
|
||||
public class BaseApplication extends Application {
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
//注册下载器
|
||||
DownloadManager.init(this);
|
||||
}
|
||||
}
|
||||
DownloadEntity mEntity = new DownloadEntity();
|
||||
mEntity.setFileName(fileName); //设置文件名
|
||||
mEntity.setDownloadUrl(downloadUrl); //设置下载链接
|
||||
mEntity.setDownloadPath(downloadPath); //设置存放路径
|
||||
```
|
||||
### 二、为了能接收到Aria传递的数据,你需要把你的Activity或fragment注册到Aria管理器中,注册的方式很简单,在onResume
|
||||
```java
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
```
|
||||
### 三、还记得上面的DownloadEntity吗?现在是时候使用它进行下载了
|
||||
- 启动下载
|
||||
```java
|
||||
Aria.whit(this).load(mEntity).start();
|
||||
```
|
||||
- 暂停下载
|
||||
```java
|
||||
Aria.whit(this).load(mEntity).stop();
|
||||
```
|
||||
- 恢复下载
|
||||
```java
|
||||
Aria.whit(this).load(mEntity).resume();
|
||||
```
|
||||
- 取消下载
|
||||
```java
|
||||
Aria.whit(this).load(mEntity).cancel();
|
||||
```
|
||||
|
||||
* 二、创建广播接收器,用来接收下载的各种状态
|
||||
### 四、关于Aria,你还需要知道的一些东西
|
||||
- 设置下载任务数,Aria默认下载任务为**2**
|
||||
```java
|
||||
Aria.get(getContext()).setMaxDownloadNum(num);
|
||||
```
|
||||
- 停止所有下载
|
||||
```java
|
||||
Aria.get(this).stopAllTask();
|
||||
```
|
||||
- 设置失败重试次数,从事次数不能少于 1
|
||||
```java
|
||||
Aria.get(this).setReTryNum(10);
|
||||
```
|
||||
- 设置失败重试间隔,重试间隔不能小于 5000ms
|
||||
```java
|
||||
Aria.get(this).setReTryInterval(5000);
|
||||
```
|
||||
- 设置是否打开广播,如果你需要在Service后台获取下载完成情况,那么你需要打开Aria广播发送按钮,[Aria广播使用](#广播使用)
|
||||
```java
|
||||
Aria.get(this).openBroadcast(true);
|
||||
```
|
||||
|
||||
***
|
||||
### 广播使用
|
||||
#### 一、创建广播接收器,用来接收下载的各种状态
|
||||
```java
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
long len = 0;
|
||||
@ -72,7 +121,7 @@ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
};
|
||||
```
|
||||
|
||||
* 三、在Activity中创建广播过滤器
|
||||
#### 二、在Activity中创建广播过滤器
|
||||
```java
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
@ -90,63 +139,16 @@ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
registerReceiver(mReceiver, filter);
|
||||
}
|
||||
```
|
||||
|
||||
* 四、创建下载实体
|
||||
```java
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setFileName(fileName); //设置文件名
|
||||
entity.setDownloadUrl(downloadUrl); //设置下载链接
|
||||
entity.setDownloadPath(downloadPath); //设置存放路径
|
||||
```
|
||||
|
||||
* 五、通过命令控制下载(下载状态控制,或下载任务切换将自动完成)</br>
|
||||
**!!注意:命令需要第四步的下载实体支持**
|
||||
|
||||
- 获取命令工厂实例和下载管理器实例
|
||||
```java
|
||||
CmdFactory factory = CmdFactory.getInstance();
|
||||
DownloadManager manager = DownloadManager.getInstance();
|
||||
```
|
||||
- 开始命令、恢复下载命令都是同一个
|
||||
```java
|
||||
private void start() {
|
||||
List<IDownloadCmd> commands = new ArrayList<>();
|
||||
IDownloadCmd addCMD = factory.createCmd(this, entity, CmdFactory.TASK_CREATE);
|
||||
IDownloadCmd startCmd = factory.createCmd(this, entity, CmdFactory.TASK_START);
|
||||
commands.add(addCMD);
|
||||
commands.add(startCmd);
|
||||
manager.setCmds(commands).exe();
|
||||
}
|
||||
```
|
||||
- 停止命令
|
||||
```java
|
||||
private void stop() {
|
||||
IDownloadCmd stopCmd = factory.createCmd(this, entity, CmdFactory.TASK_STOP);
|
||||
manager.setCmd(stopCmd).exe();
|
||||
}
|
||||
```
|
||||
- 取消命令(取消下载、删除下载任务)
|
||||
```java
|
||||
private void cancel() {
|
||||
IDownloadCmd cancelCmd = factory.createCmd(this, entity, CmdFactory.TASK_CANCEL);
|
||||
manager.setCmd(cancelCmd).exe();
|
||||
}
|
||||
```
|
||||
|
||||
# 修改最大任务数
|
||||
```
|
||||
mManager.getTaskQueue().setDownloadNum(num);
|
||||
|
||||
```
|
||||
|
||||
# 开发日志
|
||||
***
|
||||
## 开发日志
|
||||
+ v_2.1.0 修复大量bug
|
||||
+ v_2.1.1 增加,选择最大下载任务数接口
|
||||
+ v_2.3.1 重命名为Aria,下载流程简化
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright 2016 AriaLyy(DownloadUtil)
|
||||
Copyright 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -104,8 +104,15 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
//};
|
||||
|
||||
public void onClick(View view){
|
||||
DownloadNumDialog dialog = new DownloadNumDialog(this);
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
switch (view.getId()){
|
||||
case R.id.num:
|
||||
DownloadNumDialog dialog = new DownloadNumDialog(this);
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
break;
|
||||
case R.id.stop_all:
|
||||
Aria.get(this).stopAllTask();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -17,6 +17,8 @@
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
@ -30,12 +32,15 @@ import butterknife.Bind;
|
||||
import com.arialyy.aria.core.AMTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadManager;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
|
||||
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@ -56,7 +61,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
@Bind(R.id.speed) TextView mSpeed;
|
||||
private DownloadEntity mEntity;
|
||||
private BroadcastReceiver mReceiver;
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(DownloadManager.ACTION_START)) {
|
||||
L.d("START");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Handler mUpdateHandler = new Handler() {
|
||||
@Override public void handleMessage(Message msg) {
|
||||
@ -126,10 +138,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
@ -141,11 +155,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setTitle("单任务下载");
|
||||
init();
|
||||
Aria.get(this).openBroadcast(true);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mEntity = DbEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
|
||||
new String[] { DOWNLOAD_URL });
|
||||
mEntity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (mEntity != null) {
|
||||
mPb.setProgress((int) ((mEntity.getCurrentProgress() * 100) / mEntity.getFileSize()));
|
||||
mSize.setText(CommonUtil.formatFileSize(mEntity.getFileSize()));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -22,6 +22,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadManager;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@ -50,9 +51,7 @@ public class DownloadModule extends BaseModule {
|
||||
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
for (String url : urls) {
|
||||
DownloadEntity entity =
|
||||
DownloadEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
|
||||
new String[] { url });
|
||||
DownloadEntity entity = Aria.get(getContext()).getDownloadEntity(url);
|
||||
if (entity == null) {
|
||||
entity = createDownloadEntity(url);
|
||||
}
|
||||
@ -93,7 +92,6 @@ public class DownloadModule extends BaseModule {
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
entity.setFileName(fileName);
|
||||
//entity.setFileName("taskName_________" + i);
|
||||
entity.save();
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil)
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,15 +19,26 @@
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:onClick="onClick"
|
||||
android:id="@+id/num"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="下载数设置"
|
||||
android:layout_margin="16dp"
|
||||
android:onClick="onClick"
|
||||
android:text="下载数设置"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
<Button
|
||||
android:id="@+id/stop_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_margin="16dp"
|
||||
android:onClick="onClick"
|
||||
android:text="停止所有"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">DownloadDemo</string>
|
||||
<string name="app_name">Aria</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
<string-array name="test_apk_download_url">
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 788 KiB After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 44 KiB |
Reference in New Issue
Block a user