This commit is contained in:
AriaLyy
2017-04-05 16:12:32 +08:00
parent 5d77e917ad
commit 6f24f76fdb
70 changed files with 1205 additions and 704 deletions

2
.idea/modules.xml generated
View File

@ -2,8 +2,8 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" /> <module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" /> <module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" /> <module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />

View File

@ -27,7 +27,9 @@ import android.content.Context;
import android.os.Build; import android.os.Build;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.scheduler.OnSchedulerListener; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulerListener;
import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.upload.UploadReceiver; import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTask;
@ -56,6 +58,10 @@ import com.arialyy.aria.core.upload.UploadTask;
* </pre> * </pre>
*/ */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria { @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
/**
* 不支持断点
*/
public static final String ACTION_SUPPORT_BREAK_POINT = "ACTION_SUPPORT_BREAK_POINT";
/** /**
* 预处理完成 * 预处理完成
*/ */
@ -163,7 +169,7 @@ import com.arialyy.aria.core.upload.UploadTask;
/** /**
* 上传任务状态监听 * 上传任务状态监听
*/ */
public static class UploadSchedulerListener implements OnSchedulerListener<UploadTask> { public static class UploadSchedulerListener implements ISchedulerListener<UploadTask> {
@Override public void onTaskPre(UploadTask task) { @Override public void onTaskPre(UploadTask task) {
@ -201,7 +207,8 @@ import com.arialyy.aria.core.upload.UploadTask;
/** /**
* 下载任务状态监听 * 下载任务状态监听
*/ */
public static class DownloadSchedulerListener implements OnSchedulerListener<DownloadTask> { public static class DownloadSchedulerListener implements
IDownloadSchedulerListener<DownloadTask> {
@Override public void onTaskPre(DownloadTask task) { @Override public void onTaskPre(DownloadTask task) {
@ -234,5 +241,9 @@ import com.arialyy.aria.core.upload.UploadTask;
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
} }
@Override public void onNoSupportBreakPoint(DownloadTask task) {
}
} }
} }

View File

@ -31,7 +31,6 @@ class StartCmd<T extends ITaskEntity> extends AbsCmd<T> {
} }
@Override public void executeCmd() { @Override public void executeCmd() {
Log.d(TAG, "startCmd");
ITask task = mQueue.getTask(mEntity.getEntity()); ITask task = mQueue.getTask(mEntity.getEntity());
if (task == null) { if (task == null) {
task = mQueue.createTask(mTargetName, mEntity); task = mQueue.createTask(mTargetName, mEntity);

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import android.os.Parcel; import android.os.Parcel;
@ -129,8 +128,7 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity{
this.fileSize = fileSize; this.fileSize = fileSize;
} }
@Override @Override public int getState() {
public int getState() {
return state; return state;
} }
@ -167,16 +165,26 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity{
} }
@Override public String toString() { @Override public String toString() {
return "DownloadEntity{" + return "DownloadEntity{"
"downloadUrl='" + downloadUrl + '\'' + + "downloadUrl='"
", downloadPath='" + downloadPath + '\'' + + downloadUrl
", completeTime=" + completeTime + + '\''
", fileSize=" + fileSize + + ", downloadPath='"
", state=" + state + + downloadPath
", isDownloadComplete=" + isDownloadComplete + + '\''
", currentProgress=" + currentProgress + + ", completeTime="
", failNum=" + failNum + + completeTime
'}'; + ", fileSize="
+ fileSize
+ ", state="
+ state
+ ", isDownloadComplete="
+ isDownloadComplete
+ ", currentProgress="
+ currentProgress
+ ", failNum="
+ failNum
+ '}';
} }
@Override public int describeContents() { @Override public int describeContents() {

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
class DownloadListener implements IDownloadListener { class DownloadListener implements IDownloadListener {

View File

@ -21,7 +21,7 @@ import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.OnSchedulerListener; import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -36,7 +36,7 @@ import java.util.Set;
public class DownloadReceiver implements IReceiver<DownloadEntity> { public class DownloadReceiver implements IReceiver<DownloadEntity> {
private static final String TAG = "DownloadReceiver"; private static final String TAG = "DownloadReceiver";
public String targetName; public String targetName;
public OnSchedulerListener<DownloadTask> listener; public ISchedulerListener<DownloadTask> listener;
/** /**
* {@link #load(String)},请使用该方法 * {@link #load(String)},请使用该方法
@ -62,7 +62,7 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
/** /**
* 添加调度器回调 * 添加调度器回调
*/ */
public DownloadReceiver addSchedulerListener(OnSchedulerListener<DownloadTask> listener) { public DownloadReceiver addSchedulerListener(ISchedulerListener<DownloadTask> listener) {
this.listener = listener; this.listener = listener;
DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener); DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener);
return this; return this;
@ -110,8 +110,8 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
List<AbsCmd> stopCmds = new ArrayList<>(); List<AbsCmd> stopCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) { for (DownloadEntity entity : allEntity) {
if (entity.getState() == DownloadEntity.STATE_RUNNING) { if (entity.getState() == DownloadEntity.STATE_RUNNING) {
stopCmds.add(CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity), stopCmds.add(
CmdFactory.TASK_STOP)); CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity), CmdFactory.TASK_STOP));
} }
} }
ariaManager.setCmds(stopCmds).exe(); ariaManager.setCmds(stopCmds).exe();
@ -125,8 +125,8 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
List<DownloadEntity> allEntity = DbEntity.findAllData(DownloadEntity.class); List<DownloadEntity> allEntity = DbEntity.findAllData(DownloadEntity.class);
List<AbsCmd> cancelCmds = new ArrayList<>(); List<AbsCmd> cancelCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) { for (DownloadEntity entity : allEntity) {
cancelCmds.add(CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity), cancelCmds.add(
CmdFactory.TASK_CANCEL)); CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL));
} }
ariaManager.setCmds(cancelCmds).exe(); ariaManager.setCmds(cancelCmds).exe();
Set<String> keys = ariaManager.getReceiver().keySet(); Set<String> keys = ariaManager.getReceiver().keySet();

View File

@ -91,8 +91,7 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
/** /**
* 设置文件名 * 设置文件名
*/ */
@Deprecated @Deprecated public DownloadTarget setDownloadName(@NonNull String downloadName) {
public DownloadTarget setDownloadName(@NonNull String downloadName) {
if (TextUtils.isEmpty(downloadName)) { if (TextUtils.isEmpty(downloadName)) {
throw new IllegalArgumentException("文件名不能为null"); throw new IllegalArgumentException("文件名不能为null");
} }

View File

@ -103,11 +103,12 @@ public class DownloadTask implements ITask {
@Deprecated public boolean isDownloading() { @Deprecated public boolean isDownloading() {
return mUtil.isDownloading(); return mUtil.isDownloading();
} }
@Override public boolean isRunning() { @Override public boolean isRunning() {
return isDownloading(); return isDownloading();
} }
@Override public IEntity getEntity() { @Override public DownloadEntity getEntity() {
return mEntity; return mEntity;
} }
@ -133,8 +134,7 @@ public class DownloadTask implements ITask {
return mTargetName; return mTargetName;
} }
@Override @Override public void setTargetName(String targetName) {
public void setTargetName(String targetName) {
this.mTargetName = targetName; this.mTargetName = targetName;
} }
@ -186,7 +186,6 @@ public class DownloadTask implements ITask {
int threadNum = 3; int threadNum = 3;
String targetName; String targetName;
public Builder(String targetName, DownloadTaskEntity taskEntity) { public Builder(String targetName, DownloadTaskEntity taskEntity) {
CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity); CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity);
this.targetName = targetName; this.targetName = targetName;
@ -245,6 +244,12 @@ public class DownloadTask implements ITask {
sendIntent.putExtra(Aria.ENTITY, downloadEntity); sendIntent.putExtra(Aria.ENTITY, downloadEntity);
} }
@Override public void supportBreakpoint(boolean support) {
super.supportBreakpoint(support);
sendInState2Target(ISchedulers.SUPPORT_BREAK_POINT);
sendIntent(Aria.ACTION_SUPPORT_BREAK_POINT, -1);
}
@Override public void onPre() { @Override public void onPre() {
super.onPre(); super.onPre();
downloadEntity.setState(DownloadEntity.STATE_PRE); downloadEntity.setState(DownloadEntity.STATE_PRE);
@ -342,14 +347,13 @@ public class DownloadTask implements ITask {
downloadEntity.setDownloadComplete(action.equals(Aria.ACTION_COMPLETE)); downloadEntity.setDownloadComplete(action.equals(Aria.ACTION_COMPLETE));
downloadEntity.setCurrentProgress(location); downloadEntity.setCurrentProgress(location);
downloadEntity.update(); downloadEntity.update();
if (!Configuration.isOpenBreadCast) return;
Intent intent = CommonUtil.createIntent(context.getPackageName(), action); Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
intent.putExtra(Aria.ENTITY, downloadEntity); intent.putExtra(Aria.ENTITY, downloadEntity);
if (location != -1) { if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location); intent.putExtra(Aria.CURRENT_LOCATION, location);
} }
if (Configuration.isOpenBreadCast) {
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
} }
} }
}

