From 80f3a38fc60566a0fed8eb6e1bb132dabc0af23f Mon Sep 17 00:00:00 2001
From: AriaLyy <511455842@qq.com>
Date: Tue, 21 Mar 2017 21:43:55 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/misc.xml | 2 +-
.idea/modules.xml | 2 +-
.../main/java/com/arialyy/aria/core/Aria.java | 1 -
.../aria/core/download/DownloadTarget.java | 13 +-
.../com/arialyy/aria/core/inf/AbsTarget.java | 6 +-
DownloadApi.md | 40 +++++
README.md | 161 +++++++++---------
.../simple/download/DownloadDialog.java | 3 +-
.../simple/download/DownloadPopupWindow.java | 3 +-
.../simple/download/SimpleNotification.java | 2 +-
.../simple/download/SingleTaskActivity.java | 3 +-
.../fragment_download/DownloadFragment.java | 2 +-
.../multi_download/DownloadAdapter.java | 2 +-
.../arialyy/simple/upload/UploadActivity.java | 2 +-
14 files changed, 146 insertions(+), 96 deletions(-)
create mode 100644 DownloadApi.md
diff --git a/.idea/misc.xml b/.idea/misc.xml
index fbb68289..5d199810 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 9f4bd159..5f6de159 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,8 +2,8 @@
-
+
diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
index dbb99ffa..8857685f 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
@@ -43,7 +43,6 @@ import com.arialyy.aria.core.upload.UploadTask;
* .load(DOWNLOAD_URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- * .setDownloadName("test.apk") //文件名,必填
* .start();
*
*
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
index e50738f8..eedd7cd4 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
@@ -21,6 +21,7 @@ import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.util.CheckUtil;
+import java.io.File;
import java.util.Map;
/**
@@ -35,6 +36,14 @@ public class DownloadTarget extends AbsTarget
/**
* 停止下载
*/
- public void stop() {
+ protected void pause() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_STOP))
.exe();
@@ -150,7 +150,7 @@ public class AbsTarget
/**
* 恢复下载
*/
- public void resume() {
+ protected void resume() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START))
.exe();
@@ -168,7 +168,7 @@ public class AbsTarget
/**
* 重新下载
*/
- public void reStart() {
+ void reStart() {
cancel();
start();
}
diff --git a/DownloadApi.md b/DownloadApi.md
new file mode 100644
index 00000000..45134f3d
--- /dev/null
+++ b/DownloadApi.md
@@ -0,0 +1,40 @@
+## 关于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广播配置](https://github.com/AriaLyy/Aria/blob/v_2.0/BroadCast.md)
+
+ ```java
+ Aria.get(this).openBroadcast(true);
+ ```
+
+## https证书配置
+ + 将你的证书导入`assets`目录
+ + 调用以下代码配置ca证书相关信息
+
+ ```java
+ /**
+ * 设置CA证书信息
+ *
+ * @param caAlias ca证书别名
+ * @param caPath assets 文件夹下的ca证书完整路径
+ */
+ Aria.get(this).setCAInfo("caAlias","caPath");
+ ```
diff --git a/README.md b/README.md
index ddc19c92..da521d1a 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,17 @@
# Aria
![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)
-Aria,致力于让下载傻瓜化
+Aria,让上传、下载更容易实现
+ Aria有以下特点:
- 简单
- 可在Dialog、popupWindow等组件中使用
- - 可自定义是否使用广播
- 支持多线程、多任务下载
- - 支持任务自动切换
- - 支持下载速度直接获取
+ - 支持多任务自动调度
+ - 可以直接获取速度
- 支持https地址下载
-[Aria怎样使用?](#使用)
+Aria怎样使用?
+* [下载](#使用)
+* [上传](#上传)
如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^`
@@ -24,113 +25,115 @@ compile 'com.arialyy.aria:Aria:2.4.0'
![多任务下载](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/download_img.gif)
![Dialog使用](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/dialog_use.gif "")
-## 性能展示
-![性能展示](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/performance.png)
+## 性能
+![性能展示](https://github.com/AriaLyy/DownloadUtil/blob/master/img/performance.png)
***
## 使用
-### 一、添加权限
+由于Aria涉及到文件和网络的操作,因此需要你在manifest文件中添加以下权限
```xml
```
-### 二、只需要以下参数,你便能很简单的使用Aria下载文件了
-```java
- Aria.whit(this)
- .load(DOWNLOAD_URL) //下载地址,必填
- .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径,必填
- .setDownloadName("test.apk") //文件名,必填
- .start();
-```
-### 三、为了能接收到Aria传递的数据,你需要把你的Activity或fragment注册到Aria管理器中,注册的方式很简单,在onResume
-```java
-@Override protected void onResume() {
- super.onResume();
- Aria.whit(this).addSchedulerListener(new MySchedulerListener());
- }
-```
-### 四、通过下载链接,你还能使用Aria执行很多操作,如:
-Aria支持https下载,如果你希望使用自己的ca证书,那么你需要进行[Aria https证书配置](#https证书配置)
-- 添加任务(不进行下载)
+## 使用Aria进行下载
+* 添加任务(不进行下载),当其他下载任务完成时,将自动下载等待中的任务
```java
- Aria.whit(this).load(DOWNLOAD_URL)
- .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径,必填
- .setDownloadName("test.apk") //文件名,必填
- .add();
- ```
-- 启动下载
-
- ```java
- Aria.whit(this).load(DOWNLOAD_URL).start();
- ```
-- 暂停下载
-
- ```java
- Aria.whit(this).load(DOWNLOAD_URL).stop();
+ Aria.download(this)
+ .load(DOWNLOAD_URL)
+ .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径
+ .add();
```
-- 恢复下载
- ```java
- Aria.whit(this).load(DOWNLOAD_URL).resume();
- ```
-- 取消下载
+* 下载
```java
- Aria.whit(this).load(DOWNLOAD_URL).cancel();
+ Aria.download(this)
+ .load(DOWNLOAD_URL) //读取下载地址
+ .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //设置文件保存的完整路径
+ .start(); //启动下载
```
-- 获取当前下载进度
+* 暂停
```java
- Aria.whit(this).load(DOWNLOAD_URL).getCurrentProgress();
+ Aria.download(this).load(DOWNLOAD_URL).pause();
```
-- 获取文件大小
+* 恢复下载
```java
- Aria.whit(this).load(DOWNLOAD_URL).getFileSize();
+ Aria.download(this).load(DOWNLOAD_URL).resume();
```
-
-### 五、关于Aria,你还需要知道的一些东西
-- 设置下载任务数,Aria默认下载任务为**2**
+* 取消下载
```java
- Aria.get(getContext()).setMaxDownloadNum(num);
+ Aria.download(this).load(DOWNLOAD_URL).cancel();
```
-- 停止所有下载
- ```java
- Aria.get(this).stopAllTask();
- ```
-- 设置失败重试次数,从事次数不能少于 1
+### 二、如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。
+* 创建事件类
```java
- Aria.get(this).setReTryNum(10);
+ final static class MySchedulerListener extends Aria.DownloadSchedulerListener{
+ @Override public void onTaskPre(DownloadTask task) {
+ super.onTaskPre(task);
+ }
+
+ @Override public void onTaskStop(DownloadTask task) {
+ super.onTaskStop(task);
+ }
+
+ @Override public void onTaskCancel(DownloadTask task) {
+ super.onTaskCancel(task);
+ }
+
+ @Override public void onTaskRunning(DownloadTask task) {
+ super.onTaskRunning(task);
+ }
+ }
```
-- 设置失败重试间隔,重试间隔不能小于 5000ms
- ```java
- Aria.get(this).setReTryInterval(5000);
- ```
-- 设置是否打开广播,如果你需要在Service后台获取下载完成情况,那么你需要打开Aria广播,[Aria广播配置](https://github.com/AriaLyy/Aria/blob/v_2.0/BroadCast.md)
+* 将事件注册到Aria
```java
- Aria.get(this).openBroadcast(true);
+ @Override protected void onResume() {
+ super.onResume();
+ Aria.whit(this).addSchedulerListener(new MySchedulerListener());
+ }
```
-### https证书配置
- + 将你的证书导入`assets`目录
- + 调用以下代码配置ca证书相关信息
-
- ```java
- /**
- * 设置CA证书信息
- *
- * @param caAlias ca证书别名
- * @param caPath assets 文件夹下的ca证书完整路径
- */
- Aria.get(this).setCAInfo("caAlias","caPath");
- ```
+### 关于下载的其它api
+[Download API]()
+
+**tips:为了防止内存泄露的情况,事件类需要使用staic进行修饰**
+
+## 上传
+ * 添加任务(只添加,不上传)
+
+ ```java
+ Aria.upload(this)
+ .load(filePath) //文件路径
+ .setUploadUrl(uploadUrl) //上传路径
+ .setAttachment(fileKey) //服务器读取文件的key
+ .add();
+ ```
+
+ * 上传
+
+ ```java
+ Aria.upload(this)
+ .load(filePath) //文件路径
+ .setUploadUrl(uploadUrl) //上传路径
+ .setAttachment(fileKey) //服务器读取文件的key
+ .start();
+ ```
+ * 取消上传
+
+ ```java
+ Aria.upload(this)
+ .load(filePath)
+ .cancel();
+ ```
***
## 开发日志
diff --git a/app/src/main/java/com/arialyy/simple/download/DownloadDialog.java b/app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
index 62a7e593..2a1b94fc 100644
--- a/app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
+++ b/app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
@@ -62,11 +62,10 @@ public class DownloadDialog extends AbsDialog {
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
- .setDownloadName("daialog.apk")
.start();
break;
case R.id.stop:
- Aria.download(this).load(DOWNLOAD_URL).stop();
+ Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
diff --git a/app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java b/app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java
index c5631a4f..294d8003 100644
--- a/app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java
+++ b/app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java
@@ -64,11 +64,10 @@ public class DownloadPopupWindow extends AbsPopupWindow {
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
- .setDownloadName("daialog.apk")
.start();
break;
case R.id.stop:
- Aria.download(this).load(DOWNLOAD_URL).stop();
+ Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
diff --git a/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java b/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
index e4e6c605..7fd48a2a 100644
--- a/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
+++ b/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
@@ -47,7 +47,7 @@ public class SimpleNotification {
}
public void stop() {
- Aria.download(mContext).load(DOWNLOAD_URL).stop();
+ Aria.download(mContext).load(DOWNLOAD_URL).pause();
}
private static class DownloadCallback extends Aria.DownloadSchedulerListener {
diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
index 256b5efb..1afe953d 100644
--- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
+++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
@@ -227,12 +227,11 @@ public class SingleTaskActivity extends BaseActivity {
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- .setDownloadName("test.apk")
.start();
}
private void stop() {
- Aria.download(this).load(DOWNLOAD_URL).stop();
+ Aria.download(this).load(DOWNLOAD_URL).pause();
}
private void cancel() {
diff --git a/app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java b/app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
index d9599818..133c884e 100644
--- a/app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
+++ b/app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
@@ -62,7 +62,7 @@ public class DownloadFragment extends AbsFragment {
.start();
break;
case R.id.stop:
- Aria.download(this).load(DOWNLOAD_URL).stop();
+ Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java b/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
index 50326e33..165d2959 100644
--- a/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
+++ b/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
@@ -187,7 +187,7 @@ final class DownloadAdapter extends AbsRVAdapter {
}
@OnClick(R.id.stop) void stop() {
- Aria.upload(this).load(FILE_PATH).stop();
+ Aria.upload(this).load(FILE_PATH).cancel();
}
@OnClick(R.id.remove) void remove() {