From 88456ebccc6965b9570ecebf9e38e89b30d55d8d Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@QQ.com> Date: Mon, 5 Jun 2017 21:28:52 +0800 Subject: [PATCH 1/5] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git commit –m 'readme修改 :blush:' --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6421c676..fbe030ce 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Aria有以下特点: - [一句代码加可以获取当前的下载速度](#常用接口) - [一句代码就可以动态设置最大下载数](#代码中设置参数) - [通过修改配置文件很容易就能修改下载线程数](#配置文件设置参数) + - [优先下载某一个任务](#常用接口) + 支持https地址下载 - 在配置文件中很容易就可以设置CA证书的信息 + 支持300、301、302重定向下载链接下载 From 7f0f1e71b8d0bf1cb230d74a3e2d1d736b05193c Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@QQ.com> Date: Mon, 5 Jun 2017 21:30:15 +0800 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fbe030ce..7cee8fa6 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority( *** ## 后续版本开发规划 -* ~~下载任务可以设置优先级~~ +* ~~http、scoket断点上传~~ * ~~实现上传队列调度功能~~ From b95ab29466895d966da5e62dcbec08d296dbf8d3 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Fri, 9 Jun 2017 20:45:29 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20https://github.com/Ari?= =?UTF-8?q?aLyy/Aria/issues/33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arialyy/aria/core/download/DownloadTask.java | 16 +++++++++------- README.md | 3 ++- .../simple/download/SingleTaskActivity.java | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 97bd7917..0ac71387 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -133,17 +133,19 @@ public class DownloadTask extends AbsTask { */ @Override public void cancel() { if (!mEntity.isDownloadComplete()) { + if (!mUtil.isDownloading()) { + if (mOutHandler != null) { + mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget(); + } + //发送取消下载的广播 + Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL); + intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity); + mContext.sendBroadcast(intent); + } mUtil.cancelDownload(); mUtil.delConfigFile(); mUtil.delTempFile(); mEntity.deleteData(); - if (mOutHandler != null) { - mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget(); - } - //发送取消下载的广播 - Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL); - intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity); - mContext.sendBroadcast(intent); } } diff --git a/README.md b/README.md index 6421c676..4556cf1b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Aria怎样使用? ## 下载 [![Download](https://api.bintray.com/packages/arialyy/maven/Aria/images/download.svg)](https://bintray.com/arialyy/maven/Aria/_latestVersion)
```java -compile 'com.arialyy.aria:Aria:3.1.5' +compile 'com.arialyy.aria:Aria:3.1.6' ``` ## 示例 @@ -277,6 +277,7 @@ Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority( ## 开发日志 + + v_3.1.6 [取消任务时onTaskCancel回调两次的bug](https://github.com/AriaLyy/Aria/issues/33) + v_3.1.5 优化代码结构,增加优先下载任务功能。 + v_3.1.4 修复快速切换,暂停、恢复功能时,概率性出现的重新下载问题,添加onPre()回调,onPre()用于请求地址之前执行界面UI更新操作。 + v_3.1.0 添加Aria配置文件,优化代码 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 dfe71692..7f8849e7 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -241,6 +241,7 @@ public class SingleTaskActivity extends BaseActivity { @Override public void onTaskCancel(DownloadTask task) { if (task.getKey().equals(DOWNLOAD_URL)) { mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL); + L.d(TAG, "task__cancel"); } } From 854489851c6fc20c67e02dbb599ca502c4a66a34 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@QQ.com> Date: Mon, 12 Jun 2017 20:04:55 +0800 Subject: [PATCH 4/5] Create README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c5327ee..94f0536b 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ compile 'com.arialyy.aria:Aria:3.1.6' ```java @Override protected void onResume() { super.onResume(); - Aria.whit(this).addSchedulerListener(new MySchedulerListener()); + Aria.download(this).addSchedulerListener(new MySchedulerListener()); } ``` From f1d72e1651b0dc0687b14f9de7b99206465c7291 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 13 Jun 2017 17:14:45 +0800 Subject: [PATCH 5/5] merge v_3.0 --- Aria/build.gradle | 58 +++- .../main/java/com/arialyy/aria/core/Aria.java | 13 +- .../com/arialyy/aria/core/AriaManager.java | 3 + .../com/arialyy/aria/core/ConfigHelper.java | 13 + .../com/arialyy/aria/core/Configuration.java | 20 ++ .../aria/core/download/ConnectionHelp.java | 26 +- .../aria/core/download/DownloadReceiver.java | 36 ++- .../aria/core/download/DownloadTask.java | 23 ++ .../aria/core/download/DownloadUtil.java | 11 +- .../aria/core/download/IDownloadUtil.java | 5 + .../aria/core/download/SingleThreadTask.java | 29 +- .../com/arialyy/aria/core/inf/AbsTarget.java | 10 + .../com/arialyy/aria/core/inf/IReceiver.java | 5 + .../aria/core/queue/DownloadTaskQueue.java | 9 + .../core/scheduler/AbsSchedulerListener.java | 67 +++++ .../aria/core/scheduler/AbsSchedulers.java | 79 ++++- .../core/scheduler/DownloadSchedulers.java | 1 + .../aria/core/scheduler/ISchedulers.java | 14 + .../aria/core/scheduler/UploadSchedulers.java | 1 + .../aria/core/upload/UploadReceiver.java | 15 + .../aria/core/upload/UploadTaskEntity.java | 2 +- .../com/arialyy/aria/util/CommonUtil.java | 31 ++ AriaAnnotations/.gitignore | 1 + AriaAnnotations/build.gradle | 25 ++ .../com/arialyy/annotations/Download.java | 96 ++++++ .../java/com/arialyy/annotations/Upload.java | 95 ++++++ AriaCompiler/.gitignore | 1 + AriaCompiler/build.gradle | 28 ++ .../com/arialyy/compiler/AriaProcessor.java | 80 +++++ .../com/arialyy/compiler/ElementHandle.java | 279 ++++++++++++++++++ .../java/com/arialyy/compiler/PrintLog.java | 70 +++++ .../com/arialyy/compiler/ProxyConstance.java | 38 +++ .../com/arialyy/compiler/ProxyEntity.java | 32 ++ README.md | 111 ++++--- app/build.gradle | 10 +- app/src/main/assets/aria_config.xml | 4 +- .../simple/base/adapter/AbsHolder.java | 48 +++ .../simple/base/adapter/AbsRVAdapter.java | 72 +++++ .../base/adapter/RvItemClickSupport.java | 204 +++++++++++++ .../simple/download/DownloadDialog.java | 54 ++-- .../simple/download/DownloadPopupWindow.java | 50 ++-- .../simple/download/SingleTaskActivity.java | 126 ++++++-- .../fragment_download/DownloadFragment.java | 68 ++--- .../multi_download/DownloadAdapter.java | 4 +- .../multi_download/FileListAdapter.java | 4 +- .../multi_download/MultiDownloadActivity.java | 67 ++--- .../multi_download/MultiTaskActivity.java | 55 ++-- .../service_download/DownloadService.java | 59 ++-- .../arialyy/simple/upload/UploadActivity.java | 58 ++-- .../res/menu/menu_single_task_activity.xml | 22 ++ app/src/main/res/values/ids.xml | 19 ++ build.gradle | 51 +++- cache/build/mPro.properties | 0 gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- 55 files changed, 1966 insertions(+), 340 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java create mode 100644 AriaAnnotations/.gitignore create mode 100644 AriaAnnotations/build.gradle create mode 100644 AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java create mode 100644 AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java create mode 100644 AriaCompiler/.gitignore create mode 100644 AriaCompiler/build.gradle create mode 100644 AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java create mode 100644 AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java create mode 100644 AriaCompiler/src/main/java/com/arialyy/compiler/PrintLog.java create mode 100644 AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java create mode 100644 AriaCompiler/src/main/java/com/arialyy/compiler/ProxyEntity.java create mode 100644 app/src/main/java/com/arialyy/simple/base/adapter/AbsHolder.java create mode 100644 app/src/main/java/com/arialyy/simple/base/adapter/AbsRVAdapter.java create mode 100644 app/src/main/java/com/arialyy/simple/base/adapter/RvItemClickSupport.java create mode 100644 app/src/main/res/values/ids.xml delete mode 100644 cache/build/mPro.properties diff --git a/Aria/build.gradle b/Aria/build.gradle index 77eb5fd4..32dbc8b6 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'bintray-release' android { compileSdkVersion 23 @@ -7,8 +8,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 23 - versionCode 315 - versionName "3.1.5" + versionCode 317 + versionName "3.1.7" } buildTypes { release { @@ -19,8 +20,57 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + 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') } -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-core' + userOrg = rootProject.userOrg + groupId = rootProject.groupId +// uploadName = rootProject.uploadName + uploadName = 'AriaApi' + 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') +//} 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 f4cfd252..27e19d2e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java @@ -26,6 +26,8 @@ import android.app.Service; import android.content.Context; import android.os.Build; import android.widget.PopupWindow; +import com.arialyy.annotations.Download; +import com.arialyy.annotations.Upload; import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.scheduler.IDownloadSchedulerListener; import com.arialyy.aria.core.scheduler.ISchedulerListener; @@ -171,8 +173,12 @@ import com.arialyy.aria.core.upload.UploadTask; /** * 上传任务状态监听 + * + * @see Upload + * @deprecated 请使用注解函数的方式来实现事件的获取 */ - public static class UploadSchedulerListener implements ISchedulerListener { + @Deprecated public static class UploadSchedulerListener + implements ISchedulerListener { /** * 预处理,有时有些地址链接比较慢,这时可以先在这个地方出来一些界面上的UI,如按钮的状态。 @@ -218,8 +224,11 @@ import com.arialyy.aria.core.upload.UploadTask; /** * 下载任务状态监听 + * + * @see Download + * @deprecated 请使用注解函数的方式来实现事件的获取 */ - public static class DownloadSchedulerListener + @Deprecated public static class DownloadSchedulerListener implements IDownloadSchedulerListener { /** * 预处理,有时有些地址链接比较慢,这时可以先在这个地方出来一些界面上的UI,如按钮的状态。 diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 7c14afa0..dacb0aea 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -176,11 +176,13 @@ import org.xml.sax.SAXException; if (isDownload) { DownloadReceiver dReceiver = new DownloadReceiver(); dReceiver.targetName = obj.getClass().getName(); + dReceiver.obj = obj; mReceivers.put(key, dReceiver); receiver = dReceiver; } else { UploadReceiver uReceiver = new UploadReceiver(); uReceiver.targetName = obj.getClass().getName(); + uReceiver.obj = obj; mReceivers.put(key, uReceiver); receiver = uReceiver; } @@ -303,6 +305,7 @@ import org.xml.sax.SAXException; if (key.contains(clsName)) { IReceiver receiver = mReceivers.get(key); receiver.removeSchedulerListener(); + receiver.unRegister(); receiver.destroy(); iter.remove(); break; diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java index 191101a2..e4c94262 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -83,10 +83,23 @@ class ConfigHelper extends DefaultHandler { case "convertSpeed": loadConvertSpeed(value); break; + case "maxSpeed": + loadMaxSpeed(value); + break; } } } + private void loadMaxSpeed(String value) { + double maxSpeed = 0.0; + if (!TextUtils.isEmpty(value)) { + maxSpeed = Double.parseDouble(value); + } + if (isDownloadConfig){ + mDownloadConfig.msxSpeed = maxSpeed; + } + } + private void loadConvertSpeed(String value) { boolean open = Boolean.parseBoolean(value); if (isDownloadConfig) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/Configuration.java b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java index 02d9ea17..1745ecc9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core; +import android.text.TextUtils; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.util.CommonUtil; import java.io.File; @@ -171,6 +172,9 @@ class Configuration { } else if (type == float.class || type == Float.class) { field.setFloat(this, Float.parseFloat(value)); } else if (type == double.class || type == Double.class) { + if (TextUtils.isEmpty(value)){ + value = "0.0"; + } field.setDouble(this, Double.parseDouble(value)); } else if (type == long.class || type == Long.class) { field.setLong(this, Long.parseLong(value)); @@ -235,10 +239,26 @@ class Configuration { */ int threadNum = 3; + /** + * 设置最大下载速度,单位:kb, 为0表示不限速 + */ + double msxSpeed = 0.0; + public int getIOTimeOut() { return iOTimeOut; } + public double getMsxSpeed() { + return msxSpeed; + } + + public DownloadConfig setMsxSpeed(double msxSpeed) { + this.msxSpeed = msxSpeed; + saveKey("msxSpeed", String.valueOf(msxSpeed)); + DownloadTaskQueue.getInstance().setMaxSpeed(msxSpeed); + return this; + } + public DownloadConfig setIOTimeOut(int iOTimeOut) { this.iOTimeOut = iOTimeOut; saveKey("iOTimeOut", iOTimeOut + ""); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java index efbc17a4..dd3efc4d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java @@ -71,9 +71,29 @@ class ConnectionHelp { } conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("User-Agent", - "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"); - conn.setRequestProperty("Accept", - "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"); + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); + StringBuilder accept = new StringBuilder(); + accept.append("image/gif, ") + .append("image/jpeg, ") + .append("image/pjpeg, ") + .append("image/webp, ") + .append("image/*, ") + .append("application/xml") + .append("application/xaml+xml, ") + .append("application/xhtml+xml, ") + .append("application/x-shockwave-flash, ") + .append("application/x-ms-xbap, ") + .append("application/x-ms-application, ") + .append("application/msword, ") + .append("application/vnd.ms-excel, ") + .append("application/vnd.ms-xpsdocument, ") + .append("application/vnd.ms-powerpoint, ") + .append("text/plain, ") + .append("text/html, ") + .append("*/*"); + conn.setRequestProperty("Accept", accept.toString()); + conn.setRequestProperty("Accept-Encoding", "identity"); + conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Connection", "Keep-Alive"); //302获取重定向地址 conn.setInstanceFollowRedirects(false); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index d52a18af..d315e9b0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -36,8 +36,19 @@ import java.util.Set; public class DownloadReceiver implements IReceiver { private static final String TAG = "DownloadReceiver"; public String targetName; + public Object obj; public ISchedulerListener listener; + /** + * 设置最大下载速度,单位:kb + * 该方法为实验性功能,清不要轻易在生产环境中使用。 + * + * @param maxSpeed 为0表示不限速 + */ + @Deprecated public void setMaxSpeed(double maxSpeed) { + AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMsxSpeed(maxSpeed); + } + /** * {@link #load(String)},请使用该方法 */ @@ -61,17 +72,37 @@ public class DownloadReceiver implements IReceiver { /** * 添加调度器回调 + * + * @see #register() */ - public DownloadReceiver addSchedulerListener(ISchedulerListener listener) { + @Deprecated public DownloadReceiver addSchedulerListener( + ISchedulerListener listener) { this.listener = listener; DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener); return this; } + /** + * 将当前类注册到Aria + */ + public DownloadReceiver register() { + DownloadSchedulers.getInstance().register(obj); + return this; + } + + /** + * 取消注册 + */ + @Override public void unRegister() { + DownloadSchedulers.getInstance().unRegister(obj); + } + /** * 移除回调 + * + * @see #unRegister() */ - @Override public void removeSchedulerListener() { + @Deprecated @Override public void removeSchedulerListener() { if (listener != null) { DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener); } @@ -133,6 +164,7 @@ public class DownloadReceiver implements IReceiver { for (String key : keys) { IReceiver receiver = ariaManager.getReceiver().get(key); receiver.removeSchedulerListener(); + receiver.unRegister(); ariaManager.getReceiver().remove(key); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 0ac71387..f72d68b2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -28,6 +28,7 @@ import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; +import java.io.File; import java.lang.ref.WeakReference; /** @@ -50,6 +51,19 @@ public class DownloadTask extends AbsTask { mUtil = new DownloadUtil(mContext, taskEntity, mListener); } + /** + * 获取文件保存路径 + * + * @return 如果路径不存在,返回null + */ + public String getDownloadPath() { + File file = new File(mEntity.getDownloadPath()); + if (!file.exists()) { + return null; + } + return mEntity.getDownloadPath(); + } + /** * 获取当前下载任务的下载地址 * @@ -88,6 +102,15 @@ public class DownloadTask extends AbsTask { stop(true); } + /** + * 设置最大下载速度,单位:kb + * + * @param maxSpeed 为0表示不限速 + */ + public void setMaxSpeed(double maxSpeed) { + mUtil.setMaxSpeed(maxSpeed); + } + /** * 开始下载 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java index 0dfda502..943294c7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java @@ -107,6 +107,15 @@ class DownloadUtil implements IDownloadUtil, Runnable { return CONSTANCE.isDownloading; } + public void setMaxSpeed(double maxSpeed) { + for (int i = 0; i < THREAD_NUM; i++) { + SingleThreadTask task = (SingleThreadTask) mTask.get(i); + if (task != null) { + task.setMaxSpeed(maxSpeed); + } + } + } + /** * 取消下载 */ @@ -323,7 +332,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { rl++; } if (i == (THREAD_NUM - 1)) { - //如果整个文件的大小不为线程个数的整数倍,则最后一个线程的结束位置即为文件的总长度 + //最后一个线程的结束位置即为文件的总长度 endL = fileLength; } addSingleTask(i, startL, endL, fileLength); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java index 5c0ba1cd..471d0048 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java @@ -63,4 +63,9 @@ interface IDownloadUtil { * 删除temp文件 */ public void delTempFile(); + + /** + * 设置最大下载速度 + */ + public void setMaxSpeed(double maxSpeed); } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java index 973a956f..c4dc1b65 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.download; +import android.os.Build; import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.AriaManager; @@ -23,10 +24,13 @@ import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashSet; import java.util.Properties; +import java.util.Set; /** * Created by lyy on 2017/1/18. @@ -41,6 +45,11 @@ final class SingleThreadTask implements Runnable { 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, DownloadUtil.ConfigEntity downloadInfo) { AriaManager manager = AriaManager.getInstance(AriaManager.APP); @@ -53,6 +62,22 @@ final class SingleThreadTask implements Runnable { mConfigFPath = downloadInfo.CONFIG_FILE_PATH; } mBufSize = manager.getDownloadConfig().getBuffSize(); + setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed()); + } + + void setMaxSpeed(double maxSpeed) { + if (-0.9999 < maxSpeed && maxSpeed < 0.00001) { + mSleepTime = 0; + } else { + BigDecimal db = new BigDecimal( + ((mBufSize / 1024) * (filterVersion() ? 1 : CONSTANCE.THREAD_NUM) / maxSpeed) * 1000); + db.setScale(0, BigDecimal.ROUND_HALF_UP); + mSleepTime = db.longValue(); + } + } + + private boolean filterVersion() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; } @Override public void run() { @@ -73,7 +98,7 @@ final class SingleThreadTask implements Runnable { + "】"); //在头里面请求下载开始位置和结束位置 conn.setRequestProperty("Range", - "bytes=" + mConfigEntity.START_LOCATION + "-" + mConfigEntity.END_LOCATION); + "bytes=" + mConfigEntity.START_LOCATION + "-" + (mConfigEntity.END_LOCATION - 1)); } else { Log.w(TAG, "该下载不支持断点"); } @@ -97,7 +122,7 @@ final class SingleThreadTask implements Runnable { if (CONSTANCE.isStop) { break; } - //把下载数据数据写入文件 + Thread.sleep(mSleepTime); file.write(buffer, 0, len); progress(len); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index 7edcb91e..66e03cfb 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -38,6 +38,16 @@ public abstract class AbsTarget { */ public void removeSchedulerListener(); + /** + * 移除观察者 + */ + public void unRegister(); + /** * 停止所有任务 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index 1dfe99de..4140433a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -91,6 +91,15 @@ public class DownloadTaskQueue } } + public void setMaxSpeed(double maxSpeed){ + Map tasks = mExecutePool.getAllTask(); + Set keys = tasks.keySet(); + for (String key : keys){ + DownloadTask task = tasks.get(key); + task.setMaxSpeed(maxSpeed); + } + } + @Override public void setMaxTaskNum(int downloadNum) { int oldMaxSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum; int diff = downloadNum - oldMaxSize; diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java new file mode 100644 index 00000000..ae411967 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.scheduler; + +import com.arialyy.aria.core.inf.ITask; + +/** + * Created by Aria.Lao on 2017/6/7. + */ +public class AbsSchedulerListener implements ISchedulerListener { + @Override public void onPre(TASK task) { + + } + + @Override public void onTaskPre(TASK task) { + + } + + @Override public void onTaskResume(TASK task) { + + } + + @Override public void onTaskStart(TASK task) { + + } + + @Override public void onTaskStop(TASK task) { + + } + + @Override public void onTaskCancel(TASK task) { + + } + + @Override public void onTaskFail(TASK task) { + + } + + @Override public void onTaskComplete(TASK task) { + + } + + @Override public void onTaskRunning(TASK task) { + + } + + public void onNoSupportBreakPoint(TASK task) { + + } + + public void setListener(Object obj) { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 4fee513f..4356d8a9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -32,21 +32,43 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** - * Created by AriaL on 2017/6/4. + * Created by lyy on 2017/6/4. */ public abstract class AbsSchedulers, QUEUE extends ITaskQueue> implements ISchedulers { private static final String TAG = "AbsSchedulers"; + /** + * 下载的动态生成的代理类后缀 + */ + String DOWNLOAD_PROXY_CLASS_SUFFIX = "$$DownloadListenerProxy"; + + /** + * 上传的动态生成的代理类后缀 + */ + String UPLOAD_PROXY_CLASS_SUFFIX = "$$UploadListenerProxy"; + protected QUEUE mQueue; + protected boolean isDownload = true; private Map> mSchedulerListeners = new ConcurrentHashMap<>(); - @Override - public void addSchedulerListener(String targetName, ISchedulerListener schedulerListener) { + private Map> mObservers = new ConcurrentHashMap<>(); + + /** + * @param targetName 观察者,创建该监听器的对象类名 + * @param schedulerListener {@link ISchedulerListener} + * @see #register(Object) + */ + @Deprecated @Override public void addSchedulerListener(String targetName, + ISchedulerListener schedulerListener) { mSchedulerListeners.put(targetName, schedulerListener); } + /** + * @param targetName 观察者,创建该监听器的对象类名 + * @see #unRegister(Object) + */ @Override public void removeSchedulerListener(String targetName, ISchedulerListener schedulerListener) { //该内存泄露解决方案:http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element @@ -57,6 +79,52 @@ public abstract class AbsSchedulers listener = mObservers.get(targetName); + if (listener == null) { + listener = createListener(targetName); + if (listener != null) { + listener.setListener(obj); + mObservers.put(targetName, listener); + } else { + Log.e(TAG, "注册错误,没有【" + targetName + "】观察者"); + } + } + } + + @Override public void unRegister(Object obj) { + for (Iterator>> iter = + mObservers.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry> entry = iter.next(); + if (entry.getKey().equals(obj.getClass().getName())) iter.remove(); + } + } + + /** + * 创建代理类 + * + * @param targetName 通过观察者创建对应的Aria事件代理 + */ + private AbsSchedulerListener createListener(String targetName) { + AbsSchedulerListener listener = null; + try { + Class clazz = Class.forName( + targetName + (isDownload ? DOWNLOAD_PROXY_CLASS_SUFFIX : UPLOAD_PROXY_CLASS_SUFFIX)); + listener = (AbsSchedulerListener) clazz.newInstance(); + } catch (ClassNotFoundException e) { + Log.e(TAG, targetName + ",没有Aria的Download或Upload注解方法"); + //e.printStackTrace(); + } catch (InstantiationException e) { + Log.e(TAG, e.getMessage()); + //e.printStackTrace(); + } catch (IllegalAccessException e) { + Log.e(TAG, e.getMessage()); + //e.printStackTrace(); + } + return listener; + } + @Override public boolean handleMessage(Message msg) { TASK task = (TASK) msg.obj; if (task == null) { @@ -100,6 +168,11 @@ public abstract class AbsSchedulers 0) { + Set keys = mObservers.keySet(); + for (String key : keys) { + callback(state, task, mObservers.get(key)); + } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java index ed8731bb..f6137abf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java @@ -34,6 +34,7 @@ public class DownloadSchedulers private DownloadSchedulers() { mQueue = DownloadTaskQueue.getInstance(); + isDownload = true; } public static DownloadSchedulers getInstance() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java index 5a240b7b..7549b55a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java @@ -80,4 +80,18 @@ public interface ISchedulers extends Handler.Callback { */ public void removeSchedulerListener(String targetName, ISchedulerListener schedulerListener); + + /** + * 将当前类注册到Aria + * + * @param obj 观察者类 + */ + public void register(Object obj); + + /** + * 移除注册 + * + * @param obj 观察者类 + */ + public void unRegister(Object obj); } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java index 37a6e3d0..c3dfd361 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java @@ -32,6 +32,7 @@ public class UploadSchedulers private UploadSchedulers() { mQueue = UploadTaskQueue.getInstance(); + isDownload = false; } public static UploadSchedulers getInstance() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java index 98ceff94..38e71953 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java @@ -19,8 +19,10 @@ import android.support.annotation.NonNull; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.CmdFactory; +import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IReceiver; +import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.orm.DbEntity; @@ -38,6 +40,7 @@ import java.util.regex.Pattern; public class UploadReceiver implements IReceiver { private static final String TAG = "DownloadReceiver"; public String targetName; + public Object obj; public ISchedulerListener listener; /** @@ -127,4 +130,16 @@ public class UploadReceiver implements IReceiver { UploadSchedulers.getInstance().removeSchedulerListener(targetName, listener); } } + + /** + * 将当前类注册到Aria + */ + public UploadReceiver register() { + UploadSchedulers.getInstance().register(obj); + return this; + } + + @Override public void unRegister() { + UploadSchedulers.getInstance().unRegister(obj); + } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java index 5da1923e..84ea56f1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java @@ -30,7 +30,7 @@ public class UploadTaskEntity extends AbsTaskEntity { public String contentType = "multipart/form-data"; //上传的文件类型 public String userAgent = "User-Agent"; public String charset = "utf-8"; - + /** * 文件上传表单 */ diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 290930ad..d3a13ba9 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -26,6 +26,7 @@ import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.inf.AbsTaskEntity; import java.io.File; +import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -40,6 +41,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; +import java.util.regex.Pattern; /** * Created by lyy on 2016/1/22. @@ -47,6 +49,35 @@ import java.util.Properties; public class CommonUtil { private static final String TAG = "CommonUtil"; + /** + * 获取CPU核心数 + */ + public static int getNumCores() { + //Private Class to display only CPU devices in the directory listing + class CpuFilter implements FileFilter { + @Override public boolean accept(File pathname) { + //Check if filename is "cpu", followed by a single digit number + return Pattern.matches("cpu[0-9]", pathname.getName()); + } + } + + try { + //Get directory containing CPU info + File dir = new File("/sys/devices/system/cpu/"); + //Filter to only list the devices we care about + File[] files = dir.listFiles(new CpuFilter()); + Log.d(TAG, "CPU Count: " + files.length); + //Return the number of cores (virtual CPU devices) + return files.length; + } catch (Exception e) { + //Print exception + Log.d(TAG, "CPU Count: Failed."); + e.printStackTrace(); + //Default to return 1 core + return 1; + } + } + /** * 通过流创建文件 */ diff --git a/AriaAnnotations/.gitignore b/AriaAnnotations/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/AriaAnnotations/.gitignore @@ -0,0 +1 @@ +/build diff --git a/AriaAnnotations/build.gradle b/AriaAnnotations/build.gradle new file mode 100644 index 00000000..bfdf001c --- /dev/null +++ b/AriaAnnotations/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'java' +apply plugin: 'bintray-release' + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + +sourceCompatibility = JavaVersion.VERSION_1_7 +targetCompatibility = JavaVersion.VERSION_1_7 + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) +} + +publish { + artifactId = 'aria-annotations' + userOrg = rootProject.userOrg + groupId = rootProject.groupId +// uploadName = rootProject.uploadName + uploadName = 'AriaAnnotations' + publishVersion = rootProject.publishVersion + description = rootProject.description + website = rootProject.website + licences = rootProject.licences +} \ No newline at end of file diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java new file mode 100644 index 00000000..b833fda1 --- /dev/null +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Created by Aria.Lao on 2017/6/6. + * Aria下载事件被注解的方法中,参数仅能有一个,参数类型为{@link com.arialyy.aria.core.download.DownloadTask} + *
+ *   
+ *       protected void onPre(DownloadTask task) {
+ *        if (task.getKey().equals(DOWNLOAD_URL)) {
+ *           mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()).sendToTarget();
+ *        }
+ *       }
+ *   
+ * 
+ */ +@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download { + /** + * 如果你在方法中添加{@code @Download.onPre}注解,在预处理完成时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onPre { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskPre}注解,在任务预处理完成时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume { + } + /** + * 如果你在方法中添加{@code @Download.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskStop}注解,在任务停止时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStop { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskCancel { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskFail)注解,在任务预失败时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskFail { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskComplete}注解,在任务完成时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskComplete { + } + + /** + * 如果你在方法中添加{@code @Download.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskRunning { + } + + /** + * 如果你在方法中添加{@code @Download.onNoSupportBreakPoint}注解,如果该任务不支持断点,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) + public @interface onNoSupportBreakPoint { + } +} diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java new file mode 100644 index 00000000..bf1a2cd1 --- /dev/null +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Created by lyy on 2017/6/6. + * Aria下载事件被注解的方法中,参数仅能有一个,参数类型为{@link com.arialyy.aria.core.upload.UploadTask} + *
+ *   
+ *       protected void onPre(UploadTask task) {
+ *        L.d(TAG, "fileSize = " + task.getConvertFileSize());
+ *       }
+ *   
+ * 
+ */ +@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Upload { + + /** + * 如果你在方法中添加{@code @Upload.onPre}注解,在预处理完成时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onPre { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskPre}注解,在任务预处理完成时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 + */ + //@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume { + //} + /** + * 如果你在方法中添加{@code @Upload.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskStop}注解,在任务停止时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStop { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskCancel { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskFail)注解,在任务预失败时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskFail { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskComplete}注解,在任务完成时,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskComplete { + } + + /** + * 如果你在方法中添加{@code @Upload.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskRunning { + } + + /** + * 如果你在方法中添加{@code @Upload.onNoSupportBreakPoint}注解,如果该任务不支持断点,Aria会调用该方法 + */ + @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) + public @interface onNoSupportBreakPoint { + } +} diff --git a/AriaCompiler/.gitignore b/AriaCompiler/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/AriaCompiler/.gitignore @@ -0,0 +1 @@ +/build diff --git a/AriaCompiler/build.gradle b/AriaCompiler/build.gradle new file mode 100644 index 00000000..3e915676 --- /dev/null +++ b/AriaCompiler/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'java' +apply plugin: 'bintray-release' + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} +sourceCompatibility = JavaVersion.VERSION_1_7 +targetCompatibility = JavaVersion.VERSION_1_7 + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.google.auto:auto-common:0.6' + compile 'com.google.auto.service:auto-service:1.0-rc2' + compile 'com.squareup:javapoet:1.9.0' + compile project(':AriaAnnotations') +} + +publish { + artifactId = 'aria-compiler' + userOrg = rootProject.userOrg + groupId = rootProject.groupId +// uploadName = rootProject.uploadName + uploadName = 'AriaCompiler' + publishVersion = rootProject.publishVersion + description = rootProject.description + website = rootProject.website + licences = rootProject.licences +} \ No newline at end of file diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java b/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java new file mode 100644 index 00000000..5ac4a533 --- /dev/null +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.compiler; + +import com.arialyy.annotations.Download; +import com.arialyy.annotations.Upload; +import com.google.auto.service.AutoService; +import java.util.LinkedHashSet; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; + +/** + * Created by lyy on 2017/6/6. + * 事件注解扫描器 + */ +@AutoService(Processor.class) public class AriaProcessor extends AbstractProcessor { + ElementHandle mHandler; + + @Override public synchronized void init(ProcessingEnvironment processingEnv) { + super.init(processingEnv); + PrintLog.init(processingEnv.getMessager()); + mHandler = new ElementHandle(processingEnv.getFiler(), processingEnv.getElementUtils()); + } + + @Override public Set getSupportedAnnotationTypes() { + Set annotataions = new LinkedHashSet<>(); + annotataions.add(Download.onPre.class.getCanonicalName()); + annotataions.add(Download.onNoSupportBreakPoint.class.getCanonicalName()); + annotataions.add(Download.onTaskCancel.class.getCanonicalName()); + annotataions.add(Download.onTaskComplete.class.getCanonicalName()); + annotataions.add(Download.onTaskFail.class.getCanonicalName()); + annotataions.add(Download.onTaskPre.class.getCanonicalName()); + annotataions.add(Download.onTaskResume.class.getCanonicalName()); + annotataions.add(Download.onTaskRunning.class.getCanonicalName()); + annotataions.add(Download.onTaskStart.class.getCanonicalName()); + annotataions.add(Download.onTaskStop.class.getCanonicalName()); + annotataions.add(Upload.onPre.class.getCanonicalName()); + annotataions.add(Upload.onNoSupportBreakPoint.class.getCanonicalName()); + annotataions.add(Upload.onTaskCancel.class.getCanonicalName()); + annotataions.add(Upload.onTaskComplete.class.getCanonicalName()); + annotataions.add(Upload.onTaskFail.class.getCanonicalName()); + annotataions.add(Upload.onTaskPre.class.getCanonicalName()); + //annotataions.add(Upload.onTaskResume.class.getCanonicalName()); + annotataions.add(Upload.onTaskRunning.class.getCanonicalName()); + annotataions.add(Upload.onTaskStart.class.getCanonicalName()); + annotataions.add(Upload.onTaskStop.class.getCanonicalName()); + return annotataions; + } + + @Override public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + mHandler.clean(); + mHandler.handleDownload(roundEnv); + mHandler.handleUpload(roundEnv); + mHandler.createProxyFile(); + return true; + } +} diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java new file mode 100644 index 00000000..3ec58d74 --- /dev/null +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.compiler; + +import com.arialyy.annotations.Download; +import com.arialyy.annotations.Upload; +import com.squareup.javapoet.ClassName; +import com.squareup.javapoet.FieldSpec; +import com.squareup.javapoet.JavaFile; +import com.squareup.javapoet.MethodSpec; +import com.squareup.javapoet.ParameterSpec; +import com.squareup.javapoet.TypeSpec; +import com.squareup.javapoet.ParameterizedTypeName; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.processing.Filer; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.util.Elements; + +/** + * Created by lyy on 2017/6/6. + * 元素处理 + */ +class ElementHandle { + + private Filer mFiler; + private Elements mElementUtil; + private Map mMethods = new HashMap<>(); + + ElementHandle(Filer filer, Elements elements) { + mFiler = filer; + mElementUtil = elements; + } + + /** + * VariableElement 一般代表成员变量 + * ExecutableElement 一般代表类中的方法 + * TypeElement 一般代表代表类 + * PackageElement 一般代表Package + */ + void handleDownload(RoundEnvironment roundEnv) { + saveMethod(true, roundEnv, Download.onNoSupportBreakPoint.class); + saveMethod(true, roundEnv, Download.onPre.class); + saveMethod(true, roundEnv, Download.onTaskCancel.class); + saveMethod(true, roundEnv, Download.onTaskComplete.class); + saveMethod(true, roundEnv, Download.onTaskFail.class); + saveMethod(true, roundEnv, Download.onTaskPre.class); + saveMethod(true, roundEnv, Download.onTaskResume.class); + saveMethod(true, roundEnv, Download.onTaskRunning.class); + saveMethod(true, roundEnv, Download.onTaskStart.class); + saveMethod(true, roundEnv, Download.onTaskStop.class); + } + + void handleUpload(RoundEnvironment roundEnv) { + saveMethod(false, roundEnv, Upload.onNoSupportBreakPoint.class); + saveMethod(false, roundEnv, Upload.onPre.class); + saveMethod(false, roundEnv, Upload.onTaskCancel.class); + saveMethod(false, roundEnv, Upload.onTaskComplete.class); + saveMethod(false, roundEnv, Upload.onTaskFail.class); + saveMethod(false, roundEnv, Upload.onTaskPre.class); + //saveMethod(false, roundEnv, Upload.onTaskResume.class); + saveMethod(false, roundEnv, Upload.onTaskRunning.class); + saveMethod(false, roundEnv, Upload.onTaskStart.class); + saveMethod(false, roundEnv, Upload.onTaskStop.class); + } + + void printMethods() { + //Set keys = mMethods.keySet(); + //for (String key : keys) { + // ProxyEntity entity = mMethods.get(key); + // for (String method : entity.methods) { + // PrintLog.getInstance().info(method); + // } + //} + PrintLog.getInstance().info("size ==> " + mMethods.size()); + } + + /** + * 在build文件夹中生成如下代码的文件 + *
+   *   
+   * package com.arialyy.simple.download;
+   *
+   * import com.arialyy.aria.core.download.DownloadTask;
+   * import com.arialyy.aria.core.scheduler.AbsSchedulerListener;
+   *
+   * public final class SingleTaskActivity$$DownloadListenerProxy extends
+   * AbsSchedulerListener {
+   * private SingleTaskActivity obj;
+   *
+   *    public void onPre(final DownloadTask task) {
+   *      obj.onPre((DownloadTask)task);
+   *    }
+   *
+   *    public void onTaskStart(final DownloadTask task) {
+   *      obj.onStart((DownloadTask)task);
+   *    }
+   *
+   *    public void setListener(final Object obj) {
+   *      this.obj = (SingleTaskActivity)obj;
+   *    }
+   * }
+   *   
+   * 
+ */ + void createProxyFile() { + Set keys = mMethods.keySet(); + try { + for (String key : keys) { + ProxyEntity entity = mMethods.get(key); + JavaFile jf = JavaFile.builder(entity.packageName, createProxyClass(entity)).build(); + + jf.writeTo(mFiler); + // 如果需要在控制台打印生成的文件,则去掉下面的注释 + //jf.writeTo(System.out); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 创建代理方法 + * + * @param isDownload 是否是下载的注解 + * @param annotation {@link Download}、{@link Upload} + * @param methodName 被代理类注解的方法名 + */ + private MethodSpec createProxyMethod(boolean isDownload, Class annotation, + String methodName) { + ClassName task = ClassName.get( + isDownload ? "com.arialyy.aria.core.download" : "com.arialyy.aria.core.upload", + isDownload ? "DownloadTask" : "UploadTask"); + ParameterSpec parameterSpec = + ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build(); + return MethodSpec.methodBuilder(annotation.getSimpleName()) + .addModifiers(Modifier.PUBLIC) + .returns(void.class) + .addParameter(parameterSpec) + .addAnnotation(Override.class) + .addCode("obj." + + methodName + + "(" + + (isDownload ? "(DownloadTask)" : "(UploadTask)") + + "task);\n") + .build(); + } + + /** + * 创建代理类 + */ + private TypeSpec createProxyClass(ProxyEntity entity) { + TypeSpec.Builder builder = TypeSpec.classBuilder( + entity.className + (entity.isDownlaod ? ProxyConstance.DOWNLOAD_PROXY_CLASS_SUFFIX + : ProxyConstance.UPLOAD_PROXY_CLASS_SUFFIX)) + .addModifiers(Modifier.PUBLIC, Modifier.FINAL); + + //添加被代理的类的字段 + ClassName obj = ClassName.get(entity.packageName, entity.className); + FieldSpec observerField = FieldSpec.builder(obj, "obj").addModifiers(Modifier.PRIVATE).build(); + builder.addField(observerField); + + //添加注解方法 + for (Class annotation : entity.methods.keySet()) { + MethodSpec method = + createProxyMethod(entity.isDownlaod, annotation, entity.methods.get(annotation)); + builder.addMethod(method); + } + + //添加设置代理的类 + ParameterSpec parameterSpec = + ParameterSpec.builder(Object.class, "obj").addModifiers(Modifier.FINAL).build(); + MethodSpec listener = MethodSpec.methodBuilder(ProxyConstance.SET_LISTENER) + .addModifiers(Modifier.PUBLIC) + .returns(void.class) + .addParameter(parameterSpec) + .addAnnotation(Override.class) + .addCode("this.obj = (" + entity.className + ")obj;\n") + .build(); + builder.addJavadoc("该文件为Aria自动生成的代理文件,请不要修改该文件的任何代码!\n"); + + //创建父类参数 + ClassName superClass = ClassName.get("com.arialyy.aria.core.scheduler", "AbsSchedulerListener"); + //创建泛型 + ClassName typeVariableName = ClassName.get( + entity.isDownlaod ? "com.arialyy.aria.core.download" : "com.arialyy.aria.core.upload", + entity.isDownlaod ? "DownloadTask" : "UploadTask"); + builder.superclass(ParameterizedTypeName.get(superClass, typeVariableName)); + builder.addMethod(listener); + return builder.build(); + } + + void clean() { + mMethods.clear(); + } + + /** + * 查找并保存扫描到的方法 + */ + private void saveMethod(boolean isDownload, RoundEnvironment roundEnv, + Class annotationClazz) { + for (Element element : roundEnv.getElementsAnnotatedWith(annotationClazz)) { + ElementKind kind = element.getKind(); + if (kind == ElementKind.METHOD) { + ExecutableElement method = (ExecutableElement) element; + TypeElement classElement = (TypeElement) method.getEnclosingElement(); + PackageElement packageElement = mElementUtil.getPackageOf(classElement); + checkDownloadMethod(isDownload, method); + String methodName = method.getSimpleName().toString(); + String className = method.getEnclosingElement().toString(); //全类名 + ProxyEntity proxyEntity = mMethods.get(className); + if (proxyEntity == null) { + proxyEntity = new ProxyEntity(); + proxyEntity.isDownlaod = isDownload; + //proxyEntity.packageName = classElement.getQualifiedName().toString(); + proxyEntity.packageName = packageElement.getQualifiedName().toString(); + proxyEntity.className = classElement.getSimpleName().toString(); + mMethods.put(className, proxyEntity); + } + proxyEntity.methods.put(annotationClazz, methodName); + } + } + } + + /** + * 检查和下载相关的方法,如果被注解的方法为private或参数不合法,则抛异常 + */ + private void checkDownloadMethod(boolean isDownload, ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + String className = method.getEnclosingElement().toString(); + Set modifiers = method.getModifiers(); + if (modifiers.contains(Modifier.PRIVATE)) { + throw new IllegalAccessError(className + "." + methodName + "不能为private方法"); + } + List params = (List) method.getParameters(); + if (params.size() > 1) { + throw new IllegalArgumentException( + className + "." + methodName + "参数错误, 参数只有一个,且参数必须是" + getCheckParams(isDownload)); + } + if (!params.get(0).asType().toString().equals(getCheckParams(isDownload))) { + throw new IllegalArgumentException(className + + "." + + methodName + + "参数【" + + params.get(0).getSimpleName() + + "】类型错误,参数必须是" + + getCheckParams(isDownload)); + } + } + + private String getCheckParams(boolean isDownload) { + return isDownload ? "com.arialyy.aria.core.download.DownloadTask" + : "com.arialyy.aria.core.upload.UploadTask"; + } +} diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/PrintLog.java b/AriaCompiler/src/main/java/com/arialyy/compiler/PrintLog.java new file mode 100644 index 00000000..1350de4b --- /dev/null +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/PrintLog.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.compiler; + +import javax.annotation.processing.Messager; +import javax.lang.model.element.Element; +import javax.tools.Diagnostic; + +/** + * Created by Aria.Lao on 2017/6/6. + */ + +class PrintLog { + + private volatile static PrintLog INSTANCE = null; + private Messager mMessager; + + public static PrintLog init(Messager msg) { + if (INSTANCE == null) { + synchronized (PrintLog.class) { + INSTANCE = new PrintLog(msg); + } + } + return INSTANCE; + } + + public static PrintLog getInstance() { + return INSTANCE; + } + + private PrintLog() { + } + + private PrintLog(Messager msg) { + mMessager = msg; + } + + public void error(Element e, String msg, Object... args) { + mMessager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args), e); + } + + public void error(String msg, Object... args) { + mMessager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args)); + } + + private void warning(String msg) { + mMessager.printMessage(Diagnostic.Kind.WARNING, msg); + } + + public void error(String msg) { + mMessager.printMessage(Diagnostic.Kind.ERROR, msg); + } + + public void info(String str) { + mMessager.printMessage(Diagnostic.Kind.NOTE, str); + } +} diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java new file mode 100644 index 00000000..7e9ac1ea --- /dev/null +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.compiler; + +/** + * Created by lyy on 2017/6/7. + */ + +public interface ProxyConstance { + /** + * 设置观察者的方法 + */ + String SET_LISTENER = "setListener"; + + /** + * 下载的动态生成的代理类后缀 + */ + String DOWNLOAD_PROXY_CLASS_SUFFIX = "$$DownloadListenerProxy"; + + /** + * 上传的动态生成的代理类后缀 + */ + String UPLOAD_PROXY_CLASS_SUFFIX = "$$UploadListenerProxy"; + +} diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyEntity.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyEntity.java new file mode 100644 index 00000000..9c6e9070 --- /dev/null +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyEntity.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.compiler; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Aria.Lao on 2017/6/7. + */ + +class ProxyEntity { + public String packageName; + public String className; + public boolean isDownlaod = true; + + public Map, String> methods = new HashMap<>(); +} diff --git a/README.md b/README.md index 94f0536b..17404c80 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,15 @@ Aria怎样使用? 如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^` ## 下载 -[![Download](https://api.bintray.com/packages/arialyy/maven/Aria/images/download.svg)](https://bintray.com/arialyy/maven/Aria/_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) ```java +<<<<<<< HEAD compile 'com.arialyy.aria:Aria:3.1.6' +======= +compile 'com.arialyy.aria:Aria:3.1.7' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.7' +>>>>>>> v_3.0 ``` ## 示例 @@ -50,7 +56,7 @@ compile 'com.arialyy.aria:Aria:3.1.6' ```java Aria.download(this) .load(DOWNLOAD_URL) - .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径 + .setDownloadPath(DOWNLOAD_PATH) //文件保存路径 .add(); ``` @@ -59,7 +65,7 @@ compile 'com.arialyy.aria:Aria:3.1.6' ```java Aria.download(this) .load(DOWNLOAD_URL) //读取下载地址 - .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //设置文件保存的完整路径 + .setDownloadPath(DOWNLOAD_PATH) //设置文件保存的完整路径 .start(); //启动下载 ``` * 暂停 @@ -80,47 +86,69 @@ compile 'com.arialyy.aria:Aria:3.1.6' ### 下载状态获取 如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。 -* 创建事件类 + +* 将对象注册到Aria + +` Aria.download(this).register();`或`Aria.upload(this).register();` +```java + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Aria.download(this).register(); + } +``` + +* 使用'@Download'或'@Upload'注解你的函数 + + **注意:** + - 注解回掉采用Apt的方式实现,所以,你不需要担心这会影响你机器的性能 + - 被注解的方法**不能被private修饰** + - 被注解的方法**只能有一个参数,并且参数类型必须是`DownloadTask`或`UploadTask`** + - 方法名可以为任意字符串 + +* 除了在widget(Activity、Fragment、Dialog、Popupwindow)中使用注解方法外,你还可以在Service、Notification等组件中使用注解函数。 ```java - final static class MySchedulerListener extends Aria.DownloadSchedulerListener{ - @Override public void onTaskPre(DownloadTask task) { - //通过下载地址可以判断任务是否是你指定的任务 - if (task.getKey().equals(DOWNLOAD_URL)) { - mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()) - .sendToTarget(); - } - } + @Download.onPre + protected void onPre(DownloadTask task) {} - @Override public void onTaskStop(DownloadTask task) { - super.onTaskStop(task); + @Download.onTaskStart + void taskStart(DownloadTask task) { + //通过下载地址可以判断任务是否是你指定的任务 + if (task.getKey().equals(DOWNLOAD_URL)) { } + } - @Override public void onTaskCancel(DownloadTask task) { - super.onTaskCancel(task); - } + @Download.onTaskRunning + protected void running(DownloadTask task) {} - @Override public void onTaskRunning(DownloadTask task) { - super.onTaskRunning(task); - } + @Download.onTaskResume + void taskResume(DownloadTask task) {} - ... - } - ``` + @Download.onTaskStop + void taskStop(DownloadTask task) {} + + @Download.onTaskCancel + void taskCancel(DownloadTask task) {} + + @Download.onTaskFail + void taskFail(DownloadTask task) {} + + @Download.onTaskComplete + void taskComplete(DownloadTask task) {} -* 将事件注册到Aria + @Download.onNoSupportBreakPoint + public void onNoSupportBreakPoint(DownloadTask task) {} +<<<<<<< HEAD ```java @Override protected void onResume() { super.onResume(); Aria.download(this).addSchedulerListener(new MySchedulerListener()); } +======= +>>>>>>> v_3.0 ``` - -### 使用广播接收器接收Aria的任务下载状态 -有的时候,你可能希望在广播中接收Aria的下载事件,那么你需要 -* 在[配置文件](#配置文件设置参数)中把` `中的value改为true -* [点击该链接查看注册Aria广播的方式](https://github.com/AriaLyy/Aria/blob/master/BroadCast.md) ### Aria参数配置 #### 配置文件设置参数 @@ -135,7 +163,7 @@ compile 'com.arialyy.aria:Aria:3.1.6' - + @@ -145,7 +173,7 @@ compile 'com.arialyy.aria:Aria:3.1.6' - + @@ -160,12 +188,15 @@ compile 'com.arialyy.aria:Aria:3.1.6' - + + + + - + @@ -260,11 +291,18 @@ Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority( ```java Aria.upload(this).load(filePath).cancel(); ``` - + ## 混淆配置 ``` -dontwarn com.arialyy.aria.** -keep class com.arialyy.aria.**{*;} +-keep class **$$DownloadListenerProxy{ *; } +-keep class **$$UploadListenerProxy{ *; } +-keepclasseswithmembernames class * { + @Download.* ; + @Upload.* ; +} + ``` ## 其他 @@ -278,7 +316,12 @@ Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority( ## 开发日志 +<<<<<<< HEAD + v_3.1.6 [取消任务时onTaskCancel回调两次的bug](https://github.com/AriaLyy/Aria/issues/33) +======= + + v_3.1.7 修复某些文件下载不了的bug,增加apt注解方法,事件获取更加简单了 + + v_3.1.6 取消任务时onTaskCancel回调两次的bug +>>>>>>> v_3.0 + v_3.1.5 优化代码结构,增加优先下载任务功能。 + v_3.1.4 修复快速切换,暂停、恢复功能时,概率性出现的重新下载问题,添加onPre()回调,onPre()用于请求地址之前执行界面UI更新操作。 + v_3.1.0 添加Aria配置文件,优化代码 diff --git a/app/build.gradle b/app/build.gradle index 4eba9ffb..4d0e6f30 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,6 +25,11 @@ android { packagingOptions { exclude 'META-INF/services/javax.annotation.processing.Processor' } + + lintOptions { + abortOnError false + } + } dependencies { @@ -36,7 +41,8 @@ dependencies { compile 'com.google.code.gson:gson:2.7' compile 'com.squareup.okhttp3:okhttp:3.2.0' compile 'com.arialyy.frame:MVVM2:2.2.0' - compile 'com.arialyy.absadapter:AbsAdapter:1.1.2' compile project(':Aria') -// compile 'com.arialyy.aria:Aria:3.0.0' +// compile 'com.arialyy.aria:aria-core:3.1.7' +// annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.7' + } diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 01c497ee..522cfa0c 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -7,7 +7,7 @@ - + @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/base/adapter/AbsHolder.java b/app/src/main/java/com/arialyy/simple/base/adapter/AbsHolder.java new file mode 100644 index 00000000..c7d48f9f --- /dev/null +++ b/app/src/main/java/com/arialyy/simple/base/adapter/AbsHolder.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.simple.base.adapter; + +import android.support.annotation.IdRes; +import android.support.v7.widget.RecyclerView; +import android.util.SparseArray; +import android.view.View; + +import butterknife.ButterKnife; + +/** + * Created by lyy on 2015/12/3. + * 通用Holder + */ +public class AbsHolder extends RecyclerView.ViewHolder { + View mView; + private SparseArray mViews = new SparseArray<>(); + + public AbsHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } + + @SuppressWarnings("unchecked") + public T getView(@IdRes int id) { + View view = mViews.get(id); + if (view == null) { + view = mView.findViewById(id); + mViews.put(id, view); + } + return (T) view; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/base/adapter/AbsRVAdapter.java b/app/src/main/java/com/arialyy/simple/base/adapter/AbsRVAdapter.java new file mode 100644 index 00000000..744ccd94 --- /dev/null +++ b/app/src/main/java/com/arialyy/simple/base/adapter/AbsRVAdapter.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.simple.base.adapter; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by lyy on 2015/12/3. + * RecyclerView 通用Adapter + */ +public abstract class AbsRVAdapter + extends RecyclerView.Adapter { + protected String TAG; + protected List mData = new ArrayList<>(); + protected Context mContext; + Holder holder; + + public AbsRVAdapter(Context context, List data) { + mData = data; + mContext = context; + String arrays[] = getClass().getName().split("\\."); + TAG = arrays[arrays.length - 1]; + } + + @Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = + LayoutInflater.from(parent.getContext()).inflate(setLayoutId(viewType), parent, false); + holder = getViewHolder(view, viewType); + return holder; + } + + protected abstract Holder getViewHolder(View convertView, int viewType); + + @Override public void onBindViewHolder(Holder holder, int position) { + bindData(holder, position, mData.get(position)); + } + + public Context getContext() { + return mContext; + } + + @Override public int getItemCount() { + return mData.size(); + } + + /** + * item 的type + */ + protected abstract int setLayoutId(int type); + + protected abstract void bindData(Holder holder, int position, T item); +} \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/base/adapter/RvItemClickSupport.java b/app/src/main/java/com/arialyy/simple/base/adapter/RvItemClickSupport.java new file mode 100644 index 00000000..e42bb060 --- /dev/null +++ b/app/src/main/java/com/arialyy/simple/base/adapter/RvItemClickSupport.java @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.simple.base.adapter; + +import android.support.v7.widget.RecyclerView; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.View; +import com.arialyy.simple.R; + +/* + * RecyclerView item 事件监听帮助类 + * RvItemClickSupport.addTo(recyclerView).setOnItemClickListener(new RvItemClickSupport.OnItemClickListener() { + * + * @Override + * public void onItemClicked(RecyclerView recyclerView, int position, View v) { + * //处理你的事件 + * }); + */ +public class RvItemClickSupport { + private final RecyclerView mRecyclerView; + private OnItemClickListener mOnItemClickListener; + private OnItemLongClickListener mOnItemLongClickListener; + private OnItemTouchListener mOnItemTouchListener; + private OnItemFocusChangeListener mOnItemFocusChangeListener; + private OnItemKeyListener mOnItemKeyListener; + + public interface OnItemClickListener { + void onItemClicked(RecyclerView recyclerView, int position, View v); + } + + public interface OnItemLongClickListener { + boolean onItemLongClicked(RecyclerView recyclerView, int position, View v); + } + + public interface OnItemTouchListener { + public void onTouchEvent(RecyclerView rv, MotionEvent e, int position, View v); + } + + public interface OnItemFocusChangeListener { + public void onFocusChange(View v, int position, boolean hasFocus); + } + + public interface OnItemKeyListener { + public boolean onKey(View v, int keyCode, int position, KeyEvent event); + } + + private View.OnFocusChangeListener mOnFocusChangeListener = new View.OnFocusChangeListener() { + + @Override public void onFocusChange(View v, boolean hasFocus) { + if (mOnItemFocusChangeListener != null) { + RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v); + mOnItemFocusChangeListener.onFocusChange(v, holder.getAdapterPosition(), + holder.itemView.hasFocus()); + } + } + }; + + private View.OnClickListener mOnClickListener = new View.OnClickListener() { + @Override public void onClick(View v) { + if (mOnItemClickListener != null) { + RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v); + mOnItemClickListener.onItemClicked(mRecyclerView, holder.getAdapterPosition(), v); + } + } + }; + + private View.OnLongClickListener mOnLongClickListener = new View.OnLongClickListener() { + @Override public boolean onLongClick(View v) { + if (mOnItemLongClickListener != null) { + RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v); + return mOnItemLongClickListener.onItemLongClicked(mRecyclerView, + holder.getAdapterPosition(), v); + } + return false; + } + }; + + private View.OnTouchListener mOnTouchListener = new View.OnTouchListener() { + @Override public boolean onTouch(View v, MotionEvent event) { + if (mOnItemTouchListener != null) { + RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v); + mOnItemTouchListener.onTouchEvent(mRecyclerView, event, holder.getAdapterPosition(), v); + } + return false; + } + }; + + private View.OnKeyListener mOnKeyListener = new View.OnKeyListener() { + @Override public boolean onKey(View v, int keyCode, KeyEvent event) { + if (mOnItemKeyListener != null) { + RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v); + return mOnItemKeyListener.onKey(v, keyCode, holder.getAdapterPosition(), event); + } + return false; + } + }; + + private RecyclerView.OnChildAttachStateChangeListener mAttachListener = + new RecyclerView.OnChildAttachStateChangeListener() { + @Override public void onChildViewAttachedToWindow(View view) { + if (mOnItemClickListener != null) { + view.setOnClickListener(mOnClickListener); + } + if (mOnItemLongClickListener != null) { + view.setOnLongClickListener(mOnLongClickListener); + } + if (mOnItemTouchListener != null) { + view.setOnTouchListener(mOnTouchListener); + } + if (mOnItemFocusChangeListener != null) { + view.setOnFocusChangeListener(mOnFocusChangeListener); + } + if (mOnItemKeyListener != null) { + view.setOnKeyListener(mOnKeyListener); + } + } + + @Override public void onChildViewDetachedFromWindow(View view) { + + } + }; + + private RvItemClickSupport(RecyclerView recyclerView) { + mRecyclerView = recyclerView; + mRecyclerView.setTag(R.id.item_click_support, this); + mRecyclerView.addOnChildAttachStateChangeListener(mAttachListener); + } + + public static RvItemClickSupport addTo(RecyclerView view) { + RvItemClickSupport support = (RvItemClickSupport) view.getTag(R.id.item_click_support); + if (support == null) { + support = new RvItemClickSupport(view); + } + return support; + } + + public static RvItemClickSupport removeFrom(RecyclerView view) { + RvItemClickSupport support = (RvItemClickSupport) view.getTag(R.id.item_click_support); + if (support != null) { + support.detach(view); + } + return support; + } + + /** + * 设置按键监听 + */ + public RvItemClickSupport setOnItemKeyListenr(OnItemKeyListener onItemKeyListener) { + mOnItemKeyListener = onItemKeyListener; + return this; + } + + /** + * 设置焦点监听 + */ + public RvItemClickSupport setOnItemFocusChangeListener( + OnItemFocusChangeListener onItemFocusChangeListener) { + mOnItemFocusChangeListener = onItemFocusChangeListener; + return this; + } + + /** + * 设置触摸监听 + */ + public RvItemClickSupport setOnItemTouchListener(OnItemTouchListener onItemTouchListener) { + mOnItemTouchListener = onItemTouchListener; + return this; + } + + /** + * 设置点击监听 + */ + public RvItemClickSupport setOnItemClickListener(OnItemClickListener listener) { + mOnItemClickListener = listener; + return this; + } + + /** + * 设置长按监听 + */ + public RvItemClickSupport setOnItemLongClickListener(OnItemLongClickListener listener) { + mOnItemLongClickListener = listener; + return this; + } + + private void detach(RecyclerView view) { + view.removeOnChildAttachStateChangeListener(mAttachListener); + view.setTag(R.id.item_click_support, null); + } +} 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 e4a92340..1f8bf46a 100644 --- a/app/src/main/java/com/arialyy/simple/download/DownloadDialog.java +++ b/app/src/main/java/com/arialyy/simple/download/DownloadDialog.java @@ -23,6 +23,7 @@ import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.OnClick; +import com.arialyy.annotations.Download; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; @@ -61,7 +62,7 @@ public class DownloadDialog extends AbsDialog { int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); mPb.setProgress(p); } - Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); + Aria.download(this).register(); DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); if (entity != null) { 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) { + mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); + setBtState(false); } - private void setBtState(boolean startEnable) { - mStart.setEnabled(startEnable); - mCancel.setEnabled(!startEnable); - mStop.setEnabled(!startEnable); + @Download.onTaskStop public void onTaskStop(DownloadTask task) { + setBtState(true); + mSpeed.setText(task.getConvertSpeed()); } - private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener { - - @Override public void onTaskPre(DownloadTask task) { - super.onTaskPre(task); - mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); - setBtState(false); - } + @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { + setBtState(true); + mPb.setProgress(0); + mSpeed.setText(task.getConvertSpeed()); + } - @Override public void onTaskStop(DownloadTask task) { - super.onTaskStop(task); - setBtState(true); + @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mPb.setProgress(task.getPercent()); mSpeed.setText(task.getConvertSpeed()); } + } - @Override public void onTaskCancel(DownloadTask task) { - super.onTaskCancel(task); - setBtState(true); - mPb.setProgress(0); - mSpeed.setText(task.getConvertSpeed()); - } + @Override protected void dataCallback(int result, Object obj) { - @Override public void onTaskRunning(DownloadTask task) { - super.onTaskRunning(task); - if (task.getKey().equals(DOWNLOAD_URL)) { - mPb.setProgress(task.getPercent()); - mSpeed.setText(task.getConvertSpeed()); - } - } + } + + private void setBtState(boolean startEnable) { + mStart.setEnabled(startEnable); + mCancel.setEnabled(!startEnable); + mStop.setEnabled(!startEnable); } } 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 b82de2bc..a8c7188d 100644 --- a/app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java +++ b/app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java @@ -25,6 +25,7 @@ import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.OnClick; +import com.arialyy.annotations.Download; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; @@ -63,7 +64,7 @@ public class DownloadPopupWindow extends AbsPopupWindow { int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); mPb.setProgress(p); } - Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); + Aria.download(this).register(); DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); if (entity != null) { mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); @@ -101,37 +102,30 @@ public class DownloadPopupWindow extends AbsPopupWindow { mStop.setEnabled(!startEnable); } - private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener { + @Download.onTaskPre public void onTaskPre(DownloadTask task) { + mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); + setBtState(false); + } - @Override public void onTaskPre(DownloadTask task) { - super.onTaskPre(task); - mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); - setBtState(false); - } + @Download.onTaskStop public void onTaskStop(DownloadTask task) { + setBtState(true); + mSpeed.setText("0.0kb/s"); + } - @Override public void onTaskStop(DownloadTask task) { - super.onTaskStop(task); - setBtState(true); - mSpeed.setText("0.0kb/s"); - } + @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { + setBtState(true); + mPb.setProgress(0); + mSpeed.setText("0.0kb/s"); + } - @Override public void onTaskCancel(DownloadTask task) { - super.onTaskCancel(task); - setBtState(true); + @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { + long current = task.getCurrentProgress(); + long len = task.getFileSize(); + if (len == 0) { mPb.setProgress(0); - mSpeed.setText("0.0kb/s"); - } - - @Override public void onTaskRunning(DownloadTask task) { - super.onTaskRunning(task); - long current = task.getCurrentProgress(); - long len = task.getFileSize(); - if (len == 0) { - mPb.setProgress(0); - } else { - mPb.setProgress((int) ((current * 100) / len)); - } - mSpeed.setText(task.getConvertSpeed()); + } else { + mPb.setProgress((int) ((current * 100) / len)); } + mSpeed.setText(task.getConvertSpeed()); } } 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 7f8849e7..dfdde90e 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -33,18 +33,21 @@ import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; import butterknife.Bind; +import com.arialyy.annotations.Download; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.util.CommonUtil; +import com.arialyy.frame.util.FileUtil; 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.ActivitySingleBinding; import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; +import java.io.File; public class SingleTaskActivity extends BaseActivity { public static final int DOWNLOAD_PRE = 0x01; @@ -60,7 +63,10 @@ public class SingleTaskActivity extends BaseActivity { //"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; - //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; + //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; + //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; + //"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt"; + //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; //不支持断点的链接 //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; //"http://172.18.104.50:8080/download/_302turn"; @@ -71,15 +77,6 @@ public class SingleTaskActivity extends BaseActivity { @Bind(R.id.size) TextView mSize; @Bind(R.id.speed) TextView mSpeed; @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() { @Override public void handleMessage(Message msg) { @@ -132,6 +129,11 @@ public class SingleTaskActivity extends BaseActivity { } }; + @Override protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Aria.download(this).register(); + } + /** * 设置start 和 stop 按钮状态 */ @@ -140,28 +142,105 @@ public class SingleTaskActivity extends BaseActivity { mStop.setEnabled(!state); } - @Override protected void onResume() { - super.onResume(); - Aria.download(this).addSchedulerListener(new MySchedulerListener()); - //registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter()); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_single_task_activity, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onMenuItemClick(MenuItem item) { - if (item.getItemId() == R.id.help) { - String msg = "一些小知识点:\n" - + "1、你可以通过task.getKey().equals(DOWNLOAD_URL)判断是否是当前页面的下载,以防止progress乱跳\n" - + "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n" - + "3、你可以在界面初始化时通过Aria.download(this).load(DOWNLOAD_URL).getPercent()等方法快速获取相关任务的一些数据"; - showMsgDialog("tip", msg); + double speed = -1; + String msg = ""; + switch (item.getItemId()) { + case R.id.help: + msg = "一些小知识点:\n" + + "1、你可以通过task.getKey().equals(DOWNLOAD_URL)判断是否是当前页面的下载,以防止progress乱跳\n" + + "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n" + + "3、你可以在界面初始化时通过Aria.download(this).load(DOWNLOAD_URL).getPercent()等方法快速获取相关任务的一些数据"; + showMsgDialog("tip", msg); + break; + case R.id.speed_0: + speed = 0.0; + break; + case R.id.speed_128: + speed = 128.0; + break; + case R.id.speed_256: + speed = 256.0; + break; + case R.id.speed_512: + speed = 512.0; + break; + case R.id.speed_1m: + speed = 1024.0; + break; + } + if (speed > -1) { + msg = item.getTitle().toString(); + Aria.download(this).setMaxSpeed(speed); + T.showShort(this, msg); } return true; } + @Download.onPre protected void onPre(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()) + .sendToTarget(); + } + } + + @Download.onTaskStart void taskStart(DownloadTask task) { + //通过下载地址可以判断任务是否是你指定的任务 + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getDownloadEntity().getFileSize()) + .sendToTarget(); + } + } + + @Download.onTaskRunning protected void running(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget(); + } + } + + @Download.onTaskResume void taskResume(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getFileSize()).sendToTarget(); + } + } + + @Download.onTaskStop void taskStop(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP); + L.d(TAG, "task__stop"); + } + } + + @Download.onTaskCancel void taskCancel(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL); + L.d(TAG, "task__cancel"); + } + } + + @Download.onTaskFail void taskFail(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE); + } + } + + @Download.onTaskComplete void taskComplete(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE); + } + } + + @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); + } + } + @Override protected int setLayoutId() { return R.layout.activity_single; } @@ -203,6 +282,7 @@ public class SingleTaskActivity extends BaseActivity { break; } } +<<<<<<< HEAD private class MySchedulerListener extends Aria.DownloadSchedulerListener { @@ -263,4 +343,6 @@ public class SingleTaskActivity extends BaseActivity { } } } +======= +>>>>>>> v_3.0 } \ No newline at end of file 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 3365a4be..d78f82fe 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 @@ -23,6 +23,7 @@ import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.OnClick; +import com.arialyy.annotations.Download; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; @@ -61,11 +62,7 @@ public class DownloadFragment extends AbsFragment { } else { setBtState(true); } - } - - @Override public void onResume() { - super.onResume(); - Aria.download(this).addSchedulerListener(new DownloadFragment.MyDialogDownloadCallback()); + Aria.download(this).register(); } @OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) { @@ -85,6 +82,33 @@ public class DownloadFragment extends AbsFragment { } } + @Download.onTaskPre public void onTaskPre(DownloadTask task) { + mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); + setBtState(false); + } + + @Download.onTaskStop public void onTaskStop(DownloadTask task) { + setBtState(true); + mSpeed.setText("0.0kb/s"); + } + + @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { + setBtState(true); + mPb.setProgress(0); + mSpeed.setText("0.0kb/s"); + } + + @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { + long current = task.getCurrentProgress(); + long len = task.getFileSize(); + if (len == 0) { + mPb.setProgress(0); + } else { + mPb.setProgress((int) ((current * 100) / len)); + } + mSpeed.setText(task.getConvertSpeed()); + } + @Override protected void onDelayLoad() { } @@ -102,38 +126,4 @@ public class DownloadFragment extends AbsFragment { 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())); - setBtState(false); - } - - @Override public void onTaskStop(DownloadTask task) { - super.onTaskStop(task); - setBtState(true); - mSpeed.setText("0.0kb/s"); - } - - @Override public void onTaskCancel(DownloadTask task) { - super.onTaskCancel(task); - setBtState(true); - mPb.setProgress(0); - mSpeed.setText("0.0kb/s"); - } - - @Override public void onTaskRunning(DownloadTask task) { - super.onTaskRunning(task); - long current = task.getCurrentProgress(); - long len = task.getFileSize(); - if (len == 0) { - mPb.setProgress(0); - } else { - mPb.setProgress((int) ((current * 100) / len)); - } - mSpeed.setText(task.getConvertSpeed()); - } - } } 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 4b3dff78..d05e51a4 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 @@ -22,12 +22,12 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; import butterknife.Bind; -import com.arialyy.absadapter.common.AbsHolder; -import com.arialyy.absadapter.recycler_view.AbsRVAdapter; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.util.CommonUtil; import com.arialyy.simple.R; +import com.arialyy.simple.base.adapter.AbsHolder; +import com.arialyy.simple.base.adapter.AbsRVAdapter; import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; import java.util.List; import java.util.Map; diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java b/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java index 13040407..bdf64ed1 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java @@ -22,10 +22,10 @@ import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import butterknife.Bind; -import com.arialyy.absadapter.common.AbsHolder; -import com.arialyy.absadapter.recycler_view.AbsRVAdapter; import com.arialyy.aria.core.Aria; import com.arialyy.simple.R; +import com.arialyy.simple.base.adapter.AbsHolder; +import com.arialyy.simple.base.adapter.AbsRVAdapter; import java.util.List; import java.util.Map; import java.util.Set; diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java index c6fa7825..cefec9a0 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java @@ -21,6 +21,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; 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; @@ -46,6 +47,7 @@ public class MultiDownloadActivity extends BaseActivity temps = Aria.download(this).getTaskList(); if (temps != null && !temps.isEmpty()) { @@ -56,53 +58,38 @@ public class MultiDownloadActivity extends BaseActivity { @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); + Aria.download(this).register(); setTitle("多任务下载"); mData.addAll(getModule(DownloadModule.class).createMultiTestList()); mAdapter = new FileListAdapter(this, mData); @@ -69,47 +73,34 @@ public class MultiTaskActivity extends BaseActivity { } } - @Override protected void onResume() { - super.onResume(); - Aria.download(this).addSchedulerListener(new DownloadListener()); + @Download.onTaskStart void taskStart(DownloadTask task) { + mAdapter.updateBtState(task.getKey(), false); } - @Override protected void onDestroy() { - super.onDestroy(); - //unregisterReceiver(mReceiver); + @Download.onTaskResume void taskResume(DownloadTask task) { + mAdapter.updateBtState(task.getKey(), false); } - @Override protected void dataCallback(int result, Object data) { - super.dataCallback(result, data); - if (result == DownloadNumDialog.RESULT_CODE) { - Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + "")); - } + @Download.onTaskStop void taskStop(DownloadTask task) { + mAdapter.updateBtState(task.getKey(), true); } - private class DownloadListener extends Aria.DownloadSchedulerListener { - - @Override public void onTaskStart(DownloadTask task) { - super.onTaskStart(task); - mAdapter.updateBtState(task.getDownloadUrl(), false); - } - - @Override public void onTaskRunning(DownloadTask task) { - super.onTaskRunning(task); - } + @Download.onTaskCancel void taskCancel(DownloadTask task) { + mAdapter.updateBtState(task.getKey(), true); + } - @Override public void onTaskResume(DownloadTask task) { - super.onTaskResume(task); - mAdapter.updateBtState(task.getDownloadUrl(), false); - } + @Download.onTaskFail void taskFail(DownloadTask task) { + mAdapter.updateBtState(task.getKey(), true); + } - @Override public void onTaskStop(DownloadTask task) { - super.onTaskStop(task); - mAdapter.updateBtState(task.getDownloadUrl(), true); - } + @Download.onTaskComplete void taskComplete(DownloadTask task) { + mAdapter.updateBtState(task.getKey(), true); + } - @Override public void onTaskComplete(DownloadTask task) { - super.onTaskComplete(task); - mAdapter.updateBtState(task.getDownloadUrl(), true); + @Override protected void dataCallback(int result, Object data) { + super.dataCallback(result, data); + if (result == DownloadNumDialog.RESULT_CODE) { + Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + "")); } } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java b/app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java index 5e2038c0..258d1739 100644 --- a/app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java +++ b/app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.os.Environment; import android.os.IBinder; import android.support.annotation.Nullable; +import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.frame.util.show.T; @@ -45,7 +46,7 @@ public class DownloadService extends Service { @Override public void onCreate() { super.onCreate(); mNotify = new DownloadNotification(getApplicationContext()); - Aria.download(this).addSchedulerListener(new MySchedulerListener()); + Aria.download(this).register(); Aria.download(this) .load(DOWNLOAD_URL) .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk") @@ -54,45 +55,37 @@ public class DownloadService extends Service { @Override public void onDestroy() { super.onDestroy(); - Aria.download(this).removeSchedulerListener(); + Aria.download(this).unRegister(); } - private class MySchedulerListener extends Aria.DownloadSchedulerListener { - - @Override public void onNoSupportBreakPoint(DownloadTask task) { - super.onNoSupportBreakPoint(task); - T.showShort(getApplicationContext(), "该下载链接不支持断点"); - } - - @Override public void onTaskStart(DownloadTask task) { - T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载"); - } + @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { + T.showShort(getApplicationContext(), "该下载链接不支持断点"); + } - @Override public void onTaskResume(DownloadTask task) { - super.onTaskResume(task); - } + @Download.onTaskStart public void onTaskStart(DownloadTask task) { + T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载"); + } - @Override public void onTaskStop(DownloadTask task) { - T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载"); - } + @Download.onTaskStop public void onTaskStop(DownloadTask task) { + T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载"); + } - @Override public void onTaskCancel(DownloadTask task) { - T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载"); - } + @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { + T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载"); + } - @Override public void onTaskFail(DownloadTask task) { - T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败"); - } + @Download.onTaskFail public void onTaskFail(DownloadTask task) { + T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败"); + } - @Override public void onTaskComplete(DownloadTask task) { - T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成"); - mNotify.upload(100); - } + @Download.onTaskComplete public void onTaskComplete(DownloadTask task) { + T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成"); + mNotify.upload(100); + } - @Override public void onTaskRunning(DownloadTask task) { - long len = task.getFileSize(); - int p = (int) (task.getCurrentProgress() * 100 / len); - mNotify.upload(p); - } + @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { + long len = task.getFileSize(); + int p = (int) (task.getCurrentProgress() * 100 / len); + mNotify.upload(p); } } diff --git a/app/src/main/java/com/arialyy/simple/upload/UploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/UploadActivity.java index f958789b..881293fc 100644 --- a/app/src/main/java/com/arialyy/simple/upload/UploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/UploadActivity.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.os.Message; import butterknife.Bind; import butterknife.OnClick; +import com.arialyy.annotations.Upload; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.frame.util.FileUtil; @@ -78,6 +79,7 @@ public class UploadActivity extends BaseActivity { @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); + Aria.upload(this).register(); } @OnClick(R.id.upload) void upload() { @@ -96,50 +98,30 @@ public class UploadActivity extends BaseActivity { Aria.upload(this).load(FILE_PATH).cancel(); } - @Override protected void onResume() { - super.onResume(); - Aria.upload(this).addSchedulerListener(new UploadListener(mHandler)); + @Upload.onPre public void onPre(UploadTask task) { } - static class UploadListener extends Aria.UploadSchedulerListener { - WeakReference handler; - - UploadListener(Handler handler) { - this.handler = new WeakReference<>(handler); - } - - @Override public void onPre(UploadTask task) { - super.onPre(task); - } - - @Override public void onTaskPre(UploadTask task) { - super.onTaskPre(task); - L.d(TAG, "fileSize = " + task.getConvertFileSize()); - } + @Upload.onTaskPre public void taskPre(UploadTask task) { + L.d(TAG, "fileSize = " + task.getConvertFileSize()); + } - @Override public void onTaskStart(UploadTask task) { - super.onTaskStart(task); - handler.get().obtainMessage(START, task).sendToTarget(); - } + @Upload.onTaskStart public void taskStart(UploadTask task) { + mHandler.obtainMessage(START, task).sendToTarget(); + } - @Override public void onTaskStop(UploadTask task) { - super.onTaskStop(task); - handler.get().obtainMessage(STOP, task).sendToTarget(); - } + @Upload.onTaskStop public void taskStop(UploadTask task) { + mHandler.obtainMessage(STOP, task).sendToTarget(); + } - @Override public void onTaskCancel(UploadTask task) { - super.onTaskCancel(task); - handler.get().obtainMessage(CANCEL, task).sendToTarget(); - } + @Upload.onTaskCancel public void taskCancel(UploadTask task) { + mHandler.obtainMessage(CANCEL, task).sendToTarget(); + } - @Override public void onTaskRunning(UploadTask task) { - super.onTaskRunning(task); - handler.get().obtainMessage(RUNNING, task).sendToTarget(); - } + @Upload.onTaskRunning public void taskRunning(UploadTask task) { + mHandler.obtainMessage(RUNNING, task).sendToTarget(); + } - @Override public void onTaskComplete(UploadTask task) { - super.onTaskComplete(task); - handler.get().obtainMessage(COMPLETE, task).sendToTarget(); - } + @Upload.onTaskComplete public void taskComplete(UploadTask task) { + mHandler.obtainMessage(COMPLETE, task).sendToTarget(); } } diff --git a/app/src/main/res/menu/menu_single_task_activity.xml b/app/src/main/res/menu/menu_single_task_activity.xml index 1015a040..0b852a7c 100644 --- a/app/src/main/res/menu/menu_single_task_activity.xml +++ b/app/src/main/res/menu/menu_single_task_activity.xml @@ -9,4 +9,26 @@ android:title="tip" app:showAsAction="ifRoom" /> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml new file mode 100644 index 00000000..4bb1b5c2 --- /dev/null +++ b/app/src/main/res/values/ids.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 29ec0227..e24ee924 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,45 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { - repositories { - jcenter() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' - 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 - // in the individual module build.gradle files - } + repositories { + jcenter() + mavenCentral() + } + dependencies { + 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' + // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } } allprojects { - repositories { - jcenter() - mavenCentral() + repositories { + jcenter() + mavenCentral() + } + + tasks.withType(Javadoc) { + options { + encoding "UTF-8" + charSet 'UTF-8' + links "http://docs.oracle.com/javase/7/docs/api" } + } } task clean(type: Delete) { - delete rootProject.buildDir + delete rootProject.buildDir +} + +ext { + userOrg = 'arialyy' + groupId = 'com.arialyy.aria' +// publishVersion = '0.0.6' + publishVersion = '3.1.7' + repoName='maven' + desc = 'android 下载框架' + website = 'https://github.com/AriaLyy/Aria' + licences = ['Apache-2.0'] } diff --git a/cache/build/mPro.properties b/cache/build/mPro.properties deleted file mode 100644 index e69de29b..00000000 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1be3bb7c..2d992c4b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME 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 diff --git a/settings.gradle b/settings.gradle index 7fa85466..e4d72994 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':Aria' +include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler'