From 7182dda17d5ee3810433ad76d6e61644d278a14a Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Wed, 24 May 2017 14:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E8=BD=AC=E6=8D=A2=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E8=BF=9B=E5=BA=A6=E7=99=BE=E5=88=86=E6=AF=94=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/build.gradle | 4 ++-- .../aria/core/download/DownloadTask.java | 24 +++++++++++++++++++ .../java/com/arialyy/aria/core/inf/ITask.java | 13 ++++++++++ .../arialyy/aria/core/upload/UploadTask.java | 24 +++++++++++++++++++ README.md | 8 +++++-- 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index 36c3b695..87935d12 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 23 - versionCode 310 - versionName "3.1.0" + versionCode 311 + versionName "3.1.1" } buildTypes { release { 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 80a99edf..8611e1fe 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 @@ -95,6 +95,18 @@ public class DownloadTask implements ITask { return mEntity.getConvertSpeed(); } + /** + * 获取百分比进度 + * + * @return 返回百分比进度,如果文件长度为0,返回0 + */ + @Override public int getPercent() { + if (mEntity.getFileSize() == 0) { + return 0; + } + return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()); + } + /** * 获取文件大小 */ @@ -102,6 +114,18 @@ public class DownloadTask implements ITask { return mEntity.getFileSize(); } + /** + * 转换单位后的文件长度 + * + * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1k、1m、1g、1t + */ + @Override public String getConvertFileSize() { + if (mEntity.getFileSize() == 0) { + return "0m"; + } + return CommonUtil.formatFileSize(mEntity.getFileSize()); + } + /** * 获取当前下载进度 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index d8aa1607..bf88e5e8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -54,8 +54,21 @@ public interface ITask { */ public String getConvertSpeed(); + /** + * 获取百分比进度 + */ + public int getPercent(); + + /** + * 原始文件byte长度 + */ public long getFileSize(); + /** + * 转换单位后的文件长度 + */ + public String getConvertFileSize(); + public long getCurrentProgress(); public void setTargetName(String targetName); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index 87b05d41..8a23431c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -151,6 +151,30 @@ public class UploadTask implements ITask { return mUploadEntity.getConvertSpeed(); } + /** + * 获取百分比进度 + * + * @return 返回百分比进度,如果文件长度为0,返回0 + */ + @Override public int getPercent() { + if (mUploadEntity.getFileSize() == 0) { + return 0; + } + return (int) (mUploadEntity.getCurrentProgress() * 100 / mUploadEntity.getFileSize()); + } + + /** + * 转换单位后的文件长度 + * + * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1k、1m、1g、1t + */ + @Override public String getConvertFileSize() { + if (mUploadEntity.getFileSize() == 0) { + return "0m"; + } + return CommonUtil.formatFileSize(mUploadEntity.getFileSize()); + } + @Override public long getFileSize() { return mUploadEntity.getFileSize(); } diff --git a/README.md b/README.md index 367a50d1..edfdf1ea 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.0' +compile 'com.arialyy.aria:Aria:3.1.1' ``` ## 示例 @@ -203,12 +203,16 @@ Aria.download(this).removeAllTask(); long speed = task.getSpeed(); } ``` -* 获取下载的文件大小 +* 获取下载的文件大小、当前进度百分比 同样的,你也可以在DownloadTask对象中获取下载的文件大小 ``` @Override public void onTaskRunning(DownloadTask task) {  //获取文件大小 long fileSize = task.getFileSize(); + //获取单位转换后的文件大小 + String fileSize1 = task.getConvertFileSize(); + //当前进度百分比 + int percent = task.getPercent(); } ```