View File

@ -315,7 +315,10 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
entity.CONFIG_FILE_PATH = mConfigFile.getPath(); entity.CONFIG_FILE_PATH = mConfigFile.getPath();
entity.isSupportBreakpoint = isSupportBreakpoint; entity.isSupportBreakpoint = isSupportBreakpoint;
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity; entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
THREAD_NUM = 1;
mConstance.THREAD_NUM = THREAD_NUM;
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity); SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
mTask.put(0, task);
mFixedThreadPool.execute(task); mFixedThreadPool.execute(task);
mListener.onPostPre(len); mListener.onPostPre(len);
mListener.onStart(0); mListener.onStart(0);

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
/** /**

View File

@ -72,7 +72,7 @@ final class SingleThreadTask implements Runnable {
conn.setRequestProperty("Range", conn.setRequestProperty("Range",
"bytes=" + mConfigEntity.START_LOCATION + "-" + mConfigEntity.END_LOCATION); "bytes=" + mConfigEntity.START_LOCATION + "-" + mConfigEntity.END_LOCATION);
} else { } else {
Log.w(TAG, "该下载不支持断点,即将重新下载"); Log.w(TAG, "该下载不支持断点");
} }
conn = ConnectionHelp.setConnectParam(mConfigEntity.DOWNLOAD_TASK_ENTITY, conn); conn = ConnectionHelp.setConnectParam(mConfigEntity.DOWNLOAD_TASK_ENTITY, conn);
conn.setConnectTimeout(mConstance.CONNECT_TIME_OUT); conn.setConnectTimeout(mConstance.CONNECT_TIME_OUT);

View File

@ -60,5 +60,4 @@ public interface IEntity {
@Ignore public static final int STATE_CANCEL = 7; @Ignore public static final int STATE_CANCEL = 7;
public int getState(); public int getState();
} }

View File

@ -28,6 +28,7 @@ public interface ITask {
/** /**
* 是否真正执行 * 是否真正执行
*
* @return true正在执行 * @return true正在执行
*/ */
public boolean isRunning(); public boolean isRunning();

