AriaLyy 8 years ago
parent e71729bd09
commit 72e296adeb
  1. 6
      Aria/build.gradle
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  4. 3
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  5. 2
      AriaAnnotations/build.gradle
  6. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java
  7. 64
      README.md
  8. 1
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  9. 1
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  10. 26
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  11. 3
      app/src/main/res/menu/menu_highest_priority.xml
  12. 10
      app/src/main/res/menu/menu_mutil_task.xml
  13. 4
      build.gradle

@ -22,8 +22,8 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaCompiler') // compile project(':AriaCompiler')
// compile project(':AriaAnnotations') compile project(':AriaAnnotations')
} }
apply from: 'bintray-release.gradle'
//apply from: 'jcenter.gradle' //apply from: 'jcenter.gradle'
//apply from: 'bintray-release.gradle'

@ -2,6 +2,7 @@ package com.arialyy.aria.core.command;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
@ -40,7 +41,8 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
private ITask createTask(DownloadEntity entity) { private ITask createTask(DownloadEntity entity) {
ITask task = mQueue.getTask(entity); ITask task = mQueue.getTask(entity);
if (task == null) { if (task == null) {
task = mQueue.createTask(mTargetName, mEntity); DownloadTaskEntity taskEntity = new DownloadTaskEntity(entity);
task = mQueue.createTask(mTargetName, taskEntity);
} else { } else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】"); Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
} }

@ -144,6 +144,8 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
/** /**
* 恢复所有正在下载的任务 * 恢复所有正在下载的任务
* 1.如果执行队列没有满则开始下载任务直到执行队列满
* 2.如果队列执行队列已经满了则将所有任务添加到等待队列中
*/ */
public void resumeAllTask() { public void resumeAllTask() {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);

@ -352,6 +352,9 @@ public class CommonUtil {
* @param size file.length() 获取文件大小 * @param size file.length() 获取文件大小
*/ */
public static String formatFileSize(double size) { public static String formatFileSize(double size) {
if (size < 0) {
return "0kb";
}
double kiloByte = size / 1024; double kiloByte = size / 1024;
if (kiloByte < 1) { if (kiloByte < 1) {
return size + "b"; return size + "b";

@ -11,4 +11,4 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
} }
//apply from: 'bintray-release.gradle' apply from: 'bintray-release.gradle'

@ -154,7 +154,7 @@ class ElementHandle {
ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build(); ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Set<String> keys = keyMapping.get(\"") sb.append("Set<String> keys = keyMapping.get(\"")
.append(annotation.getSimpleName()) .append(methodName)
.append("\");\n"); .append("\");\n");
sb.append("if (keys != null) {\n\tif (keys.contains(task.getKey())) {\n") sb.append("if (keys != null) {\n\tif (keys.contains(task.getKey())) {\n")
.append("\t\tobj.") .append("\t\tobj.")

@ -27,8 +27,8 @@ Aria怎样使用?
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java ```java
compile 'com.arialyy.aria:Aria:3.1.8' compile 'com.arialyy.aria:Aria:3.1.9'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8' annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.9'
``` ```
## 示例 ## 示例
@ -83,18 +83,18 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
### 下载状态获取 ### 下载状态获取
如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。 如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。
* 将对象注册到Aria 1. 将对象注册到Aria
` Aria.download(this).register();`或`Aria.upload(this).register();` `Aria.download(this).register();`或`Aria.upload(this).register();`
```java ```java
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Aria.download(this).register(); Aria.download(this).register();
} }
``` ```
* 使用'@Download'或'@Upload'注解你的函数 2. 使用`@Download`或`@Upload`注解你的函数
**注意:** **注意:**
- 注解回掉采用Apt的方式实现,所以,你不需要担心这会影响你机器的性能 - 注解回掉采用Apt的方式实现,所以,你不需要担心这会影响你机器的性能
@ -102,18 +102,14 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
- 被注解的方法**只能有一个参数,并且参数类型必须是`DownloadTask`或`UploadTask`** - 被注解的方法**只能有一个参数,并且参数类型必须是`DownloadTask`或`UploadTask`**
- 方法名可以为任意字符串 - 方法名可以为任意字符串
* 除了在widget(Activity、Fragment、Dialog、Popupwindow)中使用注解方法外,你还可以在Service、Notification等组件中使用注解函数。 3. 除了在widget(Activity、Fragment、Dialog、Popupwindow)中使用注解方法外,你还可以在Service、Notification等组件中使用注解函数。
```java ```java
@Download.onPre @Download.onPre(DOWNLOAD_URL)
protected void onPre(DownloadTask task) {} protected void onPre(DownloadTask task) {}
@Download.onTaskStart @Download.onTaskStart
void taskStart(DownloadTask task) { void taskStart(DownloadTask task) {}
//通过下载地址可以判断任务是否是你指定的任务
if (task.getKey().equals(DOWNLOAD_URL)) {
}
}
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) {} protected void running(DownloadTask task) {}
@ -137,6 +133,19 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
public void onNoSupportBreakPoint(DownloadTask task) {} public void onNoSupportBreakPoint(DownloadTask task) {}
``` ```
4. 如果你希望对单个任务,或某一些特定任务设置监听器。
在注解中添加任务的下载地址,**则表示只有该任务才会触发被注解的方法**。
```java
@Download.onTaskRunning({
"https://test.xx.apk",
"http://test.xx2.apk"
}) void taskRunning(DownloadTask task) {
mAdapter.setProgress(task.getDownloadEntity());
}
```
在上面的例子中,只有下载地址是`https://test.xx.apk`和`http://test.xx2.apk`才会触发
`taskRunning(DownloadTask task)`方法。
### Aria参数配置 ### Aria参数配置
#### 配置文件设置参数 #### 配置文件设置参数
@ -216,24 +225,33 @@ Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
### 常用接口 ### 常用接口
* 停止所有任务 * 停止所有任务
```java ```java
Aria.download(this).stopAllTask(); Aria.download(this).stopAllTask();
``` ```
* 恢复所有停止的任务
```java
Aria.download(this).resumeAllTask();
```
* 删除所有任务 * 删除所有任务
```java ```java
Aria.download(this).removeAllTask(); Aria.download(this).removeAllTask();
``` ```
* 获取当前任务的下载速度 * 获取当前任务的下载速度
速度参数有点特殊,需要[下载事件支持](#下载状态获取) 速度参数有点特殊,需要[下载事件支持](#下载状态获取)
``` java ``` java
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
//如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 m/s //如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s
String convertSpeed = task.getConvertSpeed(); String convertSpeed = task.getConvertSpeed();
//如果你有自己的单位格式,可以通过以下方法获取原始byte长度 //如果你有自己的单位格式,可以通过以下方法获取原始byte长度
long speed = task.getSpeed(); long speed = task.getSpeed();
} }
``` ```
* 获取下载的文件大小、当前进度百分比 * 获取下载的文件大小、当前进度百分比
同样的,你也可以在DownloadTask对象中获取下载的文件大小 同样的,你也可以在DownloadTask对象中获取下载的文件大小
``` ```
@ -246,14 +264,13 @@ Aria.download(this).removeAllTask();
int percent = task.getPercent(); int percent = task.getPercent();
} }
``` ```
* 设置高优先级任务 * 设置高优先级任务
如果你希望优先下载某一个任务,你可以 如果你希望优先下载某一个任务,你可以
``` java ``` java
Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority(); Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority();
``` ```
**tips:为了防止内存泄露的情况,事件类需要使用staic进行修饰**
## 上传 ## 上传
* 添加任务(只添加,不上传) * 添加任务(只添加,不上传)
@ -304,6 +321,7 @@ Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority(
## 开发日志 ## 开发日志
+ v_3.1.9 修复stopAll队列没有任务时崩溃的问题,增加针对单个任务监听的功能
+ v_3.1.7 修复某些文件下载不了的bug,增加apt注解方法,事件获取更加简单了 + v_3.1.7 修复某些文件下载不了的bug,增加apt注解方法,事件获取更加简单了
+ v_3.1.6 取消任务时onTaskCancel回调两次的bug + v_3.1.6 取消任务时onTaskCancel回调两次的bug
+ v_3.1.5 优化代码结构,增加优先下载任务功能。 + v_3.1.5 优化代码结构,增加优先下载任务功能。

@ -211,6 +211,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskFail(DOWNLOAD_URL) void taskFail(DownloadTask task) { @Download.onTaskFail(DOWNLOAD_URL) void taskFail(DownloadTask task) {
L.d(TAG, "task__fail");
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE); mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
} }

@ -24,6 +24,7 @@ import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.adapter.AbsHolder; import com.arialyy.simple.base.adapter.AbsHolder;

@ -20,12 +20,15 @@ import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiDownloadBinding; import com.arialyy.simple.databinding.ActivityMultiDownloadBinding;
@ -35,12 +38,16 @@ import java.util.List;
/** /**
* Created by AriaL on 2017/1/6. * Created by AriaL on 2017/1/6.
*/ */
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> { public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
@Bind(R.id.list) RecyclerView mList; @Bind(R.id.list) RecyclerView mList;
private DownloadAdapter mAdapter; private DownloadAdapter mAdapter;
private List<DownloadEntity> mData = new ArrayList<>(); private List<DownloadEntity> mData = new ArrayList<>();
String[] mFilterStr = new String[] {
"https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk",
"http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk"
};
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.activity_multi_download; return R.layout.activity_multi_download;
} }
@ -58,6 +65,16 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
mList.setAdapter(mAdapter); mList.setAdapter(mAdapter);
} }
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_mutil_task, menu);
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onMenuItemClick(MenuItem item) {
Aria.download(this).resumeAllTask();
return true;
}
@Download.onPre void onPre(DownloadTask task) { @Download.onPre void onPre(DownloadTask task) {
L.d(TAG, "download onPre"); L.d(TAG, "download onPre");
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
@ -82,14 +99,17 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
} }
@Download.onTaskFail void taskFail(DownloadTask task) { @Download.onTaskFail void taskFail(DownloadTask task) {
L.d(TAG, "download fail"); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskRunning void taskRunning(DownloadTask task) { @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) {
mAdapter.setProgress(task.getDownloadEntity()); mAdapter.setProgress(task.getDownloadEntity());
} }
} }

@ -7,9 +7,8 @@
android:icon="@mipmap/ic_add_black_48dp" android:icon="@mipmap/ic_add_black_48dp"
android:orderInCategory="80" android:orderInCategory="80"
android:title="添加一组任务" android:title="添加一组任务"
app:showAsAction="ifRoom" app:showAsAction="always"
/> />
<item <item
android:id="@+id/help" android:id="@+id/help"
android:icon="@mipmap/ic_help_black_48dp" android:icon="@mipmap/ic_help_black_48dp"

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/resume_all"
android:orderInCategory="80"
android:title="resume_all_task"
app:showAsAction="always"
/>
</menu>

@ -6,7 +6,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.android.tools.build:gradle:2.2.2'
// classpath 'com.novoda:bintray-release:0.5.0' classpath 'com.novoda:bintray-release:0.5.0'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
@ -37,7 +37,7 @@ ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
// publishVersion = '0.0.6' // publishVersion = '0.0.6'
publishVersion = '3.1.8' publishVersion = '3.1.9'
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria' website = 'https://github.com/AriaLyy/Aria'

Loading…
Cancel
Save