From d05b685fa30a2e3daea820322f67328cd9ec4706 Mon Sep 17 00:00:00 2001
From: AriaLyy <511455842@qq.com>
Date: Thu, 9 Feb 2017 18:19:43 +0800
Subject: [PATCH] =?UTF-8?q?upload=EF=BC=8C=E4=BB=A3=E7=A0=81=E9=87=8D?=
=?UTF-8?q?=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/misc.xml | 2 +-
.../main/java/com/arialyy/aria/core/Aria.java | 21 +--
.../com/arialyy/aria/core/AriaManager.java | 27 ++--
.../core/{ => download}/DownloadEntity.java | 2 +-
.../core/{ => download}/DownloadReceiver.java | 20 +--
.../core/{ => download}/DownloadTarget.java | 8 +-
.../{ => download}/DownloadTaskEntity.java | 3 +-
.../download => download/command}/AddCmd.java | 9 +-
.../command}/CancelCmd.java | 9 +-
.../command}/CmdFactory.java | 5 +-
.../command}/IDownloadCmd.java | 17 +-
.../command}/SingleCmd.java | 6 +-
.../command}/StartCmd.java | 9 +-
.../command}/StopCmd.java | 10 +-
.../queue/DownloadTaskQueue.java | 44 ++---
.../{ => download}/queue/IDownloader.java | 20 +--
.../aria/core/{ => download}/queue/IPool.java | 12 +-
.../core/{ => download}/queue/ITaskQueue.java | 19 ++-
.../{ => download}/queue/pool/CachePool.java | 22 +--
.../queue/pool/ExecutePool.java | 30 ++--
.../scheduler/DownloadSchedulers.java | 18 +--
.../scheduler/IDownloadSchedulers.java | 4 +-
.../scheduler/OnSchedulerListener.java | 20 +--
.../{ => download}/task/ConnectionHelp.java | 4 +-
.../{ => download}/task/DownloadListener.java | 2 +-
.../task/DownloadStateConstance.java | 2 +-
.../task/DownloadTask.java} | 26 +--
.../task/DownloadTaskFactory.java} | 24 +--
.../{ => download}/task/DownloadUtil.java | 6 +-
.../task/IDownloadListener.java | 2 +-
.../{ => download}/task/IDownloadUtil.java | 4 +-
.../{ => download}/task/SingleThreadTask.java | 2 +-
.../java/com/arialyy/aria/core/inf/ICmd.java | 12 ++
.../aria/core/{ => inf}/IReceiver.java | 4 +-
.../aria/core/upload/IUploadListener.java | 11 ++
.../aria/core/upload/MultipartUtility.java | 150 ++++++++++++++++++
.../aria/core/upload/UploadEntity.java | 30 ++++
.../core/{ => upload}/UploadReceiver.java | 4 +-
.../aria/core/upload/UploadTaskEntity.java | 22 +++
.../arialyy/aria/core/upload/UploadUtil.java | 122 ++++++++++++++
.../java/com/arialyy/aria/util/CheckUtil.java | 27 +++-
.../com/arialyy/aria/util/CommonUtil.java | 7 +-
app/src/main/AndroidManifest.xml | 3 +-
.../simple/dialog_task/DownloadDialog.java | 14 +-
.../fragment_task/DownloadFragment.java | 14 +-
.../arialyy/simple/module/DownloadModule.java | 2 +-
.../simple/multi_task/DownloadActivity.java | 18 +--
.../simple/multi_task/DownloadAdapter.java | 2 +-
.../simple/multi_task/MultiTaskActivity.java | 12 +-
.../notification/SimpleNotification.java | 14 +-
.../simple/pop_task/DownloadPopupWindow.java | 14 +-
.../single_task/SingleTaskActivity.java | 22 +--
.../main/java/com/arialyy/simple/upload.java | 36 +++++
app/src/main/res/layout/activity_upload.xml | 22 +++
54 files changed, 697 insertions(+), 274 deletions(-)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/DownloadEntity.java (99%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/DownloadReceiver.java (86%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/DownloadTarget.java (95%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/DownloadTaskEntity.java (92%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/AddCmd.java (82%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/CancelCmd.java (82%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/CmdFactory.java (96%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/IDownloadCmd.java (79%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/SingleCmd.java (89%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/StartCmd.java (82%)
rename Aria/src/main/java/com/arialyy/aria/core/{command/download => download/command}/StopCmd.java (83%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/queue/DownloadTaskQueue.java (77%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/queue/IDownloader.java (66%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/queue/IPool.java (83%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/queue/ITaskQueue.java (78%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/queue/pool/CachePool.java (86%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/queue/pool/ExecutePool.java (85%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/scheduler/DownloadSchedulers.java (92%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/scheduler/IDownloadSchedulers.java (94%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/scheduler/OnSchedulerListener.java (66%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/ConnectionHelp.java (96%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/DownloadListener.java (96%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/DownloadStateConstance.java (97%)
rename Aria/src/main/java/com/arialyy/aria/core/{task/Task.java => download/task/DownloadTask.java} (93%)
rename Aria/src/main/java/com/arialyy/aria/core/{task/TaskFactory.java => download/task/DownloadTaskFactory.java} (65%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/DownloadUtil.java (98%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/IDownloadListener.java (97%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/IDownloadUtil.java (94%)
rename Aria/src/main/java/com/arialyy/aria/core/{ => download}/task/SingleThreadTask.java (99%)
create mode 100644 Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java
rename Aria/src/main/java/com/arialyy/aria/core/{ => inf}/IReceiver.java (92%)
create mode 100644 Aria/src/main/java/com/arialyy/aria/core/upload/IUploadListener.java
create mode 100644 Aria/src/main/java/com/arialyy/aria/core/upload/MultipartUtility.java
create mode 100644 Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
rename Aria/src/main/java/com/arialyy/aria/core/{ => upload}/UploadReceiver.java (91%)
create mode 100644 Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java
create mode 100644 Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
create mode 100644 app/src/main/java/com/arialyy/simple/upload.java
create mode 100644 app/src/main/res/layout/activity_upload.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
index fbb68289..5d199810 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
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 8bd04957..62fd6880 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
@@ -26,8 +26,9 @@ import android.app.Service;
import android.content.Context;
import android.os.Build;
import android.widget.PopupWindow;
-import com.arialyy.aria.core.scheduler.OnSchedulerListener;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadReceiver;
+import com.arialyy.aria.core.download.scheduler.OnSchedulerListener;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/12/1.
@@ -143,35 +144,35 @@ import com.arialyy.aria.core.task.Task;
public static class SimpleSchedulerListener implements OnSchedulerListener {
- @Override public void onTaskPre(Task task) {
+ @Override public void onTaskPre(DownloadTask task) {
}
- @Override public void onTaskResume(Task task) {
+ @Override public void onTaskResume(DownloadTask task) {
}
- @Override public void onTaskStart(Task task) {
+ @Override public void onTaskStart(DownloadTask task) {
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
}
- @Override public void onTaskFail(Task task) {
+ @Override public void onTaskFail(DownloadTask task) {
}
- @Override public void onTaskComplete(Task task) {
+ @Override public void onTaskComplete(DownloadTask task) {
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
}
}
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 95a9711b..cf474214 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
@@ -27,9 +27,14 @@ import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.widget.PopupWindow;
-import com.arialyy.aria.core.command.download.IDownloadCmd;
-import com.arialyy.aria.core.queue.DownloadTaskQueue;
-import com.arialyy.aria.core.queue.ITaskQueue;
+import com.arialyy.aria.core.download.command.IDownloadCmd;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadReceiver;
+import com.arialyy.aria.core.inf.ICmd;
+import com.arialyy.aria.core.inf.IReceiver;
+import com.arialyy.aria.core.download.queue.DownloadTaskQueue;
+import com.arialyy.aria.core.download.queue.ITaskQueue;
+import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.DbUtil;
import com.arialyy.aria.util.CAConfiguration;
@@ -56,7 +61,7 @@ import java.util.Map;
public static Context APP;
private ITaskQueue mTaskQueue;
- private List mCommands = new ArrayList<>();
+ private List mCommands = new ArrayList<>();
private AriaManager(Context context) {
DbUtil.init(context.getApplicationContext());
@@ -75,7 +80,11 @@ import java.util.Map;
return INSTANCE;
}
- List getAllDownloadEntity() {
+ public Map getReceiver(){
+ return mReceivers;
+ }
+
+ public List getAllDownloadEntity() {
return DbEntity.findAllData(DownloadEntity.class);
}
@@ -89,7 +98,7 @@ import java.util.Map;
/**
* 设置命令
*/
- AriaManager setCmd(IDownloadCmd command) {
+ public AriaManager setCmd(ICmd command) {
mCommands.add(command);
return this;
}
@@ -97,7 +106,7 @@ import java.util.Map;
/**
* 设置一组命令
*/
- AriaManager setCmds(List commands) {
+ public AriaManager setCmds(List commands) {
if (commands != null && commands.size() > 0) {
mCommands.addAll(commands);
}
@@ -107,8 +116,8 @@ import java.util.Map;
/**
* 执行所有设置的命令
*/
- synchronized void exe() {
- for (IDownloadCmd command : mCommands) {
+ public synchronized void exe() {
+ for (ICmd command : mCommands) {
command.executeCmd();
}
mCommands.clear();
diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
similarity index 99%
rename from Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
index 53b69824..af97dc53 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
@@ -15,7 +15,7 @@
*/
-package com.arialyy.aria.core;
+package com.arialyy.aria.core.download;
import android.os.Parcel;
import android.os.Parcelable;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
similarity index 86%
rename from Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
index 8a2237a8..6979e802 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core;
+package com.arialyy.aria.core.download;
import android.support.annotation.NonNull;
-import com.arialyy.aria.core.command.download.CmdFactory;
-import com.arialyy.aria.core.command.download.IDownloadCmd;
-import com.arialyy.aria.core.scheduler.DownloadSchedulers;
-import com.arialyy.aria.core.scheduler.OnSchedulerListener;
+import com.arialyy.aria.core.AriaManager;
+import com.arialyy.aria.core.inf.IReceiver;
+import com.arialyy.aria.core.download.command.CmdFactory;
+import com.arialyy.aria.core.download.command.IDownloadCmd;
+import com.arialyy.aria.core.download.scheduler.DownloadSchedulers;
+import com.arialyy.aria.core.download.scheduler.OnSchedulerListener;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
@@ -30,7 +32,7 @@ import java.util.Set;
* Created by lyy on 2016/12/5.
* 下载功能接收器
*/
-public class DownloadReceiver implements IReceiver{
+public class DownloadReceiver implements IReceiver {
private static final String TAG = "DownloadReceiver";
public String targetName;
public OnSchedulerListener listener;
@@ -131,11 +133,11 @@ public class DownloadReceiver implements IReceiver{
CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL));
}
ariaManager.setCmds(cancelCmds).exe();
- Set keys = ariaManager.mReceivers.keySet();
+ Set keys = ariaManager.getReceiver().keySet();
for (String key : keys) {
- IReceiver receiver = ariaManager.mReceivers.get(key);
+ IReceiver receiver = ariaManager.getReceiver().get(key);
receiver.removeSchedulerListener();
- ariaManager.mReceivers.remove(key);
+ ariaManager.getReceiver().remove(key);
}
}
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
similarity index 95%
rename from Aria/src/main/java/com/arialyy/aria/core/DownloadTarget.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
index 6eae0275..f168d10b 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/DownloadTarget.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
@@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core;
+package com.arialyy.aria.core.download;
import android.support.annotation.NonNull;
import android.text.TextUtils;
-import com.arialyy.aria.core.command.download.CmdFactory;
-import com.arialyy.aria.core.command.download.IDownloadCmd;
+import com.arialyy.aria.core.AriaManager;
+import com.arialyy.aria.core.RequestEnum;
+import com.arialyy.aria.core.download.command.CmdFactory;
+import com.arialyy.aria.core.download.command.IDownloadCmd;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
similarity index 92%
rename from Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
index 9d15475e..b28ff240 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core;
+package com.arialyy.aria.core.download;
+import com.arialyy.aria.core.RequestEnum;
import java.util.HashMap;
import java.util.Map;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/AddCmd.java
similarity index 82%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/AddCmd.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/AddCmd.java
index 3a919edb..45698636 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/AddCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/AddCmd.java
@@ -14,12 +14,11 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.command.download;
+package com.arialyy.aria.core.download.command;
import android.util.Log;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/8/22.
@@ -36,7 +35,7 @@ class AddCmd extends IDownloadCmd {
}
@Override public void executeCmd() {
- Task task = mQueue.getTask(mEntity.downloadEntity);
+ DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
mQueue.createTask(mTargetName, mEntity);
} else {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/CancelCmd.java
similarity index 82%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/CancelCmd.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/CancelCmd.java
index 686c1521..a16437da 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/CancelCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/CancelCmd.java
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.command.download;
+package com.arialyy.aria.core.download.command;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/9/20.
@@ -35,7 +34,7 @@ class CancelCmd extends IDownloadCmd {
}
@Override public void executeCmd() {
- Task task = mQueue.getTask(mEntity.downloadEntity);
+ DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
task = mQueue.createTask(mTargetName, mEntity);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/CmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/CmdFactory.java
similarity index 96%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/CmdFactory.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/CmdFactory.java
index a6f5f3aa..e248b1bb 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/CmdFactory.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/CmdFactory.java
@@ -14,10 +14,9 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.command.download;
+package com.arialyy.aria.core.download.command;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
/**
* Created by Lyy on 2016/9/23.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/IDownloadCmd.java
similarity index 79%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/IDownloadCmd.java
index ea1909a6..b0d47767 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/IDownloadCmd.java
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.command.download;
+package com.arialyy.aria.core.download.command;
import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.queue.ITaskQueue;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.queue.ITaskQueue;
+import com.arialyy.aria.core.inf.ICmd;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
@@ -26,7 +27,7 @@ import com.arialyy.aria.util.CommonUtil;
* Created by lyy on 2016/8/22.
* 下载命令
*/
-public abstract class IDownloadCmd {
+public abstract class IDownloadCmd implements ICmd{
ITaskQueue mQueue;
DownloadTaskEntity mEntity;
String TAG;
@@ -43,17 +44,11 @@ public abstract class IDownloadCmd {
* @param targetName 产生任务的对象名
*/
IDownloadCmd(String targetName, DownloadTaskEntity entity) {
- if (!CheckUtil.checkDownloadEntity(entity.downloadEntity)) {
- return;
- }
+ CheckUtil.checkDownloadEntity(entity.downloadEntity);
mTargetName = targetName;
mEntity = entity;
TAG = CommonUtil.getClassName(this);
mQueue = AriaManager.getInstance(AriaManager.APP).getTaskQueue();
}
- /**
- * 执行命令
- */
- public abstract void executeCmd();
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/SingleCmd.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/SingleCmd.java
similarity index 89%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/SingleCmd.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/SingleCmd.java
index d9eb246e..b816ac00 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/SingleCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/SingleCmd.java
@@ -16,8 +16,8 @@
//package com.arialyy.aria.core.command.download;
//
//import android.util.Log;
-//import com.arialyy.aria.core.DownloadEntity;
-//import com.arialyy.aria.core.task.Task;
+//import com.arialyy.aria.core.download.DownloadEntity;
+//import com.arialyy.aria.core.task.DownloadTask;
//
///**
// * Created by lyy on 2016/11/30.
@@ -36,7 +36,7 @@
// }
//
// @Override public void executeCmd() {
-// Task task = mQueue.getTask(mEntity);
+// DownloadTask task = mQueue.getTask(mEntity);
// if (task == null) {
// task = mQueue.createTask(mTargetName, mEntity);
// } else {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/StartCmd.java
similarity index 82%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/StartCmd.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/StartCmd.java
index 038df58e..316db667 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/StartCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/StartCmd.java
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.command.download;
+package com.arialyy.aria.core.download.command;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/8/22.
@@ -35,7 +34,7 @@ class StartCmd extends IDownloadCmd {
}
@Override public void executeCmd() {
- Task task = mQueue.getTask(mEntity.downloadEntity);
+ DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
task = mQueue.createTask(mTargetName, mEntity);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/StopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/download/command/StopCmd.java
similarity index 83%
rename from Aria/src/main/java/com/arialyy/aria/core/command/download/StopCmd.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/command/StopCmd.java
index 1ec50551..2b342757 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/download/StopCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/command/StopCmd.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.command.download;
+package com.arialyy.aria.core.download.command;
import android.text.TextUtils;
import android.util.Log;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/9/20.
@@ -37,7 +37,7 @@ class StopCmd extends IDownloadCmd {
}
@Override public void executeCmd() {
- Task task = mQueue.getTask(mEntity.downloadEntity);
+ DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
task = mQueue.createTask(mTargetName, mEntity);
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/download/queue/DownloadTaskQueue.java
similarity index 77%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/queue/DownloadTaskQueue.java
index 52dc5e0f..346902af 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/queue/DownloadTaskQueue.java
@@ -14,18 +14,18 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.queue;
+package com.arialyy.aria.core.download.queue;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.queue.pool.CachePool;
-import com.arialyy.aria.core.queue.pool.ExecutePool;
-import com.arialyy.aria.core.scheduler.DownloadSchedulers;
-import com.arialyy.aria.core.task.Task;
-import com.arialyy.aria.core.task.TaskFactory;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.queue.pool.CachePool;
+import com.arialyy.aria.core.download.queue.pool.ExecutePool;
+import com.arialyy.aria.core.download.scheduler.DownloadSchedulers;
+import com.arialyy.aria.core.download.task.DownloadTask;
+import com.arialyy.aria.core.download.task.DownloadTaskFactory;
import com.arialyy.aria.util.Configuration;
/**
@@ -79,7 +79,7 @@ public class DownloadTaskQueue implements ITaskQueue {
return mCachePool.size();
}
- @Override public void startTask(Task task) {
+ @Override public void startTask(DownloadTask task) {
if (mExecutePool.putTask(task)) {
mCachePool.removeTask(task);
task.getDownloadEntity().setFailNum(0);
@@ -87,7 +87,7 @@ public class DownloadTaskQueue implements ITaskQueue {
}
}
- @Override public void stopTask(Task task) {
+ @Override public void stopTask(DownloadTask task) {
if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】");
if (mExecutePool.removeTask(task)) {
task.stop();
@@ -97,11 +97,11 @@ public class DownloadTaskQueue implements ITaskQueue {
}
}
- @Override public void cancelTask(Task task) {
+ @Override public void cancelTask(DownloadTask task) {
task.cancel();
}
- @Override public void reTryStart(Task task) {
+ @Override public void reTryStart(DownloadTask task) {
if (task == null) {
Log.w(TAG, "重试下载失败,task 为null");
return;
@@ -128,7 +128,7 @@ public class DownloadTaskQueue implements ITaskQueue {
//设置的任务数小于配置任务数
if (diff <= -1 && mExecutePool.size() >= size) {
for (int i = 0, len = Math.abs(diff); i < len; i++) {
- Task eTask = mExecutePool.pollTask();
+ DownloadTask eTask = mExecutePool.pollTask();
if (eTask != null) {
stopTask(eTask);
}
@@ -137,7 +137,7 @@ public class DownloadTaskQueue implements ITaskQueue {
mExecutePool.setDownloadNum(downloadNum);
if (diff >= 1) {
for (int i = 0; i < diff; i++) {
- Task nextTask = getNextTask();
+ DownloadTask nextTask = getNextTask();
if (nextTask != null
&& nextTask.getDownloadEntity().getState() == DownloadEntity.STATE_WAIT) {
startTask(nextTask);
@@ -146,21 +146,21 @@ public class DownloadTaskQueue implements ITaskQueue {
}
}
- @Override public Task createTask(String target, DownloadTaskEntity entity) {
- Task task;
+ @Override public DownloadTask createTask(String target, DownloadTaskEntity entity) {
+ DownloadTask task;
if (TextUtils.isEmpty(target)) {
task =
- TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance());
+ DownloadTaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance());
} else {
- task = TaskFactory.getInstance()
+ task = DownloadTaskFactory.getInstance()
.createTask(target, mContext, entity, DownloadSchedulers.getInstance());
}
mCachePool.putTask(task);
return task;
}
- @Override public Task getTask(DownloadEntity entity) {
- Task task = mExecutePool.getTask(entity.getDownloadUrl());
+ @Override public DownloadTask getTask(DownloadEntity entity) {
+ DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl());
if (task == null) {
task = mCachePool.getTask(entity.getDownloadUrl());
}
@@ -168,7 +168,7 @@ public class DownloadTaskQueue implements ITaskQueue {
}
@Override public void removeTask(DownloadEntity entity) {
- Task task = mExecutePool.getTask(entity.getDownloadUrl());
+ DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl());
if (task != null) {
Log.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败"));
}
@@ -178,7 +178,7 @@ public class DownloadTaskQueue implements ITaskQueue {
}
}
- @Override public Task getNextTask() {
+ @Override public DownloadTask getNextTask() {
return mCachePool.pollTask();
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java b/Aria/src/main/java/com/arialyy/aria/core/download/queue/IDownloader.java
similarity index 66%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/queue/IDownloader.java
index 601e54ed..cf855db2 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/queue/IDownloader.java
@@ -15,9 +15,9 @@
*/
-package com.arialyy.aria.core.queue;
+package com.arialyy.aria.core.download.queue;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/8/16.
@@ -27,28 +27,28 @@ public interface IDownloader {
/**
* 开始任务
*
- * @param task {@link Task}
+ * @param task {@link DownloadTask}
*/
- public void startTask(Task task);
+ public void startTask(DownloadTask task);
/**
* 停止任务
*
- * @param task {@link Task}
+ * @param task {@link DownloadTask}
*/
- public void stopTask(Task task);
+ public void stopTask(DownloadTask task);
/**
* 取消任务
*
- * @param task {@link Task}
+ * @param task {@link DownloadTask}
*/
- public void cancelTask(Task task);
+ public void cancelTask(DownloadTask task);
/**
* 重试下载
*
- * @param task {@link Task}
+ * @param task {@link DownloadTask}
*/
- public void reTryStart(Task task);
+ public void reTryStart(DownloadTask task);
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java b/Aria/src/main/java/com/arialyy/aria/core/download/queue/IPool.java
similarity index 83%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/queue/IPool.java
index f41258f4..722353fa 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/queue/IPool.java
@@ -15,9 +15,9 @@
*/
-package com.arialyy.aria.core.queue;
+package com.arialyy.aria.core.download.queue;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/8/14.
@@ -27,14 +27,14 @@ public interface IPool {
/**
* 将下载任务添加到任务池中
*/
- public boolean putTask(Task task);
+ public boolean putTask(DownloadTask task);
/**
* 按照队列原则取出下载任务
*
* @return 返回null或者下载任务
*/
- public Task pollTask();
+ public DownloadTask pollTask();
/**
* 通过下载链接获取下载任务,当任务不为空时,队列将删除该下载任务
@@ -42,7 +42,7 @@ public interface IPool {
* @param downloadUrl 下载链接
* @return 返回null或者下载任务
*/
- public Task getTask(String downloadUrl);
+ public DownloadTask getTask(String downloadUrl);
/**
* 删除任务池中的下载任务
@@ -50,7 +50,7 @@ public interface IPool {
* @param task 下载任务
* @return true:移除成功
*/
- public boolean removeTask(Task task);
+ public boolean removeTask(DownloadTask task);
/**
* 通过下载链接移除下载任务
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/download/queue/ITaskQueue.java
similarity index 78%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/queue/ITaskQueue.java
index 58ad3260..3cc29ff5 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/queue/ITaskQueue.java
@@ -14,12 +14,11 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.queue;
+package com.arialyy.aria.core.download.queue;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/8/16.
@@ -49,17 +48,17 @@ public interface ITaskQueue extends IDownloader {
*
* @param entity 下载实体{@link DownloadTaskEntity}
* @param targetName 生成该任务的对象
- * @return {@link Task}
+ * @return {@link DownloadTask}
*/
- public Task createTask(String targetName, DownloadTaskEntity entity);
+ public DownloadTask createTask(String targetName, DownloadTaskEntity entity);
/**
* 通过下载链接从缓存池或任务池搜索下载任务,如果缓存池或任务池都没有任务,则创建新任务
*
* @param entity 下载实体{@link DownloadEntity}
- * @return {@link Task}
+ * @return {@link DownloadTask}
*/
- public Task getTask(DownloadEntity entity);
+ public DownloadTask getTask(DownloadEntity entity);
/**
* 通过下载链接删除任务
@@ -73,5 +72,5 @@ public interface ITaskQueue extends IDownloader {
*
* @return 下载任务 or null
*/
- public Task getNextTask();
+ public DownloadTask getNextTask();
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java b/Aria/src/main/java/com/arialyy/aria/core/download/queue/pool/CachePool.java
similarity index 86%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/queue/pool/CachePool.java
index 8f710491..1d860a48 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/queue/pool/CachePool.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.queue.pool;
+package com.arialyy.aria.core.download.queue.pool;
import android.text.TextUtils;
import android.util.Log;
-import com.arialyy.aria.core.queue.IPool;
+import com.arialyy.aria.core.download.queue.IPool;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
-import com.arialyy.aria.core.task.Task;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
@@ -36,8 +36,8 @@ public class CachePool implements IPool {
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
private static volatile CachePool INSTANCE = null;
private static final long TIME_OUT = 1000;
- private Map mCacheArray;
- private LinkedBlockingQueue mCacheQueue;
+ private Map mCacheArray;
+ private LinkedBlockingQueue mCacheQueue;
private CachePool() {
mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM);
@@ -53,7 +53,7 @@ public class CachePool implements IPool {
return INSTANCE;
}
- @Override public boolean putTask(Task task) {
+ @Override public boolean putTask(DownloadTask task) {
synchronized (LOCK) {
if (task == null) {
Log.e(TAG, "下载任务不能为空!!");
@@ -74,10 +74,10 @@ public class CachePool implements IPool {
}
}
- @Override public Task pollTask() {
+ @Override public DownloadTask pollTask() {
synchronized (LOCK) {
try {
- Task task = null;
+ DownloadTask task = null;
task = mCacheQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (task != null) {
String url = task.getDownloadEntity().getDownloadUrl();
@@ -91,7 +91,7 @@ public class CachePool implements IPool {
return null;
}
- @Override public Task getTask(String downloadUrl) {
+ @Override public DownloadTask getTask(String downloadUrl) {
synchronized (LOCK) {
if (TextUtils.isEmpty(downloadUrl)) {
Log.e(TAG, "请传入有效的下载链接");
@@ -102,7 +102,7 @@ public class CachePool implements IPool {
}
}
- @Override public boolean removeTask(Task task) {
+ @Override public boolean removeTask(DownloadTask task) {
synchronized (LOCK) {
if (task == null) {
Log.e(TAG, "任务不能为空");
@@ -122,7 +122,7 @@ public class CachePool implements IPool {
return false;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
- Task task = mCacheArray.get(key);
+ DownloadTask task = mCacheArray.get(key);
mCacheArray.remove(key);
return mCacheQueue.remove(task);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/download/queue/pool/ExecutePool.java
similarity index 85%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/queue/pool/ExecutePool.java
index a3a1c911..1dc36d9a 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/queue/pool/ExecutePool.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.queue.pool;
+package com.arialyy.aria.core.download.queue.pool;
import android.text.TextUtils;
import android.util.Log;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
-import com.arialyy.aria.core.queue.IPool;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.queue.IPool;
import com.arialyy.aria.util.Configuration;
import java.util.HashMap;
import java.util.Map;
@@ -36,8 +36,8 @@ public class ExecutePool implements IPool {
private static final Object LOCK = new Object();
private static final long TIME_OUT = 1000;
private static volatile ExecutePool INSTANCE = null;
- private ArrayBlockingQueue mExecuteQueue;
- private Map mExecuteArray;
+ private ArrayBlockingQueue mExecuteQueue;
+ private Map mExecuteArray;
private int mSize;
private ExecutePool() {
@@ -55,7 +55,7 @@ public class ExecutePool implements IPool {
return INSTANCE;
}
- @Override public boolean putTask(Task task) {
+ @Override public boolean putTask(DownloadTask task) {
synchronized (LOCK) {
if (task == null) {
Log.e(TAG, "下载任务不能为空!!");
@@ -85,8 +85,8 @@ public class ExecutePool implements IPool {
*/
public void setDownloadNum(int downloadNum) {
try {
- ArrayBlockingQueue temp = new ArrayBlockingQueue<>(downloadNum);
- Task task;
+ ArrayBlockingQueue temp = new ArrayBlockingQueue<>(downloadNum);
+ DownloadTask task;
while ((task = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS)) != null) {
temp.offer(task);
}
@@ -103,7 +103,7 @@ public class ExecutePool implements IPool {
*
* @param newTask 新下载任务
*/
- private boolean putNewTask(Task newTask) {
+ private boolean putNewTask(DownloadTask newTask) {
String url = newTask.getDownloadEntity().getDownloadUrl();
boolean s = mExecuteQueue.offer(newTask);
Log.w(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
@@ -119,7 +119,7 @@ public class ExecutePool implements IPool {
*/
private boolean pollFirstTask() {
try {
- Task oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
+ DownloadTask oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (oldTask == null) {
Log.e(TAG, "移除任务失败");
return false;
@@ -135,10 +135,10 @@ public class ExecutePool implements IPool {
return true;
}
- @Override public Task pollTask() {
+ @Override public DownloadTask pollTask() {
synchronized (LOCK) {
try {
- Task task = null;
+ DownloadTask task = null;
task = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (task != null) {
String url = task.getDownloadEntity().getDownloadUrl();
@@ -152,7 +152,7 @@ public class ExecutePool implements IPool {
}
}
- @Override public Task getTask(String downloadUrl) {
+ @Override public DownloadTask getTask(String downloadUrl) {
synchronized (LOCK) {
if (TextUtils.isEmpty(downloadUrl)) {
Log.e(TAG, "请传入有效的下载链接");
@@ -163,7 +163,7 @@ public class ExecutePool implements IPool {
}
}
- @Override public boolean removeTask(Task task) {
+ @Override public boolean removeTask(DownloadTask task) {
synchronized (LOCK) {
if (task == null) {
Log.e(TAG, "任务不能为空");
@@ -183,7 +183,7 @@ public class ExecutePool implements IPool {
return false;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
- Task task = mExecuteArray.get(key);
+ DownloadTask task = mExecuteArray.get(key);
mExecuteArray.remove(key);
return mExecuteQueue.remove(task);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/download/scheduler/DownloadSchedulers.java
similarity index 92%
rename from Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/scheduler/DownloadSchedulers.java
index 3a11b779..f9db071b 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/scheduler/DownloadSchedulers.java
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.scheduler;
+package com.arialyy.aria.core.download.scheduler;
import android.os.CountDownTimer;
import android.os.Message;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.queue.ITaskQueue;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.queue.ITaskQueue;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.Configuration;
import java.util.Iterator;
import java.util.Map;
@@ -108,7 +108,7 @@ public class DownloadSchedulers implements IDownloadSchedulers {
}
@Override public boolean handleMessage(Message msg) {
- Task task = (Task) msg.obj;
+ DownloadTask task = (DownloadTask) msg.obj;
if (task == null) {
Log.e(TAG, "请传入下载任务");
return true;
@@ -140,7 +140,7 @@ public class DownloadSchedulers implements IDownloadSchedulers {
*
* @param state 状态
*/
- private void callback(int state, Task task) {
+ private void callback(int state, DownloadTask task) {
if (mSchedulerListeners.size() > 0) {
//if (!TextUtils.isEmpty(task.getTargetName())) {
// callback(state, task, mSchedulerListeners.get(task.getTargetName()));
@@ -152,7 +152,7 @@ public class DownloadSchedulers implements IDownloadSchedulers {
}
}
- private void callback(int state, Task task, OnSchedulerListener listener) {
+ private void callback(int state, DownloadTask task, OnSchedulerListener listener) {
if (listener != null) {
if (task == null) {
Log.e(TAG, "TASK 为null,回调失败");
@@ -201,7 +201,7 @@ public class DownloadSchedulers implements IDownloadSchedulers {
@Override public void onFinish() {
if (entity.getFailNum() <= config.getReTryNum()) {
- Task task = mQueue.getTask(entity);
+ DownloadTask task = mQueue.getTask(entity);
mQueue.reTryStart(task);
try {
Thread.sleep(config.getReTryInterval());
@@ -222,7 +222,7 @@ public class DownloadSchedulers implements IDownloadSchedulers {
* @param entity 通过Handler传递的下载实体
*/
@Override public void startNextTask(DownloadEntity entity) {
- Task newTask = mQueue.getNextTask();
+ DownloadTask newTask = mQueue.getNextTask();
if (newTask == null) {
Log.w(TAG, "没有下一任务");
return;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/download/scheduler/IDownloadSchedulers.java
similarity index 94%
rename from Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/scheduler/IDownloadSchedulers.java
index 5b38ceb5..98997122 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/scheduler/IDownloadSchedulers.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.scheduler;
+package com.arialyy.aria.core.download.scheduler;
import android.os.Handler;
-import com.arialyy.aria.core.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadEntity;
/**
* Created by “AriaLyy@outlook.com” on 2016/11/2.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/scheduler/OnSchedulerListener.java
similarity index 66%
rename from Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/scheduler/OnSchedulerListener.java
index baa584af..c83d2839 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/scheduler/OnSchedulerListener.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core.scheduler;
+package com.arialyy.aria.core.download.scheduler;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Target处理任务监听
@@ -24,40 +24,40 @@ public interface OnSchedulerListener {
/**
* 任务预加载
*/
- public void onTaskPre(Task task);
+ public void onTaskPre(DownloadTask task);
/**
* 任务恢复下载
*/
- public void onTaskResume(Task task);
+ public void onTaskResume(DownloadTask task);
/**
* 任务开始
*/
- public void onTaskStart(Task task);
+ public void onTaskStart(DownloadTask task);
/**
* 任务停止
*/
- public void onTaskStop(Task task);
+ public void onTaskStop(DownloadTask task);
/**
* 任务取消
*/
- public void onTaskCancel(Task task);
+ public void onTaskCancel(DownloadTask task);
/**
* 任务下载失败
*/
- public void onTaskFail(Task task);
+ public void onTaskFail(DownloadTask task);
/**
* 任务完成
*/
- public void onTaskComplete(Task task);
+ public void onTaskComplete(DownloadTask task);
/**
* 任务执行中
*/
- public void onTaskRunning(Task task);
+ public void onTaskRunning(DownloadTask task);
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/ConnectionHelp.java
similarity index 96%
rename from Aria/src/main/java/com/arialyy/aria/core/task/ConnectionHelp.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/ConnectionHelp.java
index bf0b44e9..1f6bd47a 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/ConnectionHelp.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/ConnectionHelp.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
-import com.arialyy.aria.core.DownloadTaskEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.util.CAConfiguration;
import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadListener.java
similarity index 96%
rename from Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadListener.java
index bab38eae..e012df53 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadListener.java
@@ -15,7 +15,7 @@
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
class DownloadListener implements IDownloadListener {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadStateConstance.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadStateConstance.java
similarity index 97%
rename from Aria/src/main/java/com/arialyy/aria/core/task/DownloadStateConstance.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadStateConstance.java
index 00da093b..785312bc 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadStateConstance.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadStateConstance.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
/**
* Created by lyy on 2017/1/18.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/Task.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadTask.java
similarity index 93%
rename from Aria/src/main/java/com/arialyy/aria/core/task/Task.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadTask.java
index 5f930cb3..b56defad 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/Task.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadTask.java
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.scheduler.DownloadSchedulers;
-import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
-import com.arialyy.aria.core.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.scheduler.DownloadSchedulers;
+import com.arialyy.aria.core.download.scheduler.IDownloadSchedulers;
+import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Configuration;
@@ -34,8 +34,8 @@ import java.lang.ref.WeakReference;
* Created by lyy on 2016/8/11.
* 下载任务类
*/
-public class Task {
- public static final String TAG = "Task";
+public class DownloadTask {
+ public static final String TAG = "DownloadTask";
/**
* 产生该任务对象的hash码
*/
@@ -47,7 +47,7 @@ public class Task {
private Context mContext;
private IDownloadUtil mUtil;
- private Task(Context context, DownloadTaskEntity taskEntity, Handler outHandler) {
+ private DownloadTask(Context context, DownloadTaskEntity taskEntity, Handler outHandler) {
mContext = context.getApplicationContext();
mTaskEntity = taskEntity;
mEntity = taskEntity.downloadEntity;
@@ -199,8 +199,8 @@ public class Task {
return this;
}
- public Task build() {
- Task task = new Task(context, taskEntity, outHandler);
+ public DownloadTask build() {
+ DownloadTask task = new DownloadTask(context, taskEntity, outHandler);
task.setTargetName(targetName);
taskEntity.downloadEntity.save();
return task;
@@ -212,7 +212,7 @@ public class Task {
*/
private static class DListener extends DownloadListener {
WeakReference outHandler;
- WeakReference wTask;
+ WeakReference wTask;
Context context;
Intent sendIntent;
long INTERVAL = 1024 * 10; //10k大小的间隔
@@ -221,9 +221,9 @@ public class Task {
long INTERVAL_TIME = 1000; //1m更新周期
boolean isFirst = true;
DownloadEntity downloadEntity;
- Task task;
+ DownloadTask task;
- DListener(Context context, Task task, Handler outHandler) {
+ DListener(Context context, DownloadTask task, Handler outHandler) {
this.context = context;
this.outHandler = new WeakReference<>(outHandler);
this.wTask = new WeakReference<>(task);
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadTaskFactory.java
similarity index 65%
rename from Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadTaskFactory.java
index a27217fb..2ac06054 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadTaskFactory.java
@@ -14,30 +14,30 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
import android.content.Context;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.scheduler.IDownloadSchedulers;
/**
* Created by lyy on 2016/8/18.
* 任务工厂
*/
-public class TaskFactory {
- private static final String TAG = "TaskFactory";
+public class DownloadTaskFactory {
+ private static final String TAG = "DownloadTaskFactory";
private static final Object LOCK = new Object();
- private static volatile TaskFactory INSTANCE = null;
+ private static volatile DownloadTaskFactory INSTANCE = null;
- private TaskFactory() {
+ private DownloadTaskFactory() {
}
- public static TaskFactory getInstance() {
+ public static DownloadTaskFactory getInstance() {
if (INSTANCE == null) {
synchronized (LOCK) {
- INSTANCE = new TaskFactory();
+ INSTANCE = new DownloadTaskFactory();
}
}
return INSTANCE;
@@ -49,7 +49,7 @@ public class TaskFactory {
* @param entity 下载任务实体{@link DownloadTaskEntity}
* @param schedulers {@link IDownloadSchedulers}
*/
- public Task createTask(Context context, DownloadTaskEntity entity,
+ public DownloadTask createTask(Context context, DownloadTaskEntity entity,
IDownloadSchedulers schedulers) {
return createTask("", context, entity, schedulers);
}
@@ -58,9 +58,9 @@ public class TaskFactory {
* @param entity 下载任务实体{@link DownloadTaskEntity}
* @param schedulers {@link IDownloadSchedulers}
*/
- public Task createTask(String targetName, Context context, DownloadTaskEntity entity,
+ public DownloadTask createTask(String targetName, Context context, DownloadTaskEntity entity,
IDownloadSchedulers schedulers) {
- Task.Builder builder = new Task.Builder(targetName, context, entity);
+ DownloadTask.Builder builder = new DownloadTask.Builder(targetName, context, entity);
builder.setOutHandler(schedulers);
return builder.build();
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadUtil.java
similarity index 98%
rename from Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadUtil.java
index b38db976..cabef40a 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/DownloadUtil.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
import android.content.Context;
import android.util.Log;
import android.util.SparseArray;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.DownloadTaskEntity;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/IDownloadListener.java
similarity index 97%
rename from Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/IDownloadListener.java
index 037bd808..d63d52b3 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/IDownloadListener.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
/**
* 下载监听
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/IDownloadUtil.java
similarity index 94%
rename from Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/IDownloadUtil.java
index 5c4e29f6..348d9051 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/IDownloadUtil.java
@@ -15,13 +15,13 @@
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
/**
* Created by “AriaLyy@outlook.com” on 2016/10/31.
* 抽象的下载接口
*/
-public interface IDownloadUtil {
+interface IDownloadUtil {
/**
* 获取当前下载位置
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/SingleThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/task/SingleThreadTask.java
similarity index 99%
rename from Aria/src/main/java/com/arialyy/aria/core/task/SingleThreadTask.java
rename to Aria/src/main/java/com/arialyy/aria/core/download/task/SingleThreadTask.java
index 2f6afc82..8b954b41 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/SingleThreadTask.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/task/SingleThreadTask.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core.task;
+package com.arialyy.aria.core.download.task;
import android.util.Log;
import com.arialyy.aria.util.CommonUtil;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java
new file mode 100644
index 00000000..9b9b2528
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java
@@ -0,0 +1,12 @@
+package com.arialyy.aria.core.inf;
+
+/**
+ * Created by Aria.Lao on 2017/2/9.
+ */
+
+public interface ICmd {
+ /**
+ * 执行命令
+ */
+ public abstract void executeCmd();
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/IReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java
similarity index 92%
rename from Aria/src/main/java/com/arialyy/aria/core/IReceiver.java
rename to Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java
index 6aebd8c4..8ead3163 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/IReceiver.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core;
+package com.arialyy.aria.core.inf;
/**
* Created by Aria.Lao on 2017/2/6.
*/
-interface IReceiver {
+public interface IReceiver {
/**
* Receiver 销毁
*/
diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/IUploadListener.java b/Aria/src/main/java/com/arialyy/aria/core/upload/IUploadListener.java
new file mode 100644
index 00000000..98f7e6ad
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/IUploadListener.java
@@ -0,0 +1,11 @@
+package com.arialyy.aria.core.upload;
+
+/**
+ * Created by Aria.Lao on 2017/2/9.
+ * 上传监听
+ */
+
+public interface IUploadListener {
+
+ public void onFail();
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/MultipartUtility.java b/Aria/src/main/java/com/arialyy/aria/core/upload/MultipartUtility.java
new file mode 100644
index 00000000..fa6cd613
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/MultipartUtility.java
@@ -0,0 +1,150 @@
+package com.arialyy.aria.core.upload;
+
+import android.util.Log;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class MultipartUtility {
+
+ private final String boundary;
+ private static final String LINE_FEED = "\r\n";
+ private HttpURLConnection httpConn;
+ private String charset;
+ private OutputStream outputStream;
+ private PrintWriter writer;
+
+ /**
+ * This constructor initializes a new HTTP POST request with content type
+ * is set to multipart/form-data
+ *
+ * @param requestURL
+ * @param charset
+ * @throws IOException
+ */
+ public MultipartUtility(String requestURL, String charset)
+ throws IOException {
+ this.charset = charset;
+
+ // creates a unique boundary based on time stamp
+ boundary = "===" + System.currentTimeMillis() + "===";
+
+ URL url = new URL(requestURL);
+ Log.e("URL", "URL : " + requestURL.toString());
+ httpConn = (HttpURLConnection) url.openConnection();
+ httpConn.setUseCaches(false);
+ httpConn.setDoOutput(true); // indicates POST method
+ httpConn.setDoInput(true);
+ httpConn.setRequestProperty("Content-Type",
+ "multipart/form-data; boundary=" + boundary);
+ httpConn.setRequestProperty("User-Agent", "CodeJava Agent");
+ httpConn.setRequestProperty("Test", "Bonjour");
+ outputStream = httpConn.getOutputStream();
+ writer = new PrintWriter(new OutputStreamWriter(outputStream, charset),
+ true);
+ }
+
+ /**
+ * Adds a form field to the request
+ *
+ * @param name field name
+ * @param value field value
+ */
+ public void addFormField(String name, String value) {
+ writer.append("--" + boundary).append(LINE_FEED);
+ writer.append("Content-Disposition: form-data; name=\"" + name + "\"")
+ .append(LINE_FEED);
+ writer.append("Content-Type: text/plain; charset=" + charset).append(
+ LINE_FEED);
+ writer.append(LINE_FEED);
+ writer.append(value).append(LINE_FEED);
+ writer.flush();
+ }
+
+ /**
+ * Adds a upload file section to the request
+ *
+ * @param fieldName name attribute in
+ * @param uploadFile a File to be uploaded
+ * @throws IOException
+ */
+ public void addFilePart(String fieldName, File uploadFile)
+ throws IOException {
+ String fileName = uploadFile.getName();
+ writer.append("--" + boundary).append(LINE_FEED);
+ writer.append(
+ "Content-Disposition: form-data; name=\"" + fieldName
+ + "\"; filename=\"" + fileName + "\"")
+ .append(LINE_FEED);
+ writer.append(
+ "Content-Type: "
+ + URLConnection.guessContentTypeFromName(fileName))
+ .append(LINE_FEED);
+ writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
+ writer.append(LINE_FEED);
+ writer.flush();
+
+ FileInputStream inputStream = new FileInputStream(uploadFile);
+ byte[] buffer = new byte[4096];
+ int bytesRead = -1;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ outputStream.flush();
+ inputStream.close();
+
+ writer.append(LINE_FEED);
+ writer.flush();
+ }
+
+ /**
+ * Adds a header field to the request.
+ *
+ * @param name - name of the header field
+ * @param value - value of the header field
+ */
+ public void addHeaderField(String name, String value) {
+ writer.append(name + ": " + value).append(LINE_FEED);
+ writer.flush();
+ }
+
+ /**
+ * Completes the request and receives response from the server.
+ *
+ * @return a list of Strings as response in case the server returned
+ * status OK, otherwise an exception is thrown.
+ * @throws IOException
+ */
+ public String finish() throws IOException {
+ StringBuffer response = new StringBuffer();
+
+ writer.append(LINE_FEED).flush();
+ writer.append("--" + boundary + "--").append(LINE_FEED);
+ writer.close();
+
+ // checks server's status code first
+ int status = httpConn.getResponseCode();
+ if (status == HttpURLConnection.HTTP_OK) {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ httpConn.getInputStream()));
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ response.append(line);
+ }
+ reader.close();
+ httpConn.disconnect();
+ } else {
+ throw new IOException("Server returned non-OK status: " + status);
+ }
+
+ return response.toString();
+ }
+}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
new file mode 100644
index 00000000..014aba7a
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
@@ -0,0 +1,30 @@
+package com.arialyy.aria.core.upload;
+
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.orm.DbEntity;
+
+/**
+ * Created by Aria.Lao on 2017/2/9.
+ * 上传文件实体
+ */
+public class UploadEntity {
+
+ private String filePath; //文件路径
+ private String fileName; //文件名
+
+ public String getFilePath() {
+ return filePath;
+ }
+
+ public void setFilePath(String filePath) {
+ this.filePath = filePath;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
similarity index 91%
rename from Aria/src/main/java/com/arialyy/aria/core/UploadReceiver.java
rename to Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
index 51eff28d..aa012d22 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/UploadReceiver.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.arialyy.aria.core;
+package com.arialyy.aria.core.upload;
+
+import com.arialyy.aria.core.inf.IReceiver;
/**
* Created by Aria.Lao on 2017/2/6.
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
new file mode 100644
index 00000000..c23cd2be
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java
@@ -0,0 +1,22 @@
+package com.arialyy.aria.core.upload;
+
+import com.arialyy.aria.core.RequestEnum;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by Aria.Lao on 2017/2/9.
+ */
+
+public class UploadTaskEntity {
+ public UploadEntity uploadEntity;
+ public RequestEnum requestEnum = RequestEnum.GET;
+ public String uploadUrl; //上传路径
+ public String uploadKey; //文件上传需要的key
+ public String contentType = "multipart/form-data"; //上传的文件类型
+ public Map headers = new HashMap<>();
+
+ public UploadTaskEntity(UploadEntity downloadEntity) {
+ this.uploadEntity = downloadEntity;
+ }
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
new file mode 100644
index 00000000..2a3b1020
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
@@ -0,0 +1,122 @@
+package com.arialyy.aria.core.upload;
+
+import android.util.Log;
+import com.arialyy.aria.util.CheckUtil;
+import java.io.BufferedInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+/**
+ * Created by Aria.Lao on 2017/2/9.
+ * 上传工具
+ */
+public class UploadUtil implements Runnable {
+ private static final String TAG = "UploadUtil";
+ private UploadEntity mUploadEntity;
+ private UploadTaskEntity mTaskEntity;
+ private IUploadListener mListener;
+
+
+ public UploadUtil(UploadTaskEntity taskEntity, IUploadListener listener) {
+ mTaskEntity = taskEntity;
+ CheckUtil.checkUploadEntity(taskEntity.uploadEntity);
+ mUploadEntity = taskEntity.uploadEntity;
+ mListener = listener;
+ }
+
+ public void start() {
+ new Thread(this).start();
+ }
+
+ @Override public void run() {
+ File file = new File(mUploadEntity.getFilePath());
+ if (!file.exists()) {
+ Log.e(TAG, "【" + mUploadEntity.getFilePath() + "】,文件不存在。");
+ mListener.onFail();
+ return;
+ }
+ String BOUNDARY = UUID.randomUUID().toString(); // 边界标识 随机生成
+ String PREFIX = "--", LINE_END = "\r\n";
+ String CONTENT_TYPE = "multipart/form-data"; // 内容类型
+ try {
+ HttpURLConnection conn = (HttpURLConnection) new URL(mTaskEntity.uploadUrl).openConnection();
+ conn.setReadTimeout(5000);
+ conn.setConnectTimeout(5000);
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+ conn.setUseCaches(false);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Charset", "utf-8"); // 设置编码
+ conn.setRequestProperty("connection", "keep-alive");
+ //conn.setRequestProperty("Content-Type", CONTENT_TYPE + ";boundary=" + BOUNDARY);
+ conn.setRequestProperty("Content-Type", mTaskEntity.contentType + ";boundary=" + BOUNDARY);
+
+ Set keys = mTaskEntity.headers.keySet();
+ for (String key : keys) {
+ conn.setRequestProperty(key, mTaskEntity.headers.get(key));
+ }
+
+ OutputStream outputSteam = conn.getOutputStream();
+ DataOutputStream dos = new DataOutputStream(outputSteam);
+ StringBuilder sb = new StringBuilder();
+ sb.append(PREFIX);
+ sb.append(BOUNDARY);
+ sb.append(LINE_END);
+ sb.append("Content-Disposition: form-data; name=\"")
+ .append(mTaskEntity.uploadUrl)
+ .append("\"; filename=\"")
+ .append(file.getName())
+ .append("\"")
+ .append(LINE_END);
+ sb.append("Content-Type:")
+ .append(mTaskEntity.contentType)
+ .append("; charset=utf-8")
+ .append(LINE_END);
+ sb.append(LINE_END);
+ dos.write(sb.toString().getBytes());
+
+ InputStream is = new FileInputStream(file);
+ byte[] bytes = new byte[1024];
+ int len = 0;
+ while ((len = is.read(bytes)) != -1) {
+ dos.write(bytes, 0, len);
+ }
+ is.close();
+ dos.write(LINE_END.getBytes());
+ byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINE_END).getBytes();
+ dos.write(end_data);
+ dos.flush();
+ dos.close();
+
+ int res = conn.getResponseCode();
+ if (res == 200) {
+ BufferedInputStream inputStream = new BufferedInputStream(conn.getInputStream());
+ byte[] buf = new byte[1024];
+ StringBuilder stringBuilder = new StringBuilder();
+ while (inputStream.read(buf) > 0) {
+ stringBuilder.append(new String(buf, 0, buf.length));
+ }
+ String data = stringBuilder.toString();
+ Log.d(TAG, data);
+ //L.j(data);
+ //absResponse.onResponse(data);
+ } else {
+ //absResponse.onError("error");
+ }
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
index 16ba16ba..08d56d48 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
@@ -18,7 +18,8 @@ package com.arialyy.aria.util;
import android.text.TextUtils;
import android.util.Log;
-import com.arialyy.aria.core.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.FileException;
import java.io.File;
import java.util.regex.Matcher;
@@ -73,21 +74,32 @@ public class CheckUtil {
if (TextUtils.isEmpty(downloadUrl)) throw new IllegalArgumentException("下载链接不能为null");
}
+ /**
+ * 检查上传实体是否合法
+ */
+ public static void checkUploadEntity(UploadEntity entity) {
+ if (entity == null) {
+ throw new NullPointerException("上传实体不能为空");
+ }
+ if (TextUtils.isEmpty(entity.getFilePath())) {
+ throw new IllegalArgumentException("上传文件路径不能为空");
+ } else if (TextUtils.isEmpty(entity.getFileName())) {
+ throw new IllegalArgumentException("上传文件名不能为空");
+ }
+ }
+
/**
* 检测下载实体是否合法
*
* @param entity 下载实体
* @return 合法(true)
*/
- public static boolean checkDownloadEntity(DownloadEntity entity) {
+ public static void checkDownloadEntity(DownloadEntity entity) {
if (entity == null) {
- Log.w(TAG, "下载实体不能为空");
- return false;
+ throw new NullPointerException("下载实体不能为空");
} else if (TextUtils.isEmpty(entity.getDownloadUrl())) {
- Log.w(TAG, "下载链接不能为空");
- return false;
+ throw new IllegalArgumentException("下载链接不能为空");
} else if (TextUtils.isEmpty(entity.getFileName())) {
- //Log.w(TAG, "文件名不能为空");
throw new FileException("文件名不能为null");
} else if (TextUtils.isEmpty(entity.getDownloadPath())) {
throw new FileException("文件保存路径不能为null");
@@ -102,6 +114,5 @@ public class CheckUtil {
dPath += fileName;
entity.setDownloadPath(dPath);
}
- return true;
}
}
\ No newline at end of file
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 e640883e..43ece013 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
@@ -21,10 +21,9 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
-import com.arialyy.aria.core.DownloadTaskEntity;
-import com.arialyy.aria.core.command.download.CmdFactory;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.command.download.IDownloadCmd;
+import com.arialyy.aria.core.download.DownloadTaskEntity;
+import com.arialyy.aria.core.download.command.CmdFactory;
+import com.arialyy.aria.core.download.command.IDownloadCmd;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 681656f0..5aacf3df 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -14,8 +14,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
+
diff --git a/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java b/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java
index 6f3ac0d5..76788d97 100644
--- a/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java
+++ b/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java
@@ -7,10 +7,10 @@ import android.widget.Button;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;
-import com.arialyy.aria.core.DownloadTarget;
+import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog;
import com.arialyy.simple.R;
@@ -86,26 +86,26 @@ public class DownloadDialog extends AbsDialog {
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
- @Override public void onTaskPre(Task task) {
+ @Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
setBtState(false);
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
setBtState(true);
mSpeed.setText("0.0kb/s");
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
setBtState(true);
mPb.setProgress(0);
mSpeed.setText("0.0kb/s");
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
long current = task.getCurrentProgress();
long len = task.getFileSize();
diff --git a/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java b/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java
index a97e03a0..7f2ac88f 100644
--- a/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java
+++ b/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java
@@ -7,10 +7,10 @@ import android.widget.Button;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;
-import com.arialyy.aria.core.DownloadTarget;
+import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsFragment;
import com.arialyy.simple.R;
@@ -90,26 +90,26 @@ public class DownloadFragment extends AbsFragment {
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
- @Override public void onTaskPre(Task task) {
+ @Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
setBtState(false);
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
setBtState(true);
mSpeed.setText("0.0kb/s");
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
setBtState(true);
mPb.setProgress(0);
mSpeed.setText("0.0kb/s");
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
long current = task.getCurrentProgress();
long len = task.getFileSize();
diff --git a/app/src/main/java/com/arialyy/simple/module/DownloadModule.java b/app/src/main/java/com/arialyy/simple/module/DownloadModule.java
index fad25862..4a084193 100644
--- a/app/src/main/java/com/arialyy/simple/module/DownloadModule.java
+++ b/app/src/main/java/com/arialyy/simple/module/DownloadModule.java
@@ -23,7 +23,7 @@ import android.content.IntentFilter;
import android.os.Environment;
import android.os.Handler;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.AndroidUtils;
import com.arialyy.frame.util.StringUtil;
diff --git a/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java b/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java
index 30b98b98..69fb7ba9 100644
--- a/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java
@@ -5,7 +5,7 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
@@ -40,45 +40,45 @@ public class DownloadActivity extends BaseActivity {
}
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
- @Override public void onTaskPre(Task task) {
+ @Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
L.d(TAG, "download pre");
mAdapter.updateState(task.getDownloadEntity());
}
- @Override public void onTaskStart(Task task) {
+ @Override public void onTaskStart(DownloadTask task) {
super.onTaskStart(task);
L.d(TAG, "download start");
mAdapter.updateState(task.getDownloadEntity());
}
- @Override public void onTaskResume(Task task) {
+ @Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task);
L.d(TAG, "download resume");
mAdapter.updateState(task.getDownloadEntity());
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
mAdapter.setProgress(task.getDownloadEntity());
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
mAdapter.updateState(task.getDownloadEntity());
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
mAdapter.updateState(task.getDownloadEntity());
}
- @Override public void onTaskComplete(Task task) {
+ @Override public void onTaskComplete(DownloadTask task) {
super.onTaskComplete(task);
mAdapter.updateState(task.getDownloadEntity());
}
- @Override public void onTaskFail(Task task) {
+ @Override public void onTaskFail(DownloadTask task) {
super.onTaskFail(task);
L.d(TAG, "download fail");
}
diff --git a/app/src/main/java/com/arialyy/simple/multi_task/DownloadAdapter.java b/app/src/main/java/com/arialyy/simple/multi_task/DownloadAdapter.java
index 75494f48..49518df7 100644
--- a/app/src/main/java/com/arialyy/simple/multi_task/DownloadAdapter.java
+++ b/app/src/main/java/com/arialyy/simple/multi_task/DownloadAdapter.java
@@ -25,7 +25,7 @@ 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.DownloadEntity;
+import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
diff --git a/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java b/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java
index 4b7f6aae..fcad3a1b 100644
--- a/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java
+++ b/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java
@@ -24,7 +24,7 @@ import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;
@@ -89,26 +89,26 @@ public class MultiTaskActivity extends BaseActivity {
private class DownloadListener extends Aria.SimpleSchedulerListener {
- @Override public void onTaskStart(Task task) {
+ @Override public void onTaskStart(DownloadTask task) {
super.onTaskStart(task);
mAdapter.updateBtState(task.getDownloadUrl(), false);
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
}
- @Override public void onTaskResume(Task task) {
+ @Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task);
mAdapter.updateBtState(task.getDownloadUrl(), false);
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
mAdapter.updateBtState(task.getDownloadUrl(), true);
}
- @Override public void onTaskComplete(Task task) {
+ @Override public void onTaskComplete(DownloadTask task) {
super.onTaskComplete(task);
mAdapter.updateBtState(task.getDownloadUrl(), true);
}
diff --git a/app/src/main/java/com/arialyy/simple/notification/SimpleNotification.java b/app/src/main/java/com/arialyy/simple/notification/SimpleNotification.java
index b71ca512..248fcfca 100644
--- a/app/src/main/java/com/arialyy/simple/notification/SimpleNotification.java
+++ b/app/src/main/java/com/arialyy/simple/notification/SimpleNotification.java
@@ -5,7 +5,7 @@ import android.content.Context;
import android.os.Environment;
import android.support.v4.app.NotificationCompat;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.simple.R;
/**
@@ -59,19 +59,19 @@ public class SimpleNotification {
mManager = manager;
}
- @Override public void onTaskStart(Task task) {
+ @Override public void onTaskStart(DownloadTask task) {
super.onTaskStart(task);
}
- @Override public void onTaskPre(Task task) {
+ @Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
long len = task.getFileSize();
int p = (int) (task.getCurrentProgress() * 100 / len);
@@ -81,7 +81,7 @@ public class SimpleNotification {
}
}
- @Override public void onTaskComplete(Task task) {
+ @Override public void onTaskComplete(DownloadTask task) {
super.onTaskComplete(task);
if (mBuilder != null) {
mBuilder.setProgress(100, 100, false);
@@ -89,7 +89,7 @@ public class SimpleNotification {
}
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
}
}
diff --git a/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java b/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java
index 171c52ab..744a7748 100644
--- a/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java
+++ b/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java
@@ -9,10 +9,10 @@ import android.widget.Button;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;
-import com.arialyy.aria.core.DownloadTarget;
+import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsPopupWindow;
import com.arialyy.simple.R;
@@ -88,26 +88,26 @@ public class DownloadPopupWindow extends AbsPopupWindow {
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
- @Override public void onTaskPre(Task task) {
+ @Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
setBtState(false);
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
setBtState(true);
mSpeed.setText("0.0kb/s");
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
setBtState(true);
mPb.setProgress(0);
mSpeed.setText("0.0kb/s");
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
long current = task.getCurrentProgress();
long len = task.getFileSize();
diff --git a/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java
index b039d3a3..db9cb4bc 100644
--- a/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java
+++ b/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java
@@ -30,10 +30,10 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
-import com.arialyy.aria.core.DownloadTarget;
+import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.DownloadEntity;
-import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.core.download.DownloadEntity;
+import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
@@ -76,7 +76,7 @@ public class SingleTaskActivity extends BaseActivity {
super.handleMessage(msg);
switch (msg.what) {
case DOWNLOAD_RUNNING:
- Task task = (Task) msg.obj;
+ DownloadTask task = (DownloadTask) msg.obj;
long current = task.getCurrentProgress();
long len = task.getFileSize();
if (len == 0) {
@@ -208,33 +208,33 @@ public class SingleTaskActivity extends BaseActivity {
}
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
- @Override public void onTaskStart(Task task) {
+ @Override public void onTaskStart(DownloadTask task) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
.sendToTarget();
}
- @Override public void onTaskResume(Task task) {
+ @Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task);
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getFileSize()).sendToTarget();
}
- @Override public void onTaskStop(Task task) {
+ @Override public void onTaskStop(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
}
- @Override public void onTaskCancel(Task task) {
+ @Override public void onTaskCancel(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
}
- @Override public void onTaskFail(Task task) {
+ @Override public void onTaskFail(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
}
- @Override public void onTaskComplete(Task task) {
+ @Override public void onTaskComplete(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
}
- @Override public void onTaskRunning(Task task) {
+ @Override public void onTaskRunning(DownloadTask task) {
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget();
}
}
diff --git a/app/src/main/java/com/arialyy/simple/upload.java b/app/src/main/java/com/arialyy/simple/upload.java
new file mode 100644
index 00000000..b88fa5a6
--- /dev/null
+++ b/app/src/main/java/com/arialyy/simple/upload.java
@@ -0,0 +1,36 @@
+package com.arialyy.simple;
+
+import android.view.View;
+import com.arialyy.aria.core.upload.IUploadListener;
+import com.arialyy.aria.core.upload.UploadEntity;
+import com.arialyy.aria.core.upload.UploadTaskEntity;
+import com.arialyy.aria.core.upload.UploadUtil;
+import com.arialyy.simple.base.BaseActivity;
+import com.arialyy.simple.databinding.ActivityUploadBinding;
+
+/**
+ * Created by Aria.Lao on 2017/2/9.
+ */
+
+public class upload extends BaseActivity{
+ @Override protected int setLayoutId() {
+ return R.layout.activity_upload;
+
+ }
+
+ public void onClick(View view){
+ UploadEntity entity = new UploadEntity();
+ entity.setFilePath("/sdcard/Download/test.pdf");
+ entity.setFileName("test.pdf");
+ UploadTaskEntity taskEntity = new UploadTaskEntity(entity);
+ taskEntity.uploadUrl = "http://172.21.1.160:8080/upload";
+ taskEntity.uploadKey = "file";
+ UploadUtil util = new UploadUtil(taskEntity, new IUploadListener() {
+ @Override public void onFail() {
+
+ }
+ });
+ util.start();
+ }
+
+}
diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml
new file mode 100644
index 00000000..9782fff3
--- /dev/null
+++ b/app/src/main/res/layout/activity_upload.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+