View File

@ -57,13 +57,14 @@ public class TaskFactory {
* @param <SCHEDULER> {@link DownloadSchedulers} * @param <SCHEDULER> {@link DownloadSchedulers}
* @return {@link DownloadTask}、{@link UploadTask} * @return {@link DownloadTask}、{@link UploadTask}
*/ */
<ENTITY extends ITaskEntity, SCHEDULER extends ISchedulers> ITask createTask( <ENTITY extends ITaskEntity, SCHEDULER extends ISchedulers> ITask createTask(String targetName,
String targetName, ENTITY entity, SCHEDULER schedulers) { ENTITY entity, SCHEDULER schedulers) {
if (entity instanceof DownloadTaskEntity) { if (entity instanceof DownloadTaskEntity) {
return createDownloadTask(targetName, (DownloadTaskEntity) entity, schedulers); return createDownloadTask(targetName, (DownloadTaskEntity) entity, schedulers);
} else if (entity instanceof UploadTaskEntity) { } else if (entity instanceof UploadTaskEntity) {
return createUploadTask(targetName, (UploadTaskEntity) entity, schedulers); return createUploadTask(targetName, (UploadTaskEntity) entity, schedulers);
} return null; }
return null;
} }
/** /**

View File

@ -42,7 +42,6 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
} }
@Override public void startTask(UploadTask task) { @Override public void startTask(UploadTask task) {
Log.e(TAG, "startTask");
if (mExecutePool.putTask(task)) { if (mExecutePool.putTask(task)) {
mCachePool.removeTask(task); mCachePool.removeTask(task);
//task.getEntity().setFailNum(0); //task.getEntity().setFailNum(0);

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.queue.pool; package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;

View File

@ -41,7 +41,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
/** /**
* 下载器任务监听 * 下载器任务监听
*/ */
private Map<String, OnSchedulerListener<DownloadTask>> mSchedulerListeners = private Map<String, IDownloadSchedulerListener<DownloadTask>> mSchedulerListeners =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
private DownloadTaskQueue mQueue; private DownloadTaskQueue mQueue;
@ -59,16 +59,17 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
} }
@Override public void addSchedulerListener(String targetName, @Override public void addSchedulerListener(String targetName,
OnSchedulerListener<DownloadTask> schedulerListener) { ISchedulerListener<DownloadTask> schedulerListener) {
mSchedulerListeners.put(targetName, schedulerListener); mSchedulerListeners.put(targetName,
(IDownloadSchedulerListener<DownloadTask>) schedulerListener);
} }
@Override public void removeSchedulerListener(String targetName, @Override public void removeSchedulerListener(String targetName,
OnSchedulerListener<DownloadTask> schedulerListener) { ISchedulerListener<DownloadTask> schedulerListener) {
//该内存溢出解决方案http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element //该内存溢出解决方案http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element
for (Iterator<Map.Entry<String, OnSchedulerListener<DownloadTask>>> iter = for (Iterator<Map.Entry<String, IDownloadSchedulerListener<DownloadTask>>> iter =
mSchedulerListeners.entrySet().iterator(); iter.hasNext(); ) { mSchedulerListeners.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, OnSchedulerListener<DownloadTask>> entry = iter.next(); Map.Entry<String, IDownloadSchedulerListener<DownloadTask>> entry = iter.next();
if (entry.getKey().equals(targetName)) iter.remove(); if (entry.getKey().equals(targetName)) iter.remove();
} }
} }
@ -118,7 +119,8 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
} }
} }
private void callback(int state, DownloadTask task, OnSchedulerListener<DownloadTask> listener) { private void callback(int state, DownloadTask task,
IDownloadSchedulerListener<DownloadTask> listener) {
if (listener != null) { if (listener != null) {
if (task == null) { if (task == null) {
Log.e(TAG, "TASK 为null回调失败"); Log.e(TAG, "TASK 为null回调失败");
@ -149,6 +151,9 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
case FAIL: case FAIL:
listener.onTaskFail(task); listener.onTaskFail(task);
break; break;
case SUPPORT_BREAK_POINT:
listener.onNoSupportBreakPoint(task);
break;
} }
} }
} }

View File

