pull/330/head
AriaLyy 8 years ago
parent 603a21fe43
commit 266c714535
  1. 52
      Aria/build.gradle
  2. 12
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. 14
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  4. 16
      AriaAnnotations/build.gradle
  5. 14
      AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java
  6. 12
      AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java
  7. 17
      AriaCompiler/build.gradle
  8. 4
      app/src/main/assets/aria_config.xml
  9. 36
      app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
  10. 18
      app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java
  11. 21
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  12. 56
      app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
  13. 7
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  14. 6
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  15. 27
      app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java
  16. 7
      app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
  17. 0
      aria/src/main/AndroidManifest.xml
  18. 0
      aria/src/main/java/com/arialyy/aria/core/Configuration.java
  19. 0
      aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java
  20. 0
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  21. 0
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java
  22. 0
      aria/src/main/java/com/arialyy/aria/exception/FileException.java
  23. 26
      build.gradle
  24. 0
      cache/build/mPro.properties
  25. 2
      gradle/wrapper/gradle-wrapper.properties

@ -1,4 +1,5 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'bintray-release'
android { android {
compileSdkVersion 23 compileSdkVersion 23
@ -22,6 +23,53 @@ 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')
} }
apply from: 'jcenter.gradle' //apply from: 'jcenter.gradle'
// Jar
task androidJar(type: Jar) {
dependsOn assemble
group 'Build'
description 'blah blah'
from zipTree(
'build/intermediates/bundles/release/classes.jar')
from zipTree(
'../AriaCompiler/build/libs/AriaCompiler.jar')
from zipTree(
'../AriaAnnotation/build/libs/AriaAnnotation.jar')
}
// javadoc tasks
android.libraryVariants.all { variant ->
task("javadoc${variant.name.capitalize()}", type: Javadoc) {
description "Generates Javadoc for $variant.name."
group 'Docs'
source = variant.javaCompile.source
source "../AriaAnnotation/src/main/java"
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
publish {
artifactId = 'Aria'
userOrg = rootProject.userOrg
groupId = rootProject.groupId
uploadName = rootProject.uploadName
publishVersion = rootProject.publishVersion
description = rootProject.description
website = rootProject.website
licences = rootProject.licences
}
//task copyJar(type: Copy) {
// from('build/libs/permission-lib.jar')
// into('../output/')
// rename ('permission-lib.jar', 'mpermissions.jar')
//}

@ -62,8 +62,11 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
/** /**
* 添加调度器回调 * 添加调度器回调
*
* @see #register()
*/ */
public DownloadReceiver addSchedulerListener(ISchedulerListener<DownloadTask> listener) { @Deprecated public DownloadReceiver addSchedulerListener(
ISchedulerListener<DownloadTask> listener) {
this.listener = listener; this.listener = listener;
DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener); DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener);
return this; return this;
@ -80,15 +83,16 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
/** /**
* 取消注册 * 取消注册
*/ */
@Override @Override public void unRegister() {
public void unRegister() {
DownloadSchedulers.getInstance().unRegister(obj); DownloadSchedulers.getInstance().unRegister(obj);
} }
/** /**
* 移除回调 * 移除回调
*
* @see #unRegister()
*/ */
@Override public void removeSchedulerListener() { @Deprecated @Override public void removeSchedulerListener() {
if (listener != null) { if (listener != null) {
DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener); DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener);
} }

@ -26,7 +26,6 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.compiler.ProxyConstance;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -39,6 +38,16 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
implements ISchedulers<TASK> { implements ISchedulers<TASK> {
private static final String TAG = "AbsSchedulers"; private static final String TAG = "AbsSchedulers";
/**
* 下载的动态生成的代理类后缀
*/
String DOWNLOAD_PROXY_CLASS_SUFFIX = "$$DownloadListenerProxy";
/**
* 上传的动态生成的代理类后缀
*/
String UPLOAD_PROXY_CLASS_SUFFIX = "$$UploadListenerProxy";
protected QUEUE mQueue; protected QUEUE mQueue;
protected boolean isDownload = true; protected boolean isDownload = true;
@ -97,8 +106,7 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
AbsSchedulerListener<TASK> listener = null; AbsSchedulerListener<TASK> listener = null;
try { try {
Class clazz = Class.forName( Class clazz = Class.forName(
targetName + (isDownload ? ProxyConstance.DOWNLOAD_PROXY_CLASS_SUFFIX targetName + (isDownload ? DOWNLOAD_PROXY_CLASS_SUFFIX : UPLOAD_PROXY_CLASS_SUFFIX));
: ProxyConstance.UPLOAD_PROXY_CLASS_SUFFIX));
listener = (AbsSchedulerListener<TASK>) clazz.newInstance(); listener = (AbsSchedulerListener<TASK>) clazz.newInstance();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.e(TAG, targetName + ",没有Aria的Download或Upload注解方法"); Log.e(TAG, targetName + ",没有Aria的Download或Upload注解方法");

@ -1,12 +1,24 @@
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'bintray-release'
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.encoding = "UTF-8" options.encoding = "UTF-8"
} }
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
}
sourceCompatibility = "1.7" publish {
targetCompatibility = "1.7" artifactId = 'aria-annotations'
userOrg = rootProject.userOrg
groupId = rootProject.groupId
uploadName = rootProject.uploadName
publishVersion = rootProject.publishVersion
description = rootProject.description
website = rootProject.website
licences = rootProject.licences
} }

@ -22,7 +22,16 @@ import java.lang.annotation.Target;
/** /**
* Created by Aria.Lao on 2017/6/6. * Created by Aria.Lao on 2017/6/6.
* 下载注解 * Aria下载事件被注解的方法中参数仅能有一个参数类型为{@link com.arialyy.aria.core.download.DownloadTask}
* <pre>
* <code>
* protected void onPre(DownloadTask task) {
* if (task.getKey().equals(DOWNLOAD_URL)) {
* mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()).sendToTarget();
* }
* }
* </code>
* </pre>
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download {
/** /**
@ -43,9 +52,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume {
} }
/**
* 如果你在方法中添加{@code @Download.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart {
} }

@ -22,7 +22,14 @@ import java.lang.annotation.Target;
/** /**
* Created by lyy on 2017/6/6. * Created by lyy on 2017/6/6.
* Aria下载事件注解 * Aria下载事件被注解的方法中参数仅能有一个参数类型为{@link com.arialyy.aria.core.upload.UploadTask}
* <pre>
* <code>
* protected void onPre(UploadTask task) {
* L.d(TAG, "fileSize = " + task.getConvertFileSize());
* }
* </code>
* </pre>
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Upload { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Upload {
@ -44,9 +51,6 @@ import java.lang.annotation.Target;
//@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume { //@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume {
//} //}
/**
* 如果你在方法中添加{@code @Upload.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart {
} }

@ -1,8 +1,11 @@
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'bintray-release'
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.encoding = "UTF-8" options.encoding = "UTF-8"
} }
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies { dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
@ -10,9 +13,15 @@ dependencies {
compile 'com.google.auto.service:auto-service:1.0-rc2' compile 'com.google.auto.service:auto-service:1.0-rc2'
compile 'com.squareup:javapoet:1.9.0' compile 'com.squareup:javapoet:1.9.0'
compile project(':AriaAnnotations') compile project(':AriaAnnotations')
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
} }
publish {
artifactId = 'aria-compiler'
userOrg = rootProject.userOrg
groupId = rootProject.groupId
uploadName = rootProject.uploadName
publishVersion = rootProject.publishVersion
description = rootProject.description
website = rootProject.website
licences = rootProject.licences
}

@ -7,7 +7,7 @@
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效--> <!--设置下载线程,线程下载数改变后,新的下载任务才会生效-->
<threadNum value="4"/> <threadNum value="4"/>
<!--是否打开下载广播,默认为false--> <!--是否打开下载广播,默认为false,不建议使用广播,你可以使用Download注解来实现事件回调-->
<openBroadcast value="false"/> <openBroadcast value="false"/>
<!--设置下载队列最大任务数, 默认为2--> <!--设置下载队列最大任务数, 默认为2-->
@ -37,7 +37,7 @@
</download> </download>
<upload> <upload>
<!--是否打开上传广播,默认为false--> <!--是否打开上传广播,默认为false,不建议使用广播,你可以使用Upload注解来实现事件回调-->
<openBroadcast value="false"/> <openBroadcast value="false"/>
<!--设置上传队列最大任务数, 默认为2--> <!--设置上传队列最大任务数, 默认为2-->

@ -23,6 +23,7 @@ import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import butterknife.OnClick; import butterknife.OnClick;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTarget;
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;
@ -61,7 +62,7 @@ public class DownloadDialog extends AbsDialog {
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); Aria.download(this).register();
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
if (entity != null) { if (entity != null) {
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
@ -89,43 +90,36 @@ public class DownloadDialog extends AbsDialog {
} }
} }
@Override protected void dataCallback(int result, Object obj) { @Download.onTaskPre public void onTaskPre(DownloadTask task) {
}
private void setBtState(boolean startEnable) {
mStart.setEnabled(startEnable);
mCancel.setEnabled(!startEnable);
mStop.setEnabled(!startEnable);
}
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
@Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
setBtState(false); setBtState(false);
} }
@Override public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
setBtState(true); setBtState(true);
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
@Override public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
setBtState(true); setBtState(true);
mPb.setProgress(0); mPb.setProgress(0);
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
@Override public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent()); mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
} }
@Override protected void dataCallback(int result, Object obj) {
}
private void setBtState(boolean startEnable) {
mStart.setEnabled(startEnable);
mCancel.setEnabled(!startEnable);
mStop.setEnabled(!startEnable);
} }
} }

@ -25,6 +25,7 @@ import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import butterknife.OnClick; import butterknife.OnClick;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTarget;
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;
@ -63,7 +64,7 @@ public class DownloadPopupWindow extends AbsPopupWindow {
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); Aria.download(this).register();
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
if (entity != null) { if (entity != null) {
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
@ -101,29 +102,23 @@ public class DownloadPopupWindow extends AbsPopupWindow {
mStop.setEnabled(!startEnable); mStop.setEnabled(!startEnable);
} }
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener { @Download.onTaskPre public void onTaskPre(DownloadTask task) {
@Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
setBtState(false); setBtState(false);
} }
@Override public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
setBtState(true); setBtState(true);
mSpeed.setText("0.0kb/s"); mSpeed.setText("0.0kb/s");
} }
@Override public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
setBtState(true); setBtState(true);
mPb.setProgress(0); mPb.setProgress(0);
mSpeed.setText("0.0kb/s"); mSpeed.setText("0.0kb/s");
} }
@Override public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
long current = task.getCurrentProgress(); long current = task.getCurrentProgress();
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
@ -134,4 +129,3 @@ public class DownloadPopupWindow extends AbsPopupWindow {
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
} }
}

@ -72,15 +72,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Bind(R.id.size) TextView mSize; @Bind(R.id.size) TextView mSize;
@Bind(R.id.speed) TextView mSpeed; @Bind(R.id.speed) TextView mSpeed;
@Bind(R.id.speeds) RadioGroup mRg; @Bind(R.id.speeds) RadioGroup mRg;
private DownloadEntity mEntity;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Aria.ACTION_START)) {
L.d("START");
}
}
};
private Handler mUpdateHandler = new Handler() { private Handler mUpdateHandler = new Handler() {
@Override public void handleMessage(Message msg) { @Override public void handleMessage(Message msg) {
@ -133,6 +124,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
}; };
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Aria.download(this).register();
}
/** /**
* 设置start stop 按钮状态 * 设置start stop 按钮状态
*/ */
@ -141,13 +137,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
mStop.setEnabled(!state); mStop.setEnabled(!state);
} }
@Override protected void onResume() {
super.onResume();
Aria.download(this).register();
//Aria.download(this).addSchedulerListener(new MySchedulerListener());
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
}
@Override public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu); getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);

