Aria 重构,Readme编写

This commit is contained in:
AriaLyy
2016-12-13 21:31:37 +08:00
parent 1a2f86a5af
commit 7bb67b403f
52 changed files with 302 additions and 137 deletions

View File

@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 58
versionName "2.3.0"
versionCode 79
versionName "2.3.1"
}
buildTypes {
release {

View File

@ -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 {

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;
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;

View File

@ -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.
@ -26,6 +26,7 @@ import android.os.Build;
/**
* Created by lyy on 2016/12/1.
* https://github.com/AriaLyy/Aria
* Aria启动管理全局任务
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {

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;
import android.annotation.TargetApi;
@ -8,10 +23,12 @@ import android.content.Context;
import android.os.Build;
import android.os.Bundle;
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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -20,6 +37,7 @@ 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 {
@ -48,6 +66,24 @@ import java.util.Set;
return getTarget(obj);
}
/**
* 获取下载列表
*/
public List<DownloadEntity> getDownloadList(){
return DownloadEntity.findAllData(DownloadEntity.class);
}
/**
* 通过下载链接获取下载实体
*/
public DownloadEntity getDownloadEntity(String downloadUrl) {
if (TextUtils.isEmpty(downloadUrl)) {
throw new IllegalArgumentException("下载链接不能为null");
}
return DownloadEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
new String[] { downloadUrl });
}
/**
* 停止所有正在执行的任务
*/
@ -62,11 +98,37 @@ 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 void openBroadcast(boolean open) {
public AriaManager openBroadcast(boolean open) {
Configuration.getInstance().setOpenBroadcast(open);
return this;
}
/**
@ -74,12 +136,13 @@ import java.util.Set;
*
* @param maxDownloadNum 最大下载数
*/
public void setMaxDownloadNum(int maxDownloadNum) {
if (maxDownloadNum < 1){
public AriaManager setMaxDownloadNum(int maxDownloadNum) {
if (maxDownloadNum < 1) {
Log.w(TAG, "最大任务数不能小于 1");
return;
return this;
}
mManager.getTaskQueue().setDownloadNum(maxDownloadNum);
return this;
}
/**

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

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.command;
import android.util.Log;

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

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.scheduler;
import com.arialyy.aria.core.task.Task;

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.
@ -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);
}
}
}
}

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

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;
import android.util.Log;
@ -36,6 +51,7 @@ public class Configuration {
* 超时时间,默认 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;
@ -57,6 +73,8 @@ public class Configuration {
mConfigFile.getParentFile().mkdirs();
mConfigFile.createNewFile();
init();
}else {
isOpenBreadCast = isOpenBroadcast();
}
} catch (IOException e) {
e.printStackTrace();
@ -123,7 +141,7 @@ public class Configuration {
/**
* 设置重试间隔
*/
public void setReTryreTryInterval(int reTryInterval) {
public void setReTryInterval(int reTryInterval) {
if (reTryInterval < 4000) {
Log.w(TAG, "重试间隔不能小于4000ms");
return;
@ -184,6 +202,7 @@ public class Configuration {
* 设置是否打开下载广播
*/
public void setOpenBroadcast(boolean openBroadcast) {
isOpenBreadCast = openBroadcast;
save(OPEN_BROADCAST, openBroadcast + "");
}
}

View File

@ -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.