@ -0,0 +1,29 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.inf.ITask;
/**
* Created by Aria.Lao on 2017/4/5.
*/
public interface IDownloadSchedulerListener<TASK extends ITask> extends ISchedulerListener<TASK> {
/**
* 支持断点的回调
*/
public void onNoSupportBreakPoint(TASK task);
}

View File

@ -20,7 +20,7 @@ import com.arialyy.aria.core.inf.ITask;
/** /**
* Target处理任务监听 * Target处理任务监听
*/ */
public interface OnSchedulerListener<TASK extends ITask> { public interface ISchedulerListener<TASK extends ITask> {
/** /**
* 任务预加载 * 任务预加载
*/ */

View File

@ -17,7 +17,6 @@
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
/** /**
@ -25,6 +24,10 @@ import com.arialyy.aria.core.inf.ITask;
* 调度器功能接口 * 调度器功能接口
*/ */
public interface ISchedulers<Task extends ITask> extends Handler.Callback { public interface ISchedulers<Task extends ITask> extends Handler.Callback {
/**
* 断点支持
*/
public static final int SUPPORT_BREAK_POINT = 8;
/** /**
* 任务预加载 * 任务预加载
*/ */
@ -62,14 +65,14 @@ public interface ISchedulers<Task extends ITask> extends Handler.Callback {
* 注册下载器监听,一个观察者只能注册一次监听 * 注册下载器监听,一个观察者只能注册一次监听
* *
* @param targetName 观察者,创建该监听器的对象类名 * @param targetName 观察者,创建该监听器的对象类名
* @param schedulerListener {@link OnSchedulerListener} * @param schedulerListener {@link ISchedulerListener}
*/ */
public void addSchedulerListener(String targetName, OnSchedulerListener<Task> schedulerListener); public void addSchedulerListener(String targetName, ISchedulerListener<Task> schedulerListener);
/** /**
* @param targetName 观察者,创建该监听器的对象类名 * @param targetName 观察者,创建该监听器的对象类名
* 取消注册监听器 * 取消注册监听器
*/ */
public void removeSchedulerListener(String targetName, OnSchedulerListener<Task> schedulerListener); public void removeSchedulerListener(String targetName,
ISchedulerListener<Task> schedulerListener);
} }

View File

@ -33,12 +33,10 @@ import java.util.concurrent.ConcurrentHashMap;
* 上传任务调度器 * 上传任务调度器
*/ */
public class UploadSchedulers implements ISchedulers<UploadTask> { public class UploadSchedulers implements ISchedulers<UploadTask> {
private static final String TAG = private static final String TAG = "UploadSchedulers";
"UploadSchedulers"; private static final Object LOCK = new Object();
private static final Object LOCK =
new Object();
private static volatile UploadSchedulers INSTANCE = null; private static volatile UploadSchedulers INSTANCE = null;
private Map<String, OnSchedulerListener<UploadTask>> mSchedulerListeners = private Map<String, ISchedulerListener<UploadTask>> mSchedulerListeners =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
private UploadTaskQueue mQueue; private UploadTaskQueue mQueue;
@ -57,15 +55,15 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
} }
@Override public void addSchedulerListener(String targetName, @Override public void addSchedulerListener(String targetName,
OnSchedulerListener<UploadTask> schedulerListener) { ISchedulerListener<UploadTask> schedulerListener) {
mSchedulerListeners.put(targetName, schedulerListener); mSchedulerListeners.put(targetName, schedulerListener);
} }
@Override public void removeSchedulerListener(String targetName, @Override public void removeSchedulerListener(String targetName,
OnSchedulerListener<UploadTask> schedulerListener) { ISchedulerListener<UploadTask> schedulerListener) {
for (Iterator<Map.Entry<String, OnSchedulerListener<UploadTask>>> iter = for (Iterator<Map.Entry<String, ISchedulerListener<UploadTask>>> iter =
mSchedulerListeners.entrySet().iterator(); iter.hasNext(); ) { mSchedulerListeners.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, OnSchedulerListener<UploadTask>> entry = iter.next(); Map.Entry<String, ISchedulerListener<UploadTask>> entry = iter.next();
if (entry.getKey().equals(targetName)) iter.remove(); if (entry.getKey().equals(targetName)) iter.remove();
} }
} }
@ -124,7 +122,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
} }
} }
private void callback(int state, UploadTask task, OnSchedulerListener<UploadTask> listener) { private void callback(int state, UploadTask task, ISchedulerListener<UploadTask> listener) {
if (listener != null) { if (listener != null) {
if (task == null) { if (task == null) {
Log.e(TAG, "TASK 为null回调失败"); Log.e(TAG, "TASK 为null回调失败");

View File

@ -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.upload; package com.arialyy.aria.core.upload;
import android.os.Parcel; import android.os.Parcel;

View File

@ -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.upload; package com.arialyy.aria.core.upload;
/** /**

View File

@ -16,13 +16,12 @@
package com.arialyy.aria.core.upload; package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.scheduler.OnSchedulerListener; import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -30,7 +29,6 @@ import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -40,7 +38,7 @@ import java.util.regex.Pattern;
public class UploadReceiver implements IReceiver<UploadEntity> { public class UploadReceiver implements IReceiver<UploadEntity> {
private static final String TAG = "DownloadReceiver"; private static final String TAG = "DownloadReceiver";
public String targetName; public String targetName;
public OnSchedulerListener<UploadTask> listener; public ISchedulerListener<UploadTask> listener;
/** /**
* 加载任务 * 加载任务
@ -118,7 +116,7 @@ public class UploadReceiver implements IReceiver<UploadEntity> {
/** /**
* 添加调度器回调 * 添加调度器回调
*/ */
public UploadReceiver addSchedulerListener(OnSchedulerListener<UploadTask> listener) { public UploadReceiver addSchedulerListener(ISchedulerListener<UploadTask> listener) {
this.listener = listener; this.listener = listener;
UploadSchedulers.getInstance().addSchedulerListener(targetName, listener); UploadSchedulers.getInstance().addSchedulerListener(targetName, listener);
return this; return this;

View File

@ -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.upload; package com.arialyy.aria.core.upload;
import android.content.Intent; import android.content.Intent;
@ -57,7 +72,6 @@ public class UploadTask implements ITask {
} }
@Override public void start() { @Override public void start() {
Log.d(TAG, "task_start");
if (mUtil.isRunning()) { if (mUtil.isRunning()) {
Log.d(TAG, "任务正在下载"); Log.d(TAG, "任务正在下载");
} else { } else {
@ -206,16 +220,15 @@ public class UploadTask implements ITask {
entity.setComplete(action.equals(Aria.ACTION_COMPLETE)); entity.setComplete(action.equals(Aria.ACTION_COMPLETE));
entity.setCurrentProgress(location); entity.setCurrentProgress(location);
entity.update(); entity.update();
if (!Configuration.isOpenBreadCast) return;
Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action); Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action);
intent.putExtra(Aria.ENTITY, entity); intent.putExtra(Aria.ENTITY, entity);
if (location != -1) { if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location); intent.putExtra(Aria.CURRENT_LOCATION, location);
} }
if (Configuration.isOpenBreadCast) {
AriaManager.APP.sendBroadcast(intent); AriaManager.APP.sendBroadcast(intent);
} }
} }
}
public static class Builder { public static class Builder {
private Handler mOutHandler; private Handler mOutHandler;

View File

@ -59,7 +59,6 @@ final class UploadUtil implements Runnable {
} }
public void start() { public void start() {
Log.d(TAG, "start");
isCancel = false; isCancel = false;
isRunning = false; isRunning = false;
new Thread(this).start(); new Thread(this).start();
@ -71,7 +70,6 @@ final class UploadUtil implements Runnable {
} }
@Override public void run() { @Override public void run() {
Log.e(TAG, "run");
File uploadFile = new File(mUploadEntity.getFilePath()); File uploadFile = new File(mUploadEntity.getFilePath());
if (!uploadFile.exists()) { if (!uploadFile.exists()) {
Log.e(TAG, "" + mUploadEntity.getFilePath() + "】,文件不存在。"); Log.e(TAG, "" + mUploadEntity.getFilePath() + "】,文件不存在。");
@ -123,7 +121,14 @@ final class UploadUtil implements Runnable {
} }
private void fail() { private void fail() {
try {
mListener.onFail(); mListener.onFail();
if (mOutputStream != null) {
mOutputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} }
/** /**
@ -151,7 +156,6 @@ final class UploadUtil implements Runnable {
*/ */
private void uploadFile(PrintWriter writer, String attachment, File uploadFile) private void uploadFile(PrintWriter writer, String attachment, File uploadFile)
throws IOException { throws IOException {
Log.e(TAG, "uploadFile");
writer.append(PREFIX).append(BOUNDARY).append(LINE_END); writer.append(PREFIX).append(BOUNDARY).append(LINE_END);
writer.append("Content-Disposition: form-data; name=\"") writer.append("Content-Disposition: form-data; name=\"")
.append(attachment) .append(attachment)

View File

@ -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.exception; package com.arialyy.aria.exception;
/** /**

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.orm; package com.arialyy.aria.orm;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.orm; package com.arialyy.aria.orm;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.orm; package com.arialyy.aria.orm;
import android.content.Context; import android.content.Context;

View File

@ -103,6 +103,8 @@ public class CheckUtil {
throw new NullPointerException("下载实体不能为空"); throw new NullPointerException("下载实体不能为空");
} else if (TextUtils.isEmpty(entity1.getDownloadUrl())) { } else if (TextUtils.isEmpty(entity1.getDownloadUrl())) {
throw new IllegalArgumentException("下载链接不能为空"); throw new IllegalArgumentException("下载链接不能为空");
} else if (TextUtils.isEmpty(entity1.getDownloadPath())) {
throw new IllegalArgumentException("保存路径不能为空");
} }
} else if (entity instanceof UploadTaskEntity) { } else if (entity instanceof UploadTaskEntity) {
UploadEntity entity1 = ((UploadTaskEntity) entity).uploadEntity; UploadEntity entity1 = ((UploadTaskEntity) entity).uploadEntity;

View File

@ -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.util; package com.arialyy.aria.util;
import android.content.Context; import android.content.Context;
@ -60,7 +75,8 @@ public class FileUtil {
|| exName.equalsIgnoreCase("rm") || exName.equalsIgnoreCase("rm")
|| exName.equalsIgnoreCase("rmvb")) { || exName.equalsIgnoreCase("rmvb")) {
//fType = new FileType("视频", ); //fType = new FileType("视频", );
} return fType; }
return fType;
} }
/** /**

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.util; package com.arialyy.aria.util;
import android.os.Environment; import android.os.Environment;

View File

@ -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.util; package com.arialyy.aria.util;
/** /**
@ -7,20 +22,16 @@ public enum Speed {
/** /**
* 最大速度为256kb * 最大速度为256kb
*/ */
KB_256(64), KB_256(64), /**
/**
* 最大速度为512kb * 最大速度为512kb
*/ */
KB_512(128), KB_512(128), /**
/**
* 最大速度为1mb * 最大速度为1mb
*/ */
MB_1(256), MB_1(256), /**
/**
* 最大速度为2mb * 最大速度为2mb
*/ */
MB_2(1024), MB_2(1024), /**
/**
* 最大速度为10mb * 最大速度为10mb
*/ */
MAX(8192); MAX(8192);

View File

@ -47,14 +47,13 @@ import java.util.concurrent.locks.ReentrantLock;
* *
* Created by Dmytro Voronkevych on 17/06/2014. * Created by Dmytro Voronkevych on 17/06/2014.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused") public class WeakHandler {
public class WeakHandler { private final Handler.Callback mCallback;
private final Handler.Callback mCallback; // hard reference to Callback. We need to keep callback in memory // hard reference to Callback. We need to keep callback in memory
private final ExecHandler mExec; private final ExecHandler mExec;
private Lock mLock = new ReentrantLock(); private Lock mLock = new ReentrantLock();
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions") @VisibleForTesting final ChainedRef mRunnables =
@VisibleForTesting new ChainedRef(mLock, null);
final ChainedRef mRunnables = new ChainedRef(mLock, null);
/** /**
* Default constructor associates this handler with the {@link Looper} for the * Default constructor associates this handler with the {@link Looper} for the
@ -111,7 +110,6 @@ public class WeakHandler {
* attached. * attached.
* *
* @param r The Runnable that will be executed. * @param r The Runnable that will be executed.
*
* @return Returns true if the Runnable was successfully placed in to the * @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. * looper processing the message queue is exiting.
@ -129,7 +127,6 @@ public class WeakHandler {
* @param r The Runnable that will be executed. * @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run, * @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base. * using the {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the Runnable was successfully placed in to the * @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a * looper processing the message queue is exiting. Note that a
@ -150,14 +147,12 @@ public class WeakHandler {
* @param r The Runnable that will be executed. * @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run, * @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base. * using the {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the Runnable was successfully placed in to the * @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a * looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if * result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message * the looper is quit before the delivery time of the message
* occurs then the message will be dropped. * occurs then the message will be dropped.
*
* @see android.os.SystemClock#uptimeMillis * @see android.os.SystemClock#uptimeMillis
*/ */
public final boolean postAtTime(Runnable r, Object token, long uptimeMillis) { public final boolean postAtTime(Runnable r, Object token, long uptimeMillis) {
@ -173,7 +168,6 @@ public class WeakHandler {
* @param r The Runnable that will be executed. * @param r The Runnable that will be executed.
* @param delayMillis The delay (in milliseconds) until the Runnable * @param delayMillis The delay (in milliseconds) until the Runnable
* will be executed. * will be executed.
*
* @return Returns true if the Runnable was successfully placed in to the * @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a * looper processing the message queue is exiting. Note that a
@ -195,7 +189,6 @@ public class WeakHandler {
* other unexpected side-effects.</b> * other unexpected side-effects.</b>
* *
* @param r The Runnable that will be executed. * @param r The Runnable that will be executed.
*
* @return Returns true if the message was successfully placed in to the * @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. * looper processing the message queue is exiting.
@ -253,11 +246,11 @@ public class WeakHandler {
/** /**
* Sends a Message containing only the what value, to be delivered * Sends a Message containing only the what value, to be delivered
* after the specified amount of time elapses. * after the specified amount of time elapses.
* @see #sendMessageDelayed(android.os.Message, long)
* *
* @return Returns true if the message was successfully placed in to the * @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. * looper processing the message queue is exiting.
* @see #sendMessageDelayed(android.os.Message, long)
*/ */
public final boolean sendEmptyMessageDelayed(int what, long delayMillis) { public final boolean sendEmptyMessageDelayed(int what, long delayMillis) {
return mExec.sendEmptyMessageDelayed(what, delayMillis); return mExec.sendEmptyMessageDelayed(what, delayMillis);
@ -266,11 +259,11 @@ public class WeakHandler {
/** /**
* Sends a Message containing only the what value, to be delivered * Sends a Message containing only the what value, to be delivered
* at a specific time. * at a specific time.
* @see #sendMessageAtTime(android.os.Message, long)
* *
* @return Returns true if the message was successfully placed in to the * @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. * looper processing the message queue is exiting.
* @see #sendMessageAtTime(android.os.Message, long)
*/ */
public final boolean sendEmptyMessageAtTime(int what, long uptimeMillis) { public final boolean sendEmptyMessageAtTime(int what, long uptimeMillis) {
return mExec.sendEmptyMessageAtTime(what, uptimeMillis); return mExec.sendEmptyMessageAtTime(what, uptimeMillis);
@ -302,7 +295,6 @@ public class WeakHandler {
* @param uptimeMillis The absolute time at which the message should be * @param uptimeMillis The absolute time at which the message should be
* delivered, using the * delivered, using the
* {@link android.os.SystemClock#uptimeMillis} time-base. * {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the message was successfully placed in to the * @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the * message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a * looper processing the message queue is exiting. Note that a
@ -407,8 +399,7 @@ public class WeakHandler {
mCallback = callback; mCallback = callback;
} }
@Override @Override public void handleMessage(@NonNull Message msg) {
public void handleMessage(@NonNull Message msg) {
if (mCallback == null) { if (mCallback == null) {
return; return;
} }
@ -429,8 +420,7 @@ public class WeakHandler {
mReference = reference; mReference = reference;
} }
@Override @Override public void run() {
public void run() {
final Runnable delegate = mDelegate.get(); final Runnable delegate = mDelegate.get();
final ChainedRef reference = mReference.get(); final ChainedRef reference = mReference.get();
if (reference != null) { if (reference != null) {
@ -443,17 +433,12 @@ public class WeakHandler {
} }
static class ChainedRef { static class ChainedRef {
@Nullable @Nullable ChainedRef next;
ChainedRef next; @Nullable ChainedRef prev;
@Nullable @NonNull final Runnable runnable;
ChainedRef prev; @NonNull final WeakRunnable wrapper;
@NonNull
final Runnable runnable;
@NonNull
final WeakRunnable wrapper;
@NonNull @NonNull Lock lock;
Lock lock;
public ChainedRef(@NonNull Lock lock, @NonNull Runnable r) { public ChainedRef(@NonNull Lock lock, @NonNull Runnable r) {
this.runnable = r; this.runnable = r;
@ -493,8 +478,7 @@ public class WeakHandler {
} }
} }
@Nullable @Nullable public WeakRunnable remove(Runnable obj) {
public WeakRunnable remove(Runnable obj) {
lock.lock(); lock.lock();
try { try {
ChainedRef curr = this.next; // Skipping head ChainedRef curr = this.next; // Skipping head

View File

@ -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.window; package com.arialyy.aria.window;
import android.os.Bundle; import android.os.Bundle;
@ -49,7 +64,4 @@ public class AriaFileChangeActivity extends FragmentActivity {
private void loadMore() { private void loadMore() {
} }
} }

View File

@ -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.window; package com.arialyy.aria.window;
import android.content.Context; import android.content.Context;

View File

@ -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.window; package com.arialyy.aria.window;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;

View File

@ -29,6 +29,8 @@
<activity android:name=".download.multi_download.MultiTaskActivity"/> <activity android:name=".download.multi_download.MultiTaskActivity"/>
<activity android:name=".download.fragment_download.FragmentActivity"/> <activity android:name=".download.fragment_download.FragmentActivity"/>
<activity android:name=".download.multi_download.MultiDownloadActivity"/> <activity android:name=".download.multi_download.MultiDownloadActivity"/>
<service android:name=".download.service_download.DownloadService"/>
</application> </application>
</manifest> </manifest>

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple; package com.arialyy.simple;
import android.content.Intent; import android.content.Intent;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.simple.base; package com.arialyy.simple.base;
import android.app.Application; import android.app.Application;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.simple.base; package com.arialyy.simple.base;
import android.databinding.ViewDataBinding; import android.databinding.ViewDataBinding;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.simple.base; package com.arialyy.simple.base;
import android.content.Context; import android.content.Context;

View File

@ -33,6 +33,7 @@ import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadMeanBinding; import com.arialyy.simple.databinding.ActivityDownloadMeanBinding;
import com.arialyy.simple.download.fragment_download.FragmentActivity; import com.arialyy.simple.download.fragment_download.FragmentActivity;
import com.arialyy.simple.download.multi_download.MultiTaskActivity; import com.arialyy.simple.download.multi_download.MultiTaskActivity;
import com.arialyy.simple.download.service_download.DownloadService;
/** /**
* Created by Lyy on 2016/10/13. * Created by Lyy on 2016/10/13.
@ -84,6 +85,9 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.service:
startService(new Intent(this, DownloadService.class));
break;
case R.id.single_task: case R.id.single_task:
startActivity(new Intent(this, SingleTaskActivity.class)); startActivity(new Intent(this, SingleTaskActivity.class));
break; break;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download; package com.arialyy.simple.download;
import android.content.Context; import android.content.Context;

View File

@ -44,9 +44,12 @@ public class DownloadModule extends BaseModule {
public DownloadModule(Context context) { public DownloadModule(Context context) {
super(context); super(context);
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk"); mTestDownloadUrl.add(
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk"); "http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"); mTestDownloadUrl.add(
"http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
mTestDownloadUrl.add(
"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
} }
public String getRadomUrl() { public String getRadomUrl() {

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download; package com.arialyy.simple.download;
import android.content.Context; import android.content.Context;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download; package com.arialyy.simple.download;
import android.app.NotificationManager; import android.app.NotificationManager;

View File

@ -26,7 +26,6 @@ import android.os.Message;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -38,6 +37,7 @@ import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Speed; import com.arialyy.aria.util.Speed;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivitySingleBinding; import com.arialyy.simple.databinding.ActivitySingleBinding;
@ -239,6 +239,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
private class MySchedulerListener extends Aria.DownloadSchedulerListener { private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onNoSupportBreakPoint(DownloadTask task) {
super.onNoSupportBreakPoint(task);
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
}
@Override public void onTaskStart(DownloadTask task) { @Override public void onTaskStart(DownloadTask task) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()) mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
.sendToTarget(); .sendToTarget();

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.fragment_download; package com.arialyy.simple.download.fragment_download;
import android.os.Bundle; import android.os.Bundle;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.fragment_download; package com.arialyy.simple.download.fragment_download;
import com.arialyy.simple.R; import com.arialyy.simple.R;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.simple.download.multi_download; package com.arialyy.simple.download.multi_download;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.multi_download; package com.arialyy.simple.download.multi_download;
import android.content.Context; import android.content.Context;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.multi_download; package com.arialyy.simple.download.multi_download;
/** /**

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.multi_download; package com.arialyy.simple.download.multi_download;
import android.os.Bundle; import android.os.Bundle;

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.service_download;
import android.app.NotificationManager;
import android.content.Context;
import android.support.v4.app.NotificationCompat;
import com.arialyy.simple.R;
/**
* Created by Aria.Lao on 2017/1/18.
*/
public class DownloadNotification {
private NotificationManager mManager;
private Context mContext;
private NotificationCompat.Builder mBuilder;
private static final int mNotifiyId = 0;
public DownloadNotification(Context context) {
mContext = context;
init();
}
private void init() {
mManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(mContext);
mBuilder.setContentTitle("Aria Download Test")
.setContentText("进度条")
.setProgress(100, 0, false)
.setSmallIcon(R.mipmap.ic_launcher);
mManager.notify(mNotifiyId, mBuilder.build());
}
public void upload(int progress){
if (mBuilder != null) {
mBuilder.setProgress(100, progress, false);
mManager.notify(mNotifiyId, mBuilder.build());
}
}
}

View File

@ -0,0 +1,102 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.download.service_download;
import android.app.Service;
import android.content.Intent;
import android.os.Environment;
import android.os.IBinder;
import android.support.annotation.Nullable;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.frame.util.show.T;
/**
* Created by Aria.Lao on 2017/4/5.
* 在服务中使用 Aria进行下载
*/
public class DownloadService extends Service {
private static final String DOWNLOAD_URL =
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
//"http://static.gaoshouyou.com/d/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk";
//不支持断点的链接
"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
private DownloadNotification mNotify;
@Nullable @Override public IBinder onBind(Intent intent) {
return null;
}
@Override public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override public void onCreate() {
super.onCreate();
mNotify = new DownloadNotification(getApplicationContext());
Aria.download(this).addSchedulerListener(new MySchedulerListener());
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk")
.start();
}
@Override public void onDestroy() {
super.onDestroy();
Aria.download(this).removeSchedulerListener();
}
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onNoSupportBreakPoint(DownloadTask task) {
super.onNoSupportBreakPoint(task);
T.showShort(getApplicationContext(), "该下载链接不支持断点");
}
@Override public void onTaskStart(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载");
}
@Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task);
}
@Override public void onTaskStop(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载");
}
@Override public void onTaskCancel(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载");
}
@Override public void onTaskFail(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败");
}
@Override public void onTaskComplete(DownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成");
mNotify.upload(100);
}
@Override public void onTaskRunning(DownloadTask task) {
long len = task.getFileSize();
int p = (int) (task.getCurrentProgress() * 100 / len);
mNotify.upload(p);
}
}
}

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.upload; package com.arialyy.simple.upload;
import android.os.Bundle; import android.os.Bundle;

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.simple.widget; package com.arialyy.simple.widget;
import android.content.Context; import android.content.Context;
@ -48,13 +47,11 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
/** /**
* offset of draw progress * offset of draw progress
*/ */
protected int mTextOffset = protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);
dp2px(DEFAULT_SIZE_TEXT_OFFSET);
/** /**
* height of reached progress bar * height of reached progress bar
*/ */
protected int mReachedProgressBarHeight = protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
/** /**
* color of reached bar * color of reached bar
*/ */
@ -66,8 +63,7 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
/** /**
* height of unreached progress bar * height of unreached progress bar
*/ */
protected int mUnReachedProgressBarHeight = protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
/** /**
* view width except padding * view width except padding
*/ */

View File

@ -65,5 +65,14 @@
style="?buttonBarButtonStyle" style="?buttonBarButtonStyle"
/> />
<Button
android:id="@+id/service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="在Service中使用"
style="?buttonBarButtonStyle"
/>
</LinearLayout> </LinearLayout>
</layout> </layout>

View File

@ -89,6 +89,7 @@
/> />
<RadioGroup <RadioGroup
android:visibility="gone"
android:id="@+id/speeds" android:id="@+id/speeds"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"