@ -23,6 +23,7 @@ import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import butterknife.OnClick; import butterknife.OnClick;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTarget;
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;
@ -61,11 +62,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
} else { } else {
setBtState(true); setBtState(true);
} }
} Aria.download(this).register();
@Override public void onResume() {
super.onResume();
Aria.download(this).addSchedulerListener(new DownloadFragment.MyDialogDownloadCallback());
} }
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) { @OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
@ -85,47 +82,23 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
} }
} }
@Override protected void onDelayLoad() { @Download.onTaskPre public void onTaskPre(DownloadTask task) {
}
@Override protected int setLayoutId() {
return R.layout.fragment_download;
}
@Override protected void dataCallback(int result, Object obj) {
}
private void setBtState(boolean startEnable) {
mStart.setEnabled(startEnable);
mCancel.setEnabled(!startEnable);
mStop.setEnabled(!startEnable);
}
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
@Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
setBtState(false); setBtState(false);
} }
@Override public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
setBtState(true); setBtState(true);
mSpeed.setText("0.0kb/s"); mSpeed.setText("0.0kb/s");
} }
@Override public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
setBtState(true); setBtState(true);
mPb.setProgress(0); mPb.setProgress(0);
mSpeed.setText("0.0kb/s"); mSpeed.setText("0.0kb/s");
} }
@Override public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
long current = task.getCurrentProgress(); long current = task.getCurrentProgress();
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
@ -135,5 +108,22 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
} }
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
@Override protected void onDelayLoad() {
}
@Override protected int setLayoutId() {
return R.layout.fragment_download;
}
@Override protected void dataCallback(int result, Object obj) {
}
private void setBtState(boolean startEnable) {
mStart.setEnabled(startEnable);
mCancel.setEnabled(!startEnable);
mStop.setEnabled(!startEnable);
} }
} }

