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. 46
      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')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaCompiler')
// compile project(':AriaAnnotations')
// compile project(':AriaCompiler')
compile project(':AriaAnnotations')
}
apply from: 'bintray-release.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 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.IEntity;
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) {
ITask task = mQueue.getTask(entity);
if (task == null) {
task = mQueue.createTask(mTargetName, mEntity);
DownloadTaskEntity taskEntity = new DownloadTaskEntity(entity);
task = mQueue.createTask(mTargetName, taskEntity);
} else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
}

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

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

@ -11,4 +11,4 @@ dependencies {
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();
StringBuilder sb = new StringBuilder();
sb.append("Set<String> keys = keyMapping.get(\"")
.append(annotation.getSimpleName())
.append(methodName)
.append("\");\n");
sb.append("if (keys != null) {\n\tif (keys.contains(task.getKey())) {\n")
.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/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java
compile 'com.arialyy.aria:Aria:3.1.8'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
compile 'com.arialyy.aria:Aria:3.1.9'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.9'
```
## 示例
@ -83,7 +83,7 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
### 下载状态获取
如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。
* 将对象注册到Aria
1. 将对象注册到Aria
`Aria.download(this).register();`或`Aria.upload(this).register();`
```java
@ -94,7 +94,7 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
}
```
* 使用'@Download'或'@Upload'注解你的函数
2. 使用`@Download`或`@Upload`注解你的函数
**注意:**
- 注解回掉采用Apt的方式实现,所以,你不需要担心这会影响你机器的性能
@ -102,18 +102,14 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
- 被注解的方法**只能有一个参数,并且参数类型必须是`DownloadTask`或`UploadTask`**
- 方法名可以为任意字符串
* 除了在widget(Activity、Fragment、Dialog、Popupwindow)中使用注解方法外,你还可以在Service、Notification等组件中使用注解函数。
3. 除了在widget(Activity、Fragment、Dialog、Popupwindow)中使用注解方法外,你还可以在Service、Notification等组件中使用注解函数。
```java
@Download.onPre
@Download.onPre(DOWNLOAD_URL)
protected void onPre(DownloadTask task) {}
@Download.onTaskStart
void taskStart(DownloadTask task) {
//通过下载地址可以判断任务是否是你指定的任务
if (task.getKey().equals(DOWNLOAD_URL)) {
}
}
void taskStart(DownloadTask task) {}
@Download.onTaskRunning
protected void running(DownloadTask task) {}
@ -137,6 +133,19 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.8'
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参数配置
#### 配置文件设置参数
@ -219,21 +228,30 @@ Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
```java
Aria.download(this).stopAllTask();
```
* 恢复所有停止的任务
```java
Aria.download(this).resumeAllTask();
```
* 删除所有任务
```java
Aria.download(this).removeAllTask();
```
* 获取当前任务的下载速度
速度参数有点特殊,需要[下载事件支持](#下载状态获取)
``` java
@Override public void onTaskRunning(DownloadTask task) {
//如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 m/s
//如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s
String convertSpeed = task.getConvertSpeed();
//如果你有自己的单位格式,可以通过以下方法获取原始byte长度
long speed = task.getSpeed();
}
```
* 获取下载的文件大小、当前进度百分比
同样的,你也可以在DownloadTask对象中获取下载的文件大小
```
@ -246,14 +264,13 @@ Aria.download(this).removeAllTask();
int percent = task.getPercent();
}
```
* 设置高优先级任务
如果你希望优先下载某一个任务,你可以
``` java
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.6 取消任务时onTaskCancel回调两次的bug
+ v_3.1.5 优化代码结构,增加优先下载任务功能。

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

@ -24,6 +24,7 @@ import android.widget.TextView;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R;
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.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import butterknife.Bind;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiDownloadBinding;
@ -35,12 +38,16 @@ import java.util.List;
/**
* Created by AriaL on 2017/1/6.
*/
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
@Bind(R.id.list) RecyclerView mList;
private DownloadAdapter mAdapter;
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() {
return R.layout.activity_multi_download;
}
@ -58,6 +65,16 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
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) {
L.d(TAG, "download onPre");
mAdapter.updateState(task.getDownloadEntity());
@ -82,14 +99,17 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
}
@Download.onTaskFail void taskFail(DownloadTask task) {
L.d(TAG, "download fail");
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskComplete void taskComplete(DownloadTask task) {
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());
}
}

@ -7,9 +7,8 @@
android:icon="@mipmap/ic_add_black_48dp"
android:orderInCategory="80"
android:title="添加一组任务"
app:showAsAction="ifRoom"
app:showAsAction="always"
/>
<item
android:id="@+id/help"
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 {
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.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
@ -37,7 +37,7 @@ ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
// publishVersion = '0.0.6'
publishVersion = '3.1.8'
publishVersion = '3.1.9'
repoName='maven'
desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria'

Loading…
Cancel
Save