diff --git a/.gitignore b/.gitignore
index 7247f19d..cda18dcf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@
.externalNativeBuild
.idea/misc.xml
.gradle
+/.idea
\ No newline at end of file
diff --git a/Aria/build.gradle b/Aria/build.gradle
index 7460d99b..b32a7e32 100644
--- a/Aria/build.gradle
+++ b/Aria/build.gradle
@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
- versionCode 58
- versionName "2.3.0"
+ versionCode 80
+ versionName "2.3.2"
}
buildTypes {
release {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/AMReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/AMReceiver.java
index 8205242d..f1714319 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/AMReceiver.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/AMReceiver.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.arialyy.aria.core;
import com.arialyy.aria.core.scheduler.OnSchedulerListener;
/**
+ * Created by lyy on 2016/12/5.
* AM 接收器
*/
public class AMReceiver {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/AMTarget.java b/Aria/src/main/java/com/arialyy/aria/core/AMTarget.java
index cc1da45d..b5fdd61c 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/AMTarget.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/AMTarget.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.arialyy.aria.core;
import com.arialyy.aria.core.command.CmdFactory;
@@ -9,7 +24,8 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Created by utstarcom on 2016/12/5.
+ * Created by lyy on 2016/12/5.
+ * https://github.com/AriaLyy/Aria
*/
public class AMTarget {
private AMReceiver receiver;
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 e6557e1f..2d2b3aaf 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@ package com.arialyy.aria.core;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
+import android.app.Dialog;
+import android.app.DialogFragment;
import android.app.Fragment;
import android.app.Service;
import android.content.Context;
@@ -26,15 +28,31 @@ import android.os.Build;
/**
* Created by lyy on 2016/12/1.
+ * https://github.com/AriaLyy/Aria
* Aria启动,管理全局任务
+ *
+ *
+ * DownloadEntity mEntity = new DownloadEntity();
+ * mEntity.setFileName(fileName); //设置文件名
+ * mEntity.setDownloadUrl(downloadUrl); //设置下载链接
+ * mEntity.setDownloadPath(downloadPath); //设置存放路径
+ *
+ * //启动下载
+ * Aria.whit(this).load(mEntity).start();
+ *
+ *
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
private Aria() {
}
+ /**
+ * 接受Activity、Service、Application
+ */
public static AMReceiver whit(Context context) {
- if (context == null) throw new IllegalArgumentException("context 不能为 null");
+ //if (context == null) throw new IllegalArgumentException("context 不能为 null");
+ checkNull(context);
if (context instanceof Activity
|| context instanceof Service
|| context instanceof Application) {
@@ -44,12 +62,31 @@ import android.os.Build;
}
}
+ /**
+ * 处理Fragment、或者DialogFragment
+ */
public static AMReceiver whit(Fragment fragment) {
+ checkNull(fragment);
return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
: fragment.getActivity()).get(fragment);
}
+ /**
+ * 处理Dialog
+ */
+ public static AMReceiver whit(Dialog dialog) {
+ checkNull(dialog);
+ return AriaManager.getInstance(dialog.getContext()).get(dialog);
+ }
+
+ private static void checkNull(Object obj) {
+ if (obj == null) throw new IllegalArgumentException("不能传入空对象");
+ }
+
+ /**
+ * 处理通用事件
+ */
public static AriaManager get(Context context) {
if (context == null) throw new IllegalArgumentException("context 不能为 null");
if (context instanceof Activity
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 346b0ab1..8310d4b0 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
@@ -1,15 +1,38 @@
+/*
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.arialyy.aria.core;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
+import android.app.Dialog;
import android.app.Service;
import android.content.Context;
+import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
+import android.os.Message;
+import android.support.v4.app.Fragment;
+import android.text.TextUtils;
+import android.util.Log;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.command.IDownloadCmd;
+import com.arialyy.aria.util.Configuration;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -18,14 +41,16 @@ import java.util.Set;
/**
* Created by lyy on 2016/12/1.
+ * https://github.com/AriaLyy/Aria
* Aria管理器,任务操作在这里执行
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
- private static final Object LOCK = new Object();
- private static volatile AriaManager INSTANCE = null;
- private Map mTargets = new HashMap<>();
+ private static final String TAG = "AriaManager";
+ private static final Object LOCK = new Object();
+ private static volatile AriaManager INSTANCE = null;
+ private Map mTargets = new HashMap<>();
private DownloadManager mManager;
- private LifeCallback mLifeCallback;
+ private LifeCallback mLifeCallback;
private AriaManager(Context context) {
regAppLifeCallback(context);
@@ -46,13 +71,21 @@ import java.util.Set;
}
/**
- * 设置同时下载的任务数
+ * 获取下载列表
+ */
+ public List getDownloadList() {
+ return DownloadEntity.findAllData(DownloadEntity.class);
+ }
+
+ /**
+ * 通过下载链接获取下载实体
*/
- public void setDownloadNum(int num){
- if (num <= 0){
- throw new IllegalArgumentException("下载任务数不能小于1");
+ public DownloadEntity getDownloadEntity(String downloadUrl) {
+ if (TextUtils.isEmpty(downloadUrl)) {
+ throw new IllegalArgumentException("下载链接不能为null");
}
- mManager.getTaskQueue().setDownloadNum(num);
+ return DownloadEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
+ new String[] { downloadUrl });
}
/**
@@ -60,7 +93,7 @@ import java.util.Set;
*/
public void stopAllTask() {
List allEntity = mManager.getAllDownloadEntity();
- List stopCmds = new ArrayList<>();
+ List stopCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
stopCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_STOP));
@@ -69,12 +102,58 @@ import java.util.Set;
mManager.setCmds(stopCmds).exe();
}
+ /**
+ * 设置下载超时时间
+ */
+ @Deprecated private AriaManager setTimeOut(int timeOut) {
+ Configuration.getInstance().setTimeOut(timeOut);
+ return this;
+ }
+
+ /**
+ * 设置下载失败重试次数
+ */
+ public AriaManager setReTryNum(int reTryNum) {
+ Configuration.getInstance().setReTryNum(reTryNum);
+ return this;
+ }
+
+ /**
+ * 设置下载失败重试间隔
+ */
+ public AriaManager setReTryInterval(int interval) {
+ Configuration.getInstance().setReTryInterval(interval);
+ return this;
+ }
+
+ /**
+ * 是否打开下载广播
+ */
+ public AriaManager openBroadcast(boolean open) {
+ Configuration.getInstance().setOpenBroadcast(open);
+ return this;
+ }
+
+ /**
+ * 设置最大下载数,最大下载数不能小于1
+ *
+ * @param maxDownloadNum 最大下载数
+ */
+ public AriaManager setMaxDownloadNum(int maxDownloadNum) {
+ if (maxDownloadNum < 1) {
+ Log.w(TAG, "最大任务数不能小于 1");
+ return this;
+ }
+ mManager.getTaskQueue().setDownloadNum(maxDownloadNum);
+ return this;
+ }
+
/**
* 删除所有任务
*/
public void cancelAllTask() {
- List allEntity = mManager.getAllDownloadEntity();
- List cancelCmds = new ArrayList<>();
+ List allEntity = mManager.getAllDownloadEntity();
+ List cancelCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
cancelCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_CANCEL));
}
@@ -88,16 +167,56 @@ import java.util.Set;
}
private AMReceiver putTarget(Object obj) {
- String clsName = obj.getClass().getName();
- AMReceiver target = mTargets.get(clsName);
+ String clsName = obj.getClass().getName();
+ AMReceiver target = mTargets.get(clsName);
if (target == null) {
target = new AMReceiver();
target.obj = obj;
- mTargets.put(clsName, target);
+ String key = "";
+ if (obj instanceof android.support.v4.app.Fragment) {
+ key = "_" + ((Fragment) obj).getActivity().getClass().getName();
+ } else if (obj instanceof android.app.Fragment) {
+ key = "_" + ((android.app.Fragment) obj).getActivity().getClass().getName();
+ } else if (obj instanceof Dialog) {
+ Activity activity = ((Dialog) obj).getOwnerActivity();
+ if (activity != null) {
+ key = "_" + activity.getClass().getName();
+ }
+ handleDialogDialogLift((Dialog) obj);
+ }
+
+ if (!TextUtils.isEmpty(key)) {
+ mTargets.put(clsName, target);
+ }
}
return target;
}
+ /**
+ * 处理对话框取消或dismiss
+ */
+ private void handleDialogDialogLift(Dialog dialog) {
+ try {
+ Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage");
+ Message dismissMsg = (Message) dismissField.get(dialog);
+ //如果Dialog已经设置Dismiss事件,则查找cancel事件
+ if (dismissMsg != null) {
+ Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage");
+ Message cancelMsg = (Message) dismissField.get(dialog);
+ if (cancelMsg != null) {
+ Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露,"
+ + "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件");
+ } else {
+
+ }
+ } else {
+
+ }
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
private AMReceiver getTarget(Object obj) {
AMReceiver target = mTargets.get(obj.getClass().getName());
if (target == null) {
@@ -149,7 +268,8 @@ import java.util.Set;
@Override public void onActivityDestroyed(Activity activity) {
Set keys = mTargets.keySet();
for (String key : keys) {
- if (key.equals(activity.getClass().getName())) {
+ String clsName = activity.getClass().getName();
+ if (key.equals(clsName) || key.contains(clsName)) {
AMReceiver target = mTargets.get(key);
if (target.obj != null) {
if (target.obj instanceof Application || target.obj instanceof Service) break;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java
index 32b040c6..53b69824 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/DownloadEntity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java b/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java
index f6eb2b9e..19afbf70 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import com.arialyy.aria.orm.DbUtil;
import com.arialyy.aria.core.command.IDownloadCmd;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.orm.DbEntity;
+import com.arialyy.aria.util.Configuration;
import java.util.ArrayList;
import java.util.List;
@@ -82,21 +83,22 @@ public class DownloadManager {
private static final Object LOCK = new Object();
private static volatile DownloadManager INSTANCE = null;
private List mCommands = new ArrayList<>();
- private Context mContext;
- private ITaskQueue mTaskQueue;
+ public static Context APP;
+ private ITaskQueue mTaskQueue;
+ private static Configuration mConfig;
private DownloadManager() {
}
private DownloadManager(Context context) {
- mContext = context;
+ APP = context;
DownloadTaskQueue.Builder builder = new DownloadTaskQueue.Builder(context);
mTaskQueue = builder.build();
DbUtil.init(context);
}
- public static DownloadManager init(Context context) {
+ static DownloadManager init(Context context) {
if (INSTANCE == null) {
synchronized (LOCK) {
INSTANCE = new DownloadManager(context.getApplicationContext());
@@ -112,7 +114,7 @@ public class DownloadManager {
return INSTANCE;
}
- public List getAllDownloadEntity() {
+ List getAllDownloadEntity() {
return DbEntity.findAllData(DownloadEntity.class);
}
@@ -126,7 +128,7 @@ public class DownloadManager {
/**
* 设置命令
*/
- public DownloadManager setCmd(IDownloadCmd command) {
+ DownloadManager setCmd(IDownloadCmd command) {
mCommands.add(command);
return this;
}
@@ -134,7 +136,7 @@ public class DownloadManager {
/**
* 设置一组命令
*/
- public DownloadManager setCmds(List commands) {
+ DownloadManager setCmds(List commands) {
if (commands != null && commands.size() > 0) {
mCommands.addAll(commands);
}
@@ -144,7 +146,7 @@ public class DownloadManager {
/**
* 执行所有设置的命令
*/
- public synchronized void exe() {
+ synchronized void exe() {
for (IDownloadCmd command : mCommands) {
command.executeCmd();
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java
index e79b37db..8781fe29 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java
index 01af9af8..9e80372d 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.DownloadEntity;
@@ -40,7 +39,9 @@ class CancelCmd extends IDownloadCmd {
task = mQueue.createTask(mTarget, mEntity);
}
if (task != null) {
- task.setmTargetName(mTarget.getClass().getName());
+ if (mTarget != null) {
+ task.setTargetName(mTarget.getClass().getName());
+ }
mQueue.cancelTask(task);
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java
index e8003efe..8b676ee2 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/IDownloadCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/IDownloadCmd.java
index a61650ba..80d85237 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/IDownloadCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/IDownloadCmd.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/SingleCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/SingleCmd.java
index f8da683d..a45f0b2f 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/SingleCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/SingleCmd.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.arialyy.aria.core.command;
import android.util.Log;
@@ -27,7 +42,7 @@ class SingleCmd extends IDownloadCmd {
} else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
}
- task.setmTargetName(mTarget.getClass().getName());
+ task.setTargetName(mTarget.getClass().getName());
mQueue.startTask(task);
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
index 295089cf..d30c0b77 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ class StartCmd extends IDownloadCmd {
task = mQueue.createTask(mTarget, mEntity);
}
if (task != null) {
- task.setmTargetName(mTarget.getClass().getName());
+ task.setTargetName(mTarget.getClass().getName());
mQueue.startTask(task);
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java
index c696e5b6..611f6e12 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
package com.arialyy.aria.core.command;
import android.util.Log;
@@ -48,7 +47,9 @@ class StopCmd extends IDownloadCmd {
Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
}
} else {
- task.setmTargetName(mTarget.getClass().getName());
+ if (mTarget != null) {
+ task.setTargetName(mTarget.getClass().getName());
+ }
mQueue.stopTask(task);
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
index 1e597934..59bd9de3 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.core.task.TaskFactory;
+import com.arialyy.aria.util.Configuration;
/**
* Created by lyy on 2016/8/17.
@@ -36,7 +37,6 @@ public class DownloadTaskQueue implements ITaskQueue {
private ExecutePool mExecutePool = ExecutePool.getInstance();
private Context mContext;
private IDownloadSchedulers mSchedulers;
- private int mDownloadNum = 2;
private DownloadTaskQueue() {
}
@@ -107,6 +107,10 @@ public class DownloadTaskQueue implements ITaskQueue {
}
@Override public void reTryStart(Task task) {
+ if (task == null) {
+ Log.w(TAG, "重试下载失败,task 为null");
+ return;
+ }
if (!task.isDownloading()) {
task.start();
} else {
@@ -123,7 +127,32 @@ public class DownloadTaskQueue implements ITaskQueue {
}
@Override public void setDownloadNum(int downloadNum) {
+ //原始长度
+ int size = Configuration.getInstance().getDownloadNum();
+ int diff = downloadNum - size;
+ if (size == downloadNum){
+ Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
+ return;
+ }
+ //设置的任务数小于配置任务数
+ if (diff <= -1 && mExecutePool.size() >= size) {
+ for (int i = 0, len = Math.abs(diff); i < len; i++) {
+ Task eTask = mExecutePool.pollTask();
+ if (eTask != null) {
+ stopTask(eTask);
+ }
+ }
+ }
mExecutePool.setDownloadNum(downloadNum);
+ if (diff >= 1) {
+ for (int i = 0; i < diff; i++) {
+ Task nextTask = getNextTask();
+ if (nextTask != null
+ && nextTask.getDownloadEntity().getState() == DownloadEntity.STATE_WAIT) {
+ startTask(nextTask);
+ }
+ }
+ }
}
@Override public Task createTask(Object target, DownloadEntity entity) {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java b/Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java
index 2534c69c..601e54ed 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java
index 615c5146..f41258f4 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
index f70059db..d558c668 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
index f2adb5e2..8f710491 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
package com.arialyy.aria.core.queue.pool;
import android.text.TextUtils;
@@ -25,6 +24,7 @@ import com.arialyy.aria.core.task.Task;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
/**
* Created by lyy on 2016/8/14.
@@ -35,6 +35,7 @@ public class CachePool implements IPool {
private static final Object LOCK = new Object();
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;
@@ -75,13 +76,19 @@ public class CachePool implements IPool {
@Override public Task pollTask() {
synchronized (LOCK) {
- Task task = mCacheQueue.poll();
- if (task != null) {
- String url = task.getDownloadEntity().getDownloadUrl();
- mCacheArray.remove(CommonUtil.keyToHashKey(url));
+ try {
+ Task task = null;
+ task = mCacheQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
+ if (task != null) {
+ String url = task.getDownloadEntity().getDownloadUrl();
+ mCacheArray.remove(CommonUtil.keyToHashKey(url));
+ }
+ return task;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- return task;
}
+ return null;
}
@Override public Task getTask(String downloadUrl) {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
index 054ffab8..a3a1c911 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
package com.arialyy.aria.core.queue.pool;
import android.text.TextUtils;
@@ -22,6 +21,7 @@ import android.util.Log;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.queue.IPool;
import com.arialyy.aria.core.task.Task;
+import com.arialyy.aria.util.Configuration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
@@ -36,11 +36,12 @@ 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;
- public static int mSize = 2;
private ArrayBlockingQueue mExecuteQueue;
private Map mExecuteArray;
+ private int mSize;
private ExecutePool() {
+ mSize = Configuration.getInstance().getDownloadNum();
mExecuteQueue = new ArrayBlockingQueue<>(mSize);
mExecuteArray = new HashMap<>();
}
@@ -91,6 +92,7 @@ public class ExecutePool implements IPool {
}
mExecuteQueue = temp;
mSize = downloadNum;
+ Configuration.getInstance().setDownloadNum(mSize);
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -135,12 +137,18 @@ public class ExecutePool implements IPool {
@Override public Task pollTask() {
synchronized (LOCK) {
- Task task = mExecuteQueue.poll();
- if (task != null) {
- String url = task.getDownloadEntity().getDownloadUrl();
- mExecuteArray.remove(CommonUtil.keyToHashKey(url));
+ try {
+ Task task = null;
+ task = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
+ if (task != null) {
+ String url = task.getDownloadEntity().getDownloadUrl();
+ mExecuteArray.remove(CommonUtil.keyToHashKey(url));
+ }
+ return task;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- return task;
+ return null;
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
index 397f2085..3e952b51 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
+import com.arialyy.aria.util.Configuration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -67,10 +68,6 @@ public class DownloadSchedulers implements IDownloadSchedulers {
private static final String TAG = "DownloadSchedulers";
private static final Object LOCK = new Object();
private static volatile DownloadSchedulers INSTANCE = null;
- /**
- * 下载失败次数
- */
- int mFailNum = 10;
/**
* 超时时间
@@ -108,7 +105,7 @@ public class DownloadSchedulers implements IDownloadSchedulers {
case STOP:
case CANCEL:
mQueue.removeTask(entity);
- if (mQueue.size() != ExecutePool.mSize) {
+ if (mQueue.size() != Configuration.getInstance().getDownloadNum()) {
startNextTask(entity);
}
break;
@@ -178,11 +175,12 @@ public class DownloadSchedulers implements IDownloadSchedulers {
* @param entity 失败实体
*/
@Override public void handleFailTask(DownloadEntity entity) {
- if (entity.getFailNum() <= mFailNum) {
+ final Configuration config = Configuration.getInstance();
+ if (entity.getFailNum() <= config.getReTryNum()) {
Task task = mQueue.getTask(entity);
mQueue.reTryStart(task);
try {
- Thread.currentThread().sleep(4000);
+ Thread.currentThread().sleep(config.getReTryInterval());
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -227,12 +225,4 @@ public class DownloadSchedulers implements IDownloadSchedulers {
}
mSchedulerListeners.remove(target.getClass().getName());
}
-
- public void setFailNum(int mFailNum) {
- this.mFailNum = mFailNum;
- }
-
- public void setTimeOut(long timeOut) {
- this.mTimeOut = timeOut;
- }
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java
index a6d3fcf5..d8b2fda9 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java
index d36d5a3e..baa584af 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.task.Task;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java
index ac1f96ff..a0e9b8b8 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
index c093cf9b..f1558cb3 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ final class DownloadUtil implements IDownloadUtil {
mDownloadEntity = entity;
mListener = downloadListener;
THREAD_NUM = threadNum;
- mFixedThreadPool = Executors.newFixedThreadPool(THREAD_NUM);
+ mFixedThreadPool = Executors.newFixedThreadPool(Integer.MAX_VALUE);
}
public IDownloadListener getListener() {
@@ -292,7 +292,7 @@ final class DownloadUtil implements IDownloadUtil {
for (int l : recordL) {
if (l == -1) continue;
Runnable task = mTask.get(l);
- if (task != null) {
+ if (task != null && !mFixedThreadPool.isShutdown()) {
mFixedThreadPool.execute(task);
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java
index 3b1704d8..78a5d604 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java
index 83bb0f53..5c4e29f6 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/Task.java b/Aria/src/main/java/com/arialyy/aria/core/task/Task.java
index 0ce8c6ca..8b29994e 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/Task.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/task/Task.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import com.arialyy.aria.core.DownloadManager;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.DownloadEntity;
+import com.arialyy.aria.util.Configuration;
/**
* Created by lyy on 2016/8/11.
@@ -75,7 +76,7 @@ public class Task {
return mTargetName;
}
- public void setmTargetName(String targetName) {
+ public void setTargetName(String targetName) {
this.mTargetName = targetName;
}
@@ -205,7 +206,7 @@ public class Task {
public Task build() {
Task task = new Task(context, downloadEntity);
task.mOutHandler = outHandler;
- task.setmTargetName(targetName);
+ task.setTargetName(targetName);
downloadEntity.save();
return task;
}
@@ -325,7 +326,9 @@ public class Task {
if (location != -1) {
intent.putExtra(DownloadManager.CURRENT_LOCATION, location);
}
- //context.sendBroadcast(intent);
+ if (Configuration.isOpenBreadCast) {
+ context.sendBroadcast(intent);
+ }
}
}
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java b/Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java
index f057dee4..8cc1b710 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
index 74047a7a..1d24fd33 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
package com.arialyy.aria.orm;
import android.support.annotation.NonNull;
@@ -46,6 +45,14 @@ public class DbEntity {
return util.findAllData(clazz);
}
+ /**
+ * 查询第一条数据
+ */
+ public static T findFirst(Class clazz) {
+ List list = findAllData(clazz);
+ return (list == null || list.size() == 0) ? null : list.get(0);
+ }
+
/**
* 查询一组数据
*
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
index d0053879..a8c3bdab 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/Id.java b/Aria/src/main/java/com/arialyy/aria/orm/Id.java
index 70dfb70a..e6861025 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/Id.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/Id.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/Ignore.java b/Aria/src/main/java/com/arialyy/aria/orm/Ignore.java
index 8cd77d8a..1b3c1359 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/Ignore.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/Ignore.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
index f58b7961..a7b6c669 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
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 2b07ec87..ba70cda1 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
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 98f2df6e..bdcf94c2 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package com.arialyy.aria.util;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.util.Log;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.DownloadEntity;
@@ -44,6 +46,33 @@ public class CommonUtil {
return CmdFactory.getInstance().createCmd(entity, cmd);
}
+ /**
+ * 存储字符串到配置文件
+ *
+ * @param preName 配置文件名
+ * @param key 存储的键值
+ * @param value 需要存储的字符串
+ * @return 成功标志
+ */
+ public static Boolean putString(String preName, Context context, String key, String value) {
+ SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
+ SharedPreferences.Editor editor = pre.edit();
+ editor.putString(key, value);
+ return editor.commit();
+ }
+
+ /**
+ * 从配置文件读取字符串
+ *
+ * @param preName 配置文件名
+ * @param key 字符串键值
+ * @return 键值对应的字符串, 默认返回""
+ */
+ public static String getString(String preName, Context context, String key) {
+ SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
+ return pre.getString(key, "");
+ }
+
/**
* 获取类里面的所在字段
*/
diff --git a/Aria/src/main/java/com/arialyy/aria/util/Configuration.java b/Aria/src/main/java/com/arialyy/aria/util/Configuration.java
new file mode 100644
index 00000000..de3703d7
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/util/Configuration.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.arialyy.aria.util;
+
+import android.util.Log;
+import com.arialyy.aria.core.DownloadManager;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+/**
+ * Created by AriaL on 2016/12/8.
+ * 信息配置
+ */
+public class Configuration {
+ private static final String TAG = "Configuration";
+ private static final String CONFIG_FILE = "/Aria/ADConfig.properties";
+ /**
+ * 当前调度器最大下载数,默认最大下载数为 “2”
+ */
+ private static final String DOWNLOAD_NUM = "DOWNLOAD_NUM";
+ /**
+ * 失败重试次数,默认最多重试 10 次
+ */
+ private static final String RE_TRY_NUM = "RE_TRY_NUM";
+ /**
+ * 是否打开下载广播,默认 false
+ */
+ private static final String OPEN_BROADCAST = "OPEN_BROADCAST";
+ /**
+ * 失败重试间隔时间,默认 4000 ms
+ */
+ private static final String RE_TRY_INTERVAL = "RE_TRY_INTERVAL";
+ /**
+ * 超时时间,默认 10000 ms
+ */
+ private static final String DOWNLOAD_TIME_OUT = "DOWNLOAD_TIME_OUT";
+ public static boolean isOpenBreadCast = false;
+
+ private static Configuration INSTANCE = null;
+ private File mConfigFile = null;
+ private static final Object LOCK = new Object();
+
+ public static Configuration getInstance() {
+ if (INSTANCE == null) {
+ synchronized (LOCK) {
+ INSTANCE = new Configuration();
+ }
+ }
+ return INSTANCE;
+ }
+
+ private Configuration() {
+ mConfigFile = new File(DownloadManager.APP.getFilesDir().getPath() + CONFIG_FILE);
+ try {
+ if (!mConfigFile.exists()) {
+ mConfigFile.getParentFile().mkdirs();
+ mConfigFile.createNewFile();
+ init();
+ }else {
+ isOpenBreadCast = isOpenBroadcast();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void init() {
+ Map config = new WeakHashMap<>();
+ config.put(DOWNLOAD_NUM, 2 + "");
+ config.put(RE_TRY_NUM, 10 + "");
+ config.put(OPEN_BROADCAST, false + "");
+ config.put(RE_TRY_INTERVAL, 4000 + "");
+ config.put(DOWNLOAD_TIME_OUT, 10000 + "");
+ saveConfig(config);
+ }
+
+ private void saveConfig(Map config) {
+ if (config == null || config.size() == 0) {
+ return;
+ }
+ Properties properties = CommonUtil.loadConfig(mConfigFile);
+ Set keys = config.keySet();
+ for (String key : keys) {
+ properties.setProperty(key, config.get(key));
+ }
+ CommonUtil.saveConfig(mConfigFile, properties);
+ }
+
+ private void save(String key, String value) {
+ Map map = new WeakHashMap<>();
+ map.put(key, value);
+ saveConfig(map);
+ }
+
+ /**
+ * 获取下载超时时间
+ *
+ * @return 默认4000ms
+ */
+ public int getTimeOut() {
+ return Integer.parseInt(CommonUtil.loadConfig(mConfigFile).getProperty(DOWNLOAD_TIME_OUT));
+ }
+
+ /**
+ * 设置重试间隔
+ */
+ public void setTimeOut(int timeOut) {
+ if (timeOut < 10000) {
+ Log.w(TAG, "下载超时时间不能小于 10000 ms");
+ return;
+ }
+ save(DOWNLOAD_TIME_OUT, timeOut + "");
+ }
+
+ /**
+ * 获取失败重试间隔时间
+ *
+ * @return 默认4000ms
+ */
+ public int getReTryInterval() {
+ return Integer.parseInt(CommonUtil.loadConfig(mConfigFile).getProperty(RE_TRY_INTERVAL));
+ }
+
+ /**
+ * 设置重试间隔
+ */
+ public void setReTryInterval(int reTryInterval) {
+ if (reTryInterval < 4000) {
+ Log.w(TAG, "重试间隔不能小于4000ms");
+ return;
+ }
+ save(RE_TRY_INTERVAL, reTryInterval + "");
+ }
+
+ /**
+ * 获取最大下载数
+ *
+ * @return 默认返回2
+ */
+ public int getDownloadNum() {
+ return Integer.parseInt(CommonUtil.loadConfig(mConfigFile).getProperty(DOWNLOAD_NUM));
+ }
+
+ /**
+ * 设置最大下载数
+ */
+ public void setDownloadNum(int downloadNum) {
+ if (downloadNum < 1) {
+ Log.w(TAG, "最大下载数不能小于1");
+ return;
+ }
+ save(DOWNLOAD_NUM, downloadNum + "");
+ }
+
+ /**
+ * 获取最大重试数
+ *
+ * @return 默认返回 10
+ */
+ public int getReTryNum() {
+ return Integer.parseInt(CommonUtil.loadConfig(mConfigFile).getProperty(RE_TRY_NUM));
+ }
+
+ /**
+ * 设置重试数
+ */
+ public void setReTryNum(int reTryNum) {
+ if (reTryNum < 1) {
+ Log.w(TAG, "最大下载数不能小于1");
+ return;
+ }
+ save(RE_TRY_NUM, reTryNum + "");
+ }
+
+ /**
+ * 是否打开下载广播
+ *
+ * @return 默认false
+ */
+ public boolean isOpenBroadcast() {
+ return Boolean.parseBoolean(CommonUtil.loadConfig(mConfigFile).getProperty(RE_TRY_NUM));
+ }
+
+ /**
+ * 设置是否打开下载广播
+ */
+ public void setOpenBroadcast(boolean openBroadcast) {
+ isOpenBreadCast = openBroadcast;
+ save(OPEN_BROADCAST, openBroadcast + "");
+ }
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/util/PathUtil.java b/Aria/src/main/java/com/arialyy/aria/util/PathUtil.java
index 53e810d6..ed7efc5a 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/PathUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/PathUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/BroadCast.md b/BroadCast.md
new file mode 100644
index 00000000..47c6791c
--- /dev/null
+++ b/BroadCast.md
@@ -0,0 +1,58 @@
+# 广播使用
+#### 一、创建广播接收器,用来接收下载的各种状态
+```java
+private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ long len = 0;
+ @Override public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ //可以通过intent获取到下载实体,下载实体中包含了各种下载状态
+ DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
+ switch (action) {
+ case DownloadManager.ACTION_PRE: //预处理
+ break;
+ case DownloadManager.ACTION_POST_PRE: //预处理完成
+ //预处理完成,便可以获取文件的下载长度了
+ len = entity.getFileSize();
+ break;
+ case DownloadManager.ACTION_START: //开始下载
+ L.d(TAG, "download start");
+ break;
+ case DownloadManager.ACTION_RESUME: //恢复下载
+ L.d(TAG, "download resume");
+ long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
+ break;
+ case DownloadManager.ACTION_RUNNING: //下载中
+ long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
+ break;
+ case DownloadManager.ACTION_STOP: //停止下载
+ L.d(TAG, "download stop");
+ break;
+ case DownloadManager.ACTION_COMPLETE: //下载完成
+ break;
+ case DownloadManager.ACTION_CANCEL: //取消下载
+ break;
+ case DownloadManager.ACTION_FAIL: // 下载失败
+ break;
+ }
+ }
+ };
+```
+
+#### 二、在Activity中创建广播过滤器
+```java
+@Override protected void onResume() {
+ super.onResume();
+ IntentFilter filter = new IntentFilter();
+ filter.addDataScheme(getPackageName());
+ filter.addAction(DownloadManager.ACTION_PRE);
+ filter.addAction(DownloadManager.ACTION_POST_PRE);
+ filter.addAction(DownloadManager.ACTION_RESUME);
+ filter.addAction(DownloadManager.ACTION_START);
+ filter.addAction(DownloadManager.ACTION_RUNNING);
+ filter.addAction(DownloadManager.ACTION_STOP);
+ filter.addAction(DownloadManager.ACTION_CANCEL);
+ filter.addAction(DownloadManager.ACTION_COMPLETE);
+ filter.addAction(DownloadManager.ACTION_FAIL);
+ registerReceiver(mReceiver, filter);
+}
+```
\ No newline at end of file
diff --git a/README.md b/README.md
index ef22d2d8..e444c096 100644
--- a/README.md
+++ b/README.md
@@ -1,152 +1,107 @@
-# DownloadUtil
+# Aria
![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)
-这是一个 android 智能切换多任务断点续传工具,使用该工具,你可以很容易实现`多线程下载功能和复杂的任务自动切换功能`
-+ 该工具具有以下特点:
- - 通过命令控制下载
- - 可在广播中接收任务的各种下载状态
+Aria,致力于让下载傻瓜化
++ Aria有以下特点:
+ - 简单
+ - 可自定义是否使用广播
+ - 支持多线程、多任务下载
- 支持任务自动切换
- 支持下载速度直接获取
-如果你觉得我的代码对你有帮助,您的star和issues将是对我最大支持.`^_^`
+[Aria怎样使用?](#使用)
-#下载
-[![Download](https://api.bintray.com/packages/arialyy/maven/MTDownloadUtil/images/download.svg)](https://bintray.com/arialyy/maven/MTDownloadUtil/_latestVersion)
-compile 'com.arialyy.downloadutil:DownloadUtil:2.1.1'
+如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^`
+
+## 下载
+[![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:2.3.2'
+```
-#示例
+
+## 示例
![多任务下载](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/download_img.gif)
![单任务下载](https://github.com/AriaLyy/DownloadUtil/blob/master/img/11.gif "")
-# 性能展示
+## 性能展示
![性能展示](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/performance.png)
-# 使用
-* 一、在Application注册下载器
+***
+## 使用
+### 一、Aria 是实体驱动型的工具,所以,第一步,你需要创建一个下载实体
```java
-public class BaseApplication extends Application {
- @Override public void onCreate() {
- super.onCreate();
- //注册下载器
- DownloadManager.init(this);
- }
-}
+ DownloadEntity mEntity = new DownloadEntity();
+ mEntity.setFileName(fileName); //设置文件名
+ mEntity.setDownloadUrl(downloadUrl); //设置下载链接
+ mEntity.setDownloadPath(downloadPath); //设置存放路径
```
-
-* 二、创建广播接收器,用来接收下载的各种状态
-```java
-private BroadcastReceiver mReceiver = new BroadcastReceiver() {
- long len = 0;
- @Override public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- //可以通过intent获取到下载实体,下载实体中包含了各种下载状态
- DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
- switch (action) {
- case DownloadManager.ACTION_PRE: //预处理
- break;
- case DownloadManager.ACTION_POST_PRE: //预处理完成
- //预处理完成,便可以获取文件的下载长度了
- len = entity.getFileSize();
- break;
- case DownloadManager.ACTION_START: //开始下载
- L.d(TAG, "download start");
- break;
- case DownloadManager.ACTION_RESUME: //恢复下载
- L.d(TAG, "download resume");
- long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
- break;
- case DownloadManager.ACTION_RUNNING: //下载中
- long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
- break;
- case DownloadManager.ACTION_STOP: //停止下载
- L.d(TAG, "download stop");
- break;
- case DownloadManager.ACTION_COMPLETE: //下载完成
- break;
- case DownloadManager.ACTION_CANCEL: //取消下载
- break;
- case DownloadManager.ACTION_FAIL: // 下载失败
- break;
- }
- }
- };
-```
-
-* 三、在Activity中创建广播过滤器
+### 二、为了能接收到Aria传递的数据,你需要把你的Activity或fragment注册到Aria管理器中,注册的方式很简单,在onResume
```java
@Override protected void onResume() {
- super.onResume();
- IntentFilter filter = new IntentFilter();
- filter.addDataScheme(getPackageName());
- filter.addAction(DownloadManager.ACTION_PRE);
- filter.addAction(DownloadManager.ACTION_POST_PRE);
- filter.addAction(DownloadManager.ACTION_RESUME);
- filter.addAction(DownloadManager.ACTION_START);
- filter.addAction(DownloadManager.ACTION_RUNNING);
- filter.addAction(DownloadManager.ACTION_STOP);
- filter.addAction(DownloadManager.ACTION_CANCEL);
- filter.addAction(DownloadManager.ACTION_COMPLETE);
- filter.addAction(DownloadManager.ACTION_FAIL);
- registerReceiver(mReceiver, filter);
-}
-```
-
-* 四、创建下载实体
-```java
- DownloadEntity entity = new DownloadEntity();
- entity.setFileName(fileName); //设置文件名
- entity.setDownloadUrl(downloadUrl); //设置下载链接
- entity.setDownloadPath(downloadPath); //设置存放路径
-```
-
-* 五、通过命令控制下载(下载状态控制,或下载任务切换将自动完成)
-**!!注意:命令需要第四步的下载实体支持**
-
- - 获取命令工厂实例和下载管理器实例
- ```java
- CmdFactory factory = CmdFactory.getInstance();
- DownloadManager manager = DownloadManager.getInstance();
- ```
- - 开始命令、恢复下载命令都是同一个
- ```java
- private void start() {
- List commands = new ArrayList<>();
- IDownloadCmd addCMD = factory.createCmd(this, entity, CmdFactory.TASK_CREATE);
- IDownloadCmd startCmd = factory.createCmd(this, entity, CmdFactory.TASK_START);
- commands.add(addCMD);
- commands.add(startCmd);
- manager.setCmds(commands).exe();
- }
- ```
- - 停止命令
- ```java
- private void stop() {
- IDownloadCmd stopCmd = factory.createCmd(this, entity, CmdFactory.TASK_STOP);
- manager.setCmd(stopCmd).exe();
- }
- ```
- - 取消命令(取消下载、删除下载任务)
- ```java
- private void cancel() {
- IDownloadCmd cancelCmd = factory.createCmd(this, entity, CmdFactory.TASK_CANCEL);
- manager.setCmd(cancelCmd).exe();
- }
- ```
-
-# 修改最大任务数
-```
-mManager.getTaskQueue().setDownloadNum(num);
-
+ super.onResume();
+ Aria.whit(this).addSchedulerListener(new MySchedulerListener());
+ }
```
-
-# 开发日志
+### 三、还记得上面的DownloadEntity吗?现在是时候使用它进行下载了
+- 启动下载
+
+ ```java
+ Aria.whit(this).load(mEntity).start();
+ ```
+- 暂停下载
+
+ ```java
+ Aria.whit(this).load(mEntity).stop();
+ ```
+- 恢复下载
+
+ ```java
+ Aria.whit(this).load(mEntity).resume();
+ ```
+- 取消下载
+
+ ```java
+ Aria.whit(this).load(mEntity).cancel();
+ ```
+
+### 四、关于Aria,你还需要知道的一些东西
+- 设置下载任务数,Aria默认下载任务为**2**
+
+ ```java
+ Aria.get(getContext()).setMaxDownloadNum(num);
+ ```
+- 停止所有下载
+
+ ```java
+ Aria.get(this).stopAllTask();
+ ```
+- 设置失败重试次数,从事次数不能少于 1
+
+ ```java
+ Aria.get(this).setReTryNum(10);
+ ```
+- 设置失败重试间隔,重试间隔不能小于 5000ms
+
+ ```java
+ Aria.get(this).setReTryInterval(5000);
+ ```
+- 设置是否打开广播,如果你需要在Service后台获取下载完成情况,那么你需要打开Aria广播,[Aria广播配置](https://github.com/AriaLyy/Aria/blob/v_2.0/BroadCast.md)
+
+ ```java
+ Aria.get(this).openBroadcast(true);
+ ```
+
+***
+## 开发日志
+ v_2.1.0 修复大量bug
+ v_2.1.1 增加,选择最大下载任务数接口
+ + v_2.3.1 重命名为Aria,下载流程简化
License
-------
- Copyright 2016 AriaLyy(DownloadUtil)
+ Copyright 2016 AriaLyy(https://github.com/AriaLyy/Aria)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -158,4 +113,4 @@ License
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
- limitations under the License.
+ limitations under the License.
\ No newline at end of file
diff --git a/app/src/main/java/com/arialyy/simple/activity/MainActivity.java b/app/src/main/java/com/arialyy/simple/activity/MainActivity.java
index f73c6eed..f0b71af9 100644
--- a/app/src/main/java/com/arialyy/simple/activity/MainActivity.java
+++ b/app/src/main/java/com/arialyy/simple/activity/MainActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/app/src/main/java/com/arialyy/simple/activity/MultiTaskActivity.java b/app/src/main/java/com/arialyy/simple/activity/MultiTaskActivity.java
index 98e57a11..4e61682a 100644
--- a/app/src/main/java/com/arialyy/simple/activity/MultiTaskActivity.java
+++ b/app/src/main/java/com/arialyy/simple/activity/MultiTaskActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,8 +104,15 @@ public class MultiTaskActivity extends BaseActivity {
//};
public void onClick(View view){
- DownloadNumDialog dialog = new DownloadNumDialog(this);
- dialog.show(getSupportFragmentManager(), "download_num");
+ switch (view.getId()){
+ case R.id.num:
+ DownloadNumDialog dialog = new DownloadNumDialog(this);
+ dialog.show(getSupportFragmentManager(), "download_num");
+ break;
+ case R.id.stop_all:
+ Aria.get(this).stopAllTask();
+ break;
+ }
}
@Override protected void onResume() {
diff --git a/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java
index 643335df..e1ba249c 100644
--- a/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java
+++ b/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
package com.arialyy.simple.activity;
import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -30,12 +32,15 @@ import butterknife.Bind;
import com.arialyy.aria.core.AMTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
+import com.arialyy.aria.core.DownloadManager;
import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
+import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivitySingleBinding;
+import com.arialyy.simple.module.DownloadModule;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
public class SingleTaskActivity extends BaseActivity {
@@ -56,7 +61,14 @@ public class SingleTaskActivity extends BaseActivity {
@Bind(R.id.toolbar) Toolbar toolbar;
@Bind(R.id.speed) TextView mSpeed;
private DownloadEntity mEntity;
- private BroadcastReceiver mReceiver;
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(DownloadManager.ACTION_START)) {
+ L.d("START");
+ }
+ }
+ };
private Handler mUpdateHandler = new Handler() {
@Override public void handleMessage(Message msg) {
@@ -126,10 +138,12 @@ public class SingleTaskActivity extends BaseActivity {
@Override protected void onResume() {
super.onResume();
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
+ //registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
}
@Override protected void onDestroy() {
super.onDestroy();
+ //unregisterReceiver(mReceiver);
}
@Override protected int setLayoutId() {
@@ -141,11 +155,11 @@ public class SingleTaskActivity extends BaseActivity {
setSupportActionBar(toolbar);
toolbar.setTitle("单任务下载");
init();
+ Aria.get(this).openBroadcast(true);
}
private void init() {
- mEntity = DbEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
- new String[] { DOWNLOAD_URL });
+ mEntity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
if (mEntity != null) {
mPb.setProgress((int) ((mEntity.getCurrentProgress() * 100) / mEntity.getFileSize()));
mSize.setText(CommonUtil.formatFileSize(mEntity.getFileSize()));
diff --git a/app/src/main/java/com/arialyy/simple/adapter/DownloadAdapter.java b/app/src/main/java/com/arialyy/simple/adapter/DownloadAdapter.java
index ef15f824..f1138402 100644
--- a/app/src/main/java/com/arialyy/simple/adapter/DownloadAdapter.java
+++ b/app/src/main/java/com/arialyy/simple/adapter/DownloadAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -147,7 +147,7 @@ public class DownloadAdapter extends AbsRVAdapter list = new ArrayList<>();
for (String url : urls) {
- DownloadEntity entity =
- DownloadEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
- new String[] { url });
+ DownloadEntity entity = Aria.get(getContext()).getDownloadEntity(url);
if (entity == null) {
entity = createDownloadEntity(url);
}
@@ -93,7 +92,6 @@ public class DownloadModule extends BaseModule {
entity.setDownloadPath(getDownloadPath(url));
entity.setFileName(fileName);
//entity.setFileName("taskName_________" + i);
- entity.save();
return entity;
}
diff --git a/app/src/main/java/com/arialyy/simple/widget/HorizontalProgressBarWithNumber.java b/app/src/main/java/com/arialyy/simple/widget/HorizontalProgressBarWithNumber.java
index 6ea5eee5..0e8512a0 100644
--- a/app/src/main/java/com/arialyy/simple/widget/HorizontalProgressBarWithNumber.java
+++ b/app/src/main/java/com/arialyy/simple/widget/HorizontalProgressBarWithNumber.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
+ * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/app/src/main/res/layout/activity_multi.xml b/app/src/main/res/layout/activity_multi.xml
index ef85f1b1..0414246c 100644
--- a/app/src/main/res/layout/activity_multi.xml
+++ b/app/src/main/res/layout/activity_multi.xml
@@ -19,15 +19,26 @@
/>
+
+
-
+
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
index 58973c5d..6bce7f44 100644
Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
index 04271660..76a76280 100644
Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
index a3341c10..673fb59e 100644
Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
index a3913366..e8c89732 100644
Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
index f3d93499..11f372ec 100644
Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e9c4670d..4599b7cc 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,5 +1,5 @@
- DownloadDemo
+ Aria
Settings
diff --git a/gradle.properties b/gradle.properties
index 1d3591c8..fed5c85c 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,18 +1,19 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
+## Project-wide Gradle settings.
+#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
-
+#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
-# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
-
+#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+# org.gradle.parallel=true
+#Wed Dec 07 20:19:22 CST 2016
+systemProp.http.proxyPassword=7RbgsDfOoBn
+systemProp.http.proxyHost=hilton.h.xduotai.com
+systemProp.http.proxyUser=duotai
+systemProp.http.proxyPort=10969
diff --git a/img/download_img.gif b/img/download_img.gif
index ecd21dba..b0556fe8 100644
Binary files a/img/download_img.gif and b/img/download_img.gif differ
diff --git a/img/performance.png b/img/performance.png
index bfbc25b6..cc29de09 100644
Binary files a/img/performance.png and b/img/performance.png differ