Merge branch 'v_3.0' of github.com:AriaLyy/Aria into v_3.0

pull/330/head
AriaLyy 8 years ago
commit 1052ab057d
  1. 4
      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. 7
      Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java
  5. 3
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  7. 3
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  8. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java
  9. 46
      README.md
  10. 2
      app/build.gradle
  11. 1
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  12. 1
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  13. 26
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  14. 3
      app/src/main/res/menu/menu_highest_priority.xml
  15. 10
      app/src/main/res/menu/menu_mutil_task.xml
  16. 3
      build.gradle
  17. 4
      gradle/wrapper/gradle-wrapper.properties
  18. BIN
      img/11.gif
  19. BIN
      img/max_speed.gif
  20. BIN
      img/popupwindow_use.gif

@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '25.0.2'
buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 9
@ -25,5 +25,5 @@ dependencies {
compile project(':AriaCompiler')
// compile project(':AriaAnnotations')
}
//apply from: 'jcenter.gradle'
//apply from: 'bintray-release.gradle'
//apply from: 'jcenter.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);

@ -44,10 +44,6 @@ final class SingleThreadTask implements Runnable {
private int mBufSize;
private IDownloadListener mListener;
private DownloadStateConstance CONSTANCE;
/**
* speed = (bufSize / 1024) * CoresNum / sleepTime; (8192 / 1024) * 4 / 1= 32 kb/s
*/
private long mSleepTime = 0;
SingleThreadTask(DownloadStateConstance constance, IDownloadListener listener,
@ -71,8 +67,7 @@ final class SingleThreadTask implements Runnable {
} else {
BigDecimal db = new BigDecimal(
((mBufSize / 1024) * (filterVersion() ? 1 : CONSTANCE.THREAD_NUM) / maxSpeed) * 1000);
db.setScale(0, BigDecimal.ROUND_HALF_UP);
mSleepTime = db.longValue();
mSleepTime = db.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}

@ -161,8 +161,7 @@ public class DbEntity {
List<String> values = new ArrayList<>();
for (Field field : fields) {
field.setAccessible(true);
Ignore ignore = field.getAnnotation(Ignore.class);
if (ignore != null && ignore.value()) {
if (SqlHelper.ignoreField(field)) {
continue;
}
where.add(field.getName());

@ -511,7 +511,7 @@ final class SqlHelper extends SQLiteOpenHelper {
* @return true 忽略该字段
*/
static boolean ignoreField(Field field) {
// field.isSynthetic(), 使用as热启动App时,AS会自动给你的clss添加change字段
// field.isSynthetic(), 使用as热启动App时,AS会自动给你的class添加change字段
Ignore ignore = field.getAnnotation(Ignore.class);
int modifiers = field.getModifiers();
return (ignore != null && ignore.value())

@ -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";

@ -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 优化代码结构,增加优先下载任务功能。

@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.2'
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.arialyy.simple"

@ -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>

@ -5,6 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.2.2'
// classpath 'com.novoda:bintray-release:0.5.0'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
@ -37,7 +38,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'

@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 KiB

Loading…
Cancel
Save