@ -47,6 +47,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
Aria.download(this).register();
setTitle("下载列表"); setTitle("下载列表");
List<DownloadEntity> temps = Aria.download(this).getTaskList(); List<DownloadEntity> temps = Aria.download(this).getTaskList();
if (temps != null && !temps.isEmpty()) { if (temps != null && !temps.isEmpty()) {
@ -57,12 +58,6 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
mList.setAdapter(mAdapter); mList.setAdapter(mAdapter);
} }
@Override protected void onResume() {
super.onResume();
//Aria.download(this).addSchedulerListener(new MySchedulerListener());
Aria.download(this).register();
}
@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());

@ -50,6 +50,7 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
Aria.download(this).register();
setTitle("多任务下载"); setTitle("多任务下载");
mData.addAll(getModule(DownloadModule.class).createMultiTestList()); mData.addAll(getModule(DownloadModule.class).createMultiTestList());
mAdapter = new FileListAdapter(this, mData); mAdapter = new FileListAdapter(this, mData);
@ -72,11 +73,6 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
} }
} }
@Override protected void onResume() {
super.onResume();
Aria.download(this).register();
}
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), false); mAdapter.updateBtState(task.getKey(), false);
} }

@ -20,6 +20,7 @@ import android.content.Intent;
import android.os.Environment; import android.os.Environment;
import android.os.IBinder; import android.os.IBinder;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
@ -45,7 +46,7 @@ public class DownloadService extends Service {
@Override public void onCreate() { @Override public void onCreate() {
super.onCreate(); super.onCreate();
mNotify = new DownloadNotification(getApplicationContext()); mNotify = new DownloadNotification(getApplicationContext());
Aria.download(this).addSchedulerListener(new MySchedulerListener()); Aria.download(this).register();
Aria.download(this) Aria.download(this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk")
@ -54,45 +55,37 @@ public class DownloadService extends Service {
@Override public void onDestroy() { @Override public void onDestroy() {
super.onDestroy(); super.onDestroy();
Aria.download(this).removeSchedulerListener(); Aria.download(this).unRegister();
} }
private class MySchedulerListener extends Aria.DownloadSchedulerListener { @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {
@Override public void onNoSupportBreakPoint(DownloadTask task) {
super.onNoSupportBreakPoint(task);
T.showShort(getApplicationContext(), "该下载链接不支持断点"); T.showShort(getApplicationContext(), "该下载链接不支持断点");
} }
@Override public void onTaskStart(DownloadTask task) { @Download.onTaskStart public void onTaskStart(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载");
} }
@Override public void onTaskResume(DownloadTask task) { @Download.onTaskStop public void onTaskStop(DownloadTask task) {
super.onTaskResume(task);
}
@Override public void onTaskStop(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载");
} }
@Override public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载");
} }
@Override public void onTaskFail(DownloadTask task) { @Download.onTaskFail public void onTaskFail(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败");
} }
@Override public void onTaskComplete(DownloadTask task) { @Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成");
mNotify.upload(100); mNotify.upload(100);
} }
@Override public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
long len = task.getFileSize(); long len = task.getFileSize();
int p = (int) (task.getCurrentProgress() * 100 / len); int p = (int) (task.getCurrentProgress() * 100 / len);
mNotify.upload(p); mNotify.upload(p);
} }
} }
}

@ -79,6 +79,7 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
Aria.upload(this).register();
} }
@OnClick(R.id.upload) void upload() { @OnClick(R.id.upload) void upload() {
@ -97,12 +98,6 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
Aria.upload(this).load(FILE_PATH).cancel(); Aria.upload(this).load(FILE_PATH).cancel();
} }
@Override protected void onResume() {
super.onResume();
//Aria.upload(this).addSchedulerListener(new UploadListener(mHandler));
Aria.upload(this).register();
}
@Upload.onPre public void onPre(UploadTask task) { @Upload.onPre public void onPre(UploadTask task) {
} }

@ -1,5 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@ -7,9 +6,9 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' classpath 'com.novoda:bintray-release:0.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' // 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
// in the individual module build.gradle files // in the individual module build.gradle files
} }
@ -20,8 +19,27 @@ allprojects {
jcenter() jcenter()
mavenCentral() mavenCentral()
} }
tasks.withType(Javadoc) {
options {
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
} }
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
uploadName = 'AriaPre'
publishVersion = '0.0.1'
repoName='maven'
desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria'
licences = ['Apache-2.0']
}

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

Loading…
Cancel
Save