代码格式化
This commit is contained in:
@ -1,26 +1,26 @@
|
||||
apply plugin: 'com.android.library'
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.2"
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 58
|
||||
versionName "2.1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 58
|
||||
versionName "2.1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
}
|
||||
|
||||
apply from: 'jcenter.gradle'
|
@ -6,30 +6,30 @@ apply plugin: "com.jfrog.artifactory"
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
classifier = 'sources'
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
task javadoc(type: Javadoc) {
|
||||
source = android.sourceSets.main.java.srcDirs
|
||||
classpath += configurations.compile
|
||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||
source = android.sourceSets.main.java.srcDirs
|
||||
classpath += configurations.compile
|
||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options {
|
||||
encoding "UTF-8"
|
||||
charSet 'UTF-8'
|
||||
author true
|
||||
version true
|
||||
links "http://docs.oracle.com/javase/7/docs/api"
|
||||
title PROJ_ARTIFACTID
|
||||
}
|
||||
options {
|
||||
encoding "UTF-8"
|
||||
charSet 'UTF-8'
|
||||
author true
|
||||
version true
|
||||
links "http://docs.oracle.com/javase/7/docs/api"
|
||||
title PROJ_ARTIFACTID
|
||||
}
|
||||
}
|
||||
|
||||
//添加以下信息避免JAVADOC打包时引用其它类库而出现问题,比如出现以下错误
|
||||
@ -39,128 +39,130 @@ javadoc {
|
||||
// 符号: 类 JsonElement
|
||||
// 位置: 类 xxxx
|
||||
android.libraryVariants.all { variant ->
|
||||
println variant.javaCompile.classpath.files
|
||||
if (variant.name == 'release') { //我们只需 release 的 javadoc
|
||||
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
|
||||
// title = ''
|
||||
// description = ''
|
||||
source = variant.javaCompile.source
|
||||
classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
|
||||
options {
|
||||
encoding "utf-8"
|
||||
links "http://docs.oracle.com/javase/7/docs/api/"
|
||||
linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
|
||||
}
|
||||
exclude '**/BuildConfig.java'
|
||||
exclude '**/R.java'
|
||||
}
|
||||
task("javadoc${variant.name.capitalize()}Jar", type: Jar, dependsOn: "generate${variant.name.capitalize()}Javadoc") {
|
||||
classifier = 'javadoc'
|
||||
from tasks.getByName("generate${variant.name.capitalize()}Javadoc").destinationDir
|
||||
}
|
||||
artifacts {
|
||||
archives tasks.getByName("javadoc${variant.name.capitalize()}Jar")
|
||||
}
|
||||
println variant.javaCompile.classpath.files
|
||||
if (variant.name == 'release') {
|
||||
//我们只需 release 的 javadoc
|
||||
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
|
||||
// title = ''
|
||||
// description = ''
|
||||
source = variant.javaCompile.source
|
||||
classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
|
||||
options {
|
||||
encoding "utf-8"
|
||||
links "http://docs.oracle.com/javase/7/docs/api/"
|
||||
linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
|
||||
}
|
||||
exclude '**/BuildConfig.java'
|
||||
exclude '**/R.java'
|
||||
}
|
||||
task("javadoc${variant.name.capitalize()}Jar", type: Jar,
|
||||
dependsOn: "generate${variant.name.capitalize()}Javadoc") {
|
||||
classifier = 'javadoc'
|
||||
from tasks.getByName("generate${variant.name.capitalize()}Javadoc").destinationDir
|
||||
}
|
||||
artifacts {
|
||||
archives tasks.getByName("javadoc${variant.name.capitalize()}Jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
|
||||
def pomConfig = {
|
||||
scm {
|
||||
connection PROJ_VCSURL
|
||||
developerConnection PROJ_VCSURL
|
||||
url PROJ_WEBSITEURL
|
||||
scm {
|
||||
connection PROJ_VCSURL
|
||||
developerConnection PROJ_VCSURL
|
||||
url PROJ_WEBSITEURL
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name "The Apache Software License, Version 2.0"
|
||||
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||
distribution "repo"
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name "The Apache Software License, Version 2.0"
|
||||
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||
distribution "repo"
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id DEVELOPER_ID
|
||||
name DEVELOPER_NAME
|
||||
email DEVELOPER_EMAIL
|
||||
}
|
||||
}
|
||||
"dependencies " {
|
||||
// dependency {
|
||||
// groupId "com.alibaba"
|
||||
// artifactId "fastjson"
|
||||
// "version " "1.2.6"
|
||||
// //同dependencies
|
||||
// }
|
||||
// }
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id DEVELOPER_ID
|
||||
name DEVELOPER_NAME
|
||||
email DEVELOPER_EMAIL
|
||||
}
|
||||
}
|
||||
"dependencies " {
|
||||
// dependency {
|
||||
// groupId "com.alibaba"
|
||||
// artifactId "fastjson"
|
||||
// "version " "1.2.6"
|
||||
// //同dependencies
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId PROJ_ARTIFACTID
|
||||
artifact javadocJar
|
||||
artifact sourcesJar
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId PROJ_ARTIFACTID
|
||||
artifact javadocJar
|
||||
artifact sourcesJar
|
||||
|
||||
pom {
|
||||
packaging 'aar'
|
||||
}
|
||||
pom.withXml {
|
||||
def root = asNode()
|
||||
root.appendNode('description', PROJ_DESCRIPTION)
|
||||
root.children().last() + pomConfig
|
||||
}
|
||||
}
|
||||
pom {
|
||||
packaging 'aar'
|
||||
}
|
||||
pom.withXml {
|
||||
def root = asNode()
|
||||
root.appendNode('description', PROJ_DESCRIPTION)
|
||||
root.children().last() + pomConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
publishing.publications.mavenJava.artifact(bundleRelease)
|
||||
publishing.publications.mavenJava.artifact(bundleRelease)
|
||||
}
|
||||
|
||||
bintray {
|
||||
user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER")
|
||||
key = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
|
||||
user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER")
|
||||
key = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
|
||||
|
||||
configurations = ['archives']
|
||||
publications = ['mavenJava']
|
||||
publish = true
|
||||
configurations = ['archives']
|
||||
publications = ['mavenJava']
|
||||
publish = true
|
||||
|
||||
pkg {
|
||||
repo = 'maven'
|
||||
name = PROJ_NAME
|
||||
desc = PROJ_DESCRIPTION
|
||||
websiteUrl = PROJ_WEBSITEURL
|
||||
issueTrackerUrl = PROJ_ISSUETRACKERURL
|
||||
vcsUrl = PROJ_VCSURL
|
||||
licenses = ['Apache-2.0']
|
||||
publicDownloadNumbers = true
|
||||
}
|
||||
pkg {
|
||||
repo = 'maven'
|
||||
name = PROJ_NAME
|
||||
desc = PROJ_DESCRIPTION
|
||||
websiteUrl = PROJ_WEBSITEURL
|
||||
issueTrackerUrl = PROJ_ISSUETRACKERURL
|
||||
vcsUrl = PROJ_VCSURL
|
||||
licenses = ['Apache-2.0']
|
||||
publicDownloadNumbers = true
|
||||
}
|
||||
}
|
||||
|
||||
artifactory {
|
||||
contextUrl = 'http://oss.jfrog.org/artifactory'
|
||||
resolve {
|
||||
repository {
|
||||
repoKey = 'libs-release'
|
||||
}
|
||||
contextUrl = 'http://oss.jfrog.org/artifactory'
|
||||
resolve {
|
||||
repository {
|
||||
repoKey = 'libs-release'
|
||||
}
|
||||
publish {
|
||||
repository {
|
||||
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
|
||||
username = bintray.user
|
||||
password = bintray.key
|
||||
maven = true
|
||||
}
|
||||
defaults {
|
||||
publications('mavenJava')
|
||||
publishArtifacts = true
|
||||
}
|
||||
}
|
||||
publish {
|
||||
repository {
|
||||
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
|
||||
username = bintray.user
|
||||
password = bintray.key
|
||||
maven = true
|
||||
}
|
||||
defaults {
|
||||
publications('mavenJava')
|
||||
publishArtifacts = true
|
||||
}
|
||||
}
|
||||
}
|
@ -24,12 +24,12 @@ import java.util.concurrent.Executors;
|
||||
final class DownloadUtil implements IDownloadUtil {
|
||||
private static final String TAG = "DownloadUtil";
|
||||
private static final Object LOCK = new Object();
|
||||
//下载监听
|
||||
private IDownloadListener mListener;
|
||||
/**
|
||||
* 线程数
|
||||
*/
|
||||
private final int THREAD_NUM;
|
||||
//下载监听
|
||||
private IDownloadListener mListener;
|
||||
private int mConnectTimeOut = 5000 * 4; //连接超时时间
|
||||
private int mReadTimeOut = 5000 * 20; //流读取的超时时间
|
||||
/**
|
||||
@ -314,6 +314,31 @@ final class DownloadUtil implements IDownloadUtil {
|
||||
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程下载信息类
|
||||
*/
|
||||
private static class ConfigEntity {
|
||||
//文件大小
|
||||
long fileSize;
|
||||
String downloadUrl;
|
||||
int threadId;
|
||||
long startLocation;
|
||||
long endLocation;
|
||||
File tempFile;
|
||||
Context context;
|
||||
|
||||
private ConfigEntity(Context context, long fileSize, String downloadUrl, File file,
|
||||
int threadId, long startLocation, long endLocation) {
|
||||
this.fileSize = fileSize;
|
||||
this.downloadUrl = downloadUrl;
|
||||
this.tempFile = file;
|
||||
this.threadId = threadId;
|
||||
this.startLocation = startLocation;
|
||||
this.endLocation = endLocation;
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个线程的下载任务
|
||||
*/
|
||||
@ -490,29 +515,4 @@ final class DownloadUtil implements IDownloadUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程下载信息类
|
||||
*/
|
||||
private static class ConfigEntity {
|
||||
//文件大小
|
||||
long fileSize;
|
||||
String downloadUrl;
|
||||
int threadId;
|
||||
long startLocation;
|
||||
long endLocation;
|
||||
File tempFile;
|
||||
Context context;
|
||||
|
||||
private ConfigEntity(Context context, long fileSize, String downloadUrl, File file,
|
||||
int threadId, long startLocation, long endLocation) {
|
||||
this.fileSize = fileSize;
|
||||
this.downloadUrl = downloadUrl;
|
||||
this.tempFile = file;
|
||||
this.threadId = threadId;
|
||||
this.startLocation = startLocation;
|
||||
this.endLocation = endLocation;
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
}
|
@ -48,7 +48,15 @@ public class DownloadEntity extends DbEntity implements Parcelable {
|
||||
* 取消下载
|
||||
*/
|
||||
@Ignore public static final int STATE_CANCEL = 7;
|
||||
@Ignore public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() {
|
||||
@Override public DownloadEntity createFromParcel(Parcel source) {
|
||||
return new DownloadEntity(source);
|
||||
}
|
||||
|
||||
@Override public DownloadEntity[] newArray(int size) {
|
||||
return new DownloadEntity[size];
|
||||
}
|
||||
};
|
||||
@Ignore private long speed = 0; //下载速度
|
||||
private String downloadUrl = ""; //下载路径
|
||||
private String downloadPath = ""; //保存路径
|
||||
@ -64,6 +72,21 @@ public class DownloadEntity extends DbEntity implements Parcelable {
|
||||
public DownloadEntity() {
|
||||
}
|
||||
|
||||
protected DownloadEntity(Parcel in) {
|
||||
this.downloadUrl = in.readString();
|
||||
this.downloadPath = in.readString();
|
||||
this.fileName = in.readString();
|
||||
this.str = in.readString();
|
||||
this.completeTime = in.readLong();
|
||||
this.fileSize = in.readLong();
|
||||
this.state = in.readInt();
|
||||
this.isDownloadComplete = in.readByte() != 0;
|
||||
this.currentProgress = in.readLong();
|
||||
this.failNum = in.readInt();
|
||||
this.speed = in.readLong();
|
||||
this.rowID = in.readInt();
|
||||
}
|
||||
|
||||
public String getStr() {
|
||||
return str;
|
||||
}
|
||||
@ -92,6 +115,10 @@ public class DownloadEntity extends DbEntity implements Parcelable {
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
public void setDownloadUrl(String downloadUrl) {
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
|
||||
public long getCompleteTime() {
|
||||
return completeTime;
|
||||
}
|
||||
@ -100,10 +127,6 @@ public class DownloadEntity extends DbEntity implements Parcelable {
|
||||
this.completeTime = completeTime;
|
||||
}
|
||||
|
||||
public void setDownloadUrl(String downloadUrl) {
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
|
||||
public String getDownloadPath() {
|
||||
return downloadPath;
|
||||
}
|
||||
@ -187,29 +210,4 @@ public class DownloadEntity extends DbEntity implements Parcelable {
|
||||
dest.writeLong(this.speed);
|
||||
dest.writeInt(this.rowID);
|
||||
}
|
||||
|
||||
protected DownloadEntity(Parcel in) {
|
||||
this.downloadUrl = in.readString();
|
||||
this.downloadPath = in.readString();
|
||||
this.fileName = in.readString();
|
||||
this.str = in.readString();
|
||||
this.completeTime = in.readLong();
|
||||
this.fileSize = in.readLong();
|
||||
this.state = in.readInt();
|
||||
this.isDownloadComplete = in.readByte() != 0;
|
||||
this.currentProgress = in.readLong();
|
||||
this.failNum = in.readInt();
|
||||
this.speed = in.readLong();
|
||||
this.rowID = in.readInt();
|
||||
}
|
||||
|
||||
@Ignore public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() {
|
||||
@Override public DownloadEntity createFromParcel(Parcel source) {
|
||||
return new DownloadEntity(source);
|
||||
}
|
||||
|
||||
@Override public DownloadEntity[] newArray(int size) {
|
||||
return new DownloadEntity[size];
|
||||
}
|
||||
};
|
||||
}
|
@ -14,78 +14,64 @@ import java.util.List;
|
||||
* 下载管理器,通过命令的方式控制下载
|
||||
*/
|
||||
public class DownloadManager {
|
||||
private static final String TAG = "DownloadManager";
|
||||
private static final Object LOCK = new Object();
|
||||
private static volatile DownloadManager INSTANCE = null;
|
||||
|
||||
/**
|
||||
* 预处理完成
|
||||
*/
|
||||
public static final String ACTION_PRE = "ACTION_PRE";
|
||||
|
||||
/**
|
||||
* 下载开始前事件
|
||||
*/
|
||||
public static final String ACTION_POST_PRE = "ACTION_POST_PRE";
|
||||
|
||||
/**
|
||||
* 开始下载事件
|
||||
*/
|
||||
public static final String ACTION_START = "ACTION_START";
|
||||
|
||||
/**
|
||||
* 恢复下载事件
|
||||
*/
|
||||
public static final String ACTION_RESUME = "ACTION_RESUME";
|
||||
|
||||
/**
|
||||
* 正在下载事件
|
||||
*/
|
||||
public static final String ACTION_RUNNING = "ACTION_RUNNING";
|
||||
|
||||
/**
|
||||
* 停止下载事件
|
||||
*/
|
||||
public static final String ACTION_STOP = "ACTION_STOP";
|
||||
|
||||
/**
|
||||
* 取消下载事件
|
||||
*/
|
||||
public static final String ACTION_CANCEL = "ACTION_CANCEL";
|
||||
|
||||
/**
|
||||
* 下载完成事件
|
||||
*/
|
||||
public static final String ACTION_COMPLETE = "ACTION_COMPLETE";
|
||||
|
||||
/**
|
||||
* 下载失败事件
|
||||
*/
|
||||
public static final String ACTION_FAIL = "ACTION_FAIL";
|
||||
|
||||
/**
|
||||
* 下载实体
|
||||
*/
|
||||
public static final String ENTITY = "DOWNLOAD_ENTITY";
|
||||
|
||||
/**
|
||||
* 位置
|
||||
*/
|
||||
public static final String CURRENT_LOCATION = "CURRENT_LOCATION";
|
||||
|
||||
/**
|
||||
* 速度
|
||||
*/
|
||||
public static final String CURRENT_SPEED = "CURRENT_SPEED";
|
||||
|
||||
private static final String TAG = "DownloadManager";
|
||||
private static final Object LOCK = new Object();
|
||||
private static volatile DownloadManager INSTANCE = null;
|
||||
private List<IDownloadCmd> mCommands = new ArrayList<>();
|
||||
private Context mContext;
|
||||
|
||||
private DownloadManager() {
|
||||
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private DownloadManager(Context context) {
|
||||
mContext = context;
|
||||
DownloadTaskQueue.init(context);
|
||||
|
@ -10,9 +10,6 @@ import com.arialyy.downloadutil.core.pool.ExecutePool;
|
||||
* 任务下载器,提供抽象的方法供具体的实现类操作
|
||||
*/
|
||||
public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
private static final String TAG = "DownloadSchedulers";
|
||||
private static final Object LOCK = new Object();
|
||||
private static volatile DownloadSchedulers INSTANCE = null;
|
||||
/**
|
||||
* 任务开始
|
||||
*/
|
||||
@ -33,7 +30,9 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
* 任务完成
|
||||
*/
|
||||
public static final int COMPLETE = 5;
|
||||
|
||||
private static final String TAG = "DownloadSchedulers";
|
||||
private static final Object LOCK = new Object();
|
||||
private static volatile DownloadSchedulers INSTANCE = null;
|
||||
/**
|
||||
* 下载失败次数
|
||||
*/
|
||||
@ -50,6 +49,10 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
OnTargetListener mTargetListener;
|
||||
DownloadTaskQueue mQueue;
|
||||
|
||||
public DownloadSchedulers(DownloadTaskQueue downloadTaskQueue) {
|
||||
mQueue = downloadTaskQueue;
|
||||
}
|
||||
|
||||
public static DownloadSchedulers getInstance(DownloadTaskQueue queue) {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (LOCK) {
|
||||
@ -59,40 +62,6 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target处理任务监听
|
||||
*/
|
||||
public interface OnTargetListener {
|
||||
/**
|
||||
* 任务开始
|
||||
*/
|
||||
public void onTaskStart(Task task);
|
||||
|
||||
/**
|
||||
* 任务停止
|
||||
*/
|
||||
public void onTaskStop(Task task);
|
||||
|
||||
/**
|
||||
* 任务取消
|
||||
*/
|
||||
public void onTaskCancel(Task task);
|
||||
|
||||
/**
|
||||
* 任务下载失败
|
||||
*/
|
||||
public void onTaskFail(Task task);
|
||||
|
||||
/**
|
||||
* 任务完成
|
||||
*/
|
||||
public void onTaskComplete(Task task);
|
||||
}
|
||||
|
||||
public DownloadSchedulers(DownloadTaskQueue downloadTaskQueue) {
|
||||
mQueue = downloadTaskQueue;
|
||||
}
|
||||
|
||||
@Override public boolean handleMessage(Message msg) {
|
||||
DownloadEntity entity = (DownloadEntity) msg.obj;
|
||||
if (entity == null) {
|
||||
@ -193,4 +162,34 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
public void setTimeOut(long timeOut) {
|
||||
this.mTimeOut = timeOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target处理任务监听
|
||||
*/
|
||||
public interface OnTargetListener {
|
||||
/**
|
||||
* 任务开始
|
||||
*/
|
||||
public void onTaskStart(Task task);
|
||||
|
||||
/**
|
||||
* 任务停止
|
||||
*/
|
||||
public void onTaskStop(Task task);
|
||||
|
||||
/**
|
||||
* 任务取消
|
||||
*/
|
||||
public void onTaskCancel(Task task);
|
||||
|
||||
/**
|
||||
* 任务下载失败
|
||||
*/
|
||||
public void onTaskFail(Task task);
|
||||
|
||||
/**
|
||||
* 任务完成
|
||||
*/
|
||||
public void onTaskComplete(Task task);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,14 @@ public class DownloadTaskQueue implements ITaskQueue, IDownloader {
|
||||
private ExecutePool mExecutePool = ExecutePool.getInstance();
|
||||
private Context mContext;
|
||||
|
||||
private DownloadTaskQueue() {
|
||||
}
|
||||
|
||||
private DownloadTaskQueue(Context context) {
|
||||
super();
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public static DownloadTaskQueue getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
throw new NullPointerException("请在Application中调用init进行注册");
|
||||
@ -36,14 +44,6 @@ public class DownloadTaskQueue implements ITaskQueue, IDownloader {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private DownloadTaskQueue() {
|
||||
}
|
||||
|
||||
private DownloadTaskQueue(Context context) {
|
||||
super();
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务执行池
|
||||
*/
|
||||
|
@ -127,6 +127,54 @@ public class Task {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
DownloadEntity downloadEntity;
|
||||
Handler outHandler;
|
||||
Context context;
|
||||
int threadNum = 3;
|
||||
IDownloadUtil downloadUtil;
|
||||
|
||||
public Builder(Context context, DownloadEntity downloadEntity) {
|
||||
this.context = context;
|
||||
this.downloadEntity = downloadEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置自定义Handler处理下载状态时间
|
||||
*
|
||||
* @param schedulers {@link IDownloadSchedulers}
|
||||
*/
|
||||
public Builder setOutHandler(IDownloadSchedulers schedulers) {
|
||||
this.outHandler = new Handler(schedulers);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置线程数
|
||||
*/
|
||||
public Builder setThreadNum(int threadNum) {
|
||||
this.threadNum = threadNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
///**
|
||||
// * 设置自定义下载工具
|
||||
// *
|
||||
// * @param downloadUtil {@link IDownloadUtil}
|
||||
// */
|
||||
//public Builder setDownloadUtil(IDownloadUtil downloadUtil) {
|
||||
// this.downloadUtil = downloadUtil;
|
||||
// return this;
|
||||
//}
|
||||
|
||||
public Task build() {
|
||||
Task task = new Task(context, downloadEntity);
|
||||
task.mOutHandler = outHandler;
|
||||
downloadEntity.save();
|
||||
return task;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载监听类
|
||||
*/
|
||||
@ -239,52 +287,4 @@ public class Task {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
DownloadEntity downloadEntity;
|
||||
Handler outHandler;
|
||||
Context context;
|
||||
int threadNum = 3;
|
||||
IDownloadUtil downloadUtil;
|
||||
|
||||
public Builder(Context context, DownloadEntity downloadEntity) {
|
||||
this.context = context;
|
||||
this.downloadEntity = downloadEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置自定义Handler处理下载状态时间
|
||||
*
|
||||
* @param schedulers {@link IDownloadSchedulers}
|
||||
*/
|
||||
public Builder setOutHandler(IDownloadSchedulers schedulers) {
|
||||
this.outHandler = new Handler(schedulers);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置线程数
|
||||
*/
|
||||
public Builder setThreadNum(int threadNum) {
|
||||
this.threadNum = threadNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
///**
|
||||
// * 设置自定义下载工具
|
||||
// *
|
||||
// * @param downloadUtil {@link IDownloadUtil}
|
||||
// */
|
||||
//public Builder setDownloadUtil(IDownloadUtil downloadUtil) {
|
||||
// this.downloadUtil = downloadUtil;
|
||||
// return this;
|
||||
//}
|
||||
|
||||
public Task build() {
|
||||
Task task = new Task(context, downloadEntity);
|
||||
task.mOutHandler = outHandler;
|
||||
downloadEntity.save();
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package com.arialyy.downloadutil.core.pool;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.downloadutil.core.inf.IPool;
|
||||
import com.arialyy.downloadutil.core.Task;
|
||||
import com.arialyy.downloadutil.core.inf.IPool;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -21,6 +21,11 @@ public class CachePool implements IPool {
|
||||
private Map<String, Task> mCacheArray;
|
||||
private LinkedBlockingQueue<Task> mCacheQueue;
|
||||
|
||||
private CachePool() {
|
||||
mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM);
|
||||
mCacheArray = new HashMap<>();
|
||||
}
|
||||
|
||||
public static CachePool getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (LOCK) {
|
||||
@ -30,11 +35,6 @@ public class CachePool implements IPool {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private CachePool() {
|
||||
mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM);
|
||||
mCacheArray = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override public boolean putTask(Task task) {
|
||||
synchronized (LOCK) {
|
||||
if (task == null) {
|
||||
|
@ -18,11 +18,16 @@ public class ExecutePool implements IPool {
|
||||
private static final String TAG = "ExecutePool";
|
||||
private static final Object LOCK = new Object();
|
||||
private static final long TIME_OUT = 1000;
|
||||
private static volatile ExecutePool INSTANCE = null;
|
||||
public static int SIZE = 2;
|
||||
private static volatile ExecutePool INSTANCE = null;
|
||||
private ArrayBlockingQueue<Task> mExecuteQueue;
|
||||
private Map<String, Task> mExecuteArray;
|
||||
|
||||
private ExecutePool() {
|
||||
mExecuteQueue = new ArrayBlockingQueue<>(SIZE);
|
||||
mExecuteArray = new HashMap<>();
|
||||
}
|
||||
|
||||
public static ExecutePool getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (LOCK) {
|
||||
@ -32,11 +37,6 @@ public class ExecutePool implements IPool {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ExecutePool() {
|
||||
mExecuteQueue = new ArrayBlockingQueue<>(SIZE);
|
||||
mExecuteArray = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override public boolean putTask(Task task) {
|
||||
synchronized (LOCK) {
|
||||
if (task == null) {
|
||||
|
@ -5,6 +5,4 @@ package com.arialyy.downloadutil.help;
|
||||
*/
|
||||
public class LockHelp {
|
||||
public static final Object LOCK = new Object();
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.arialyy.downloadutil.orm;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -12,14 +11,47 @@ import java.util.List;
|
||||
* 所有数据库实体父类
|
||||
*/
|
||||
public class DbEntity {
|
||||
private static final Object LOCK = new Object();
|
||||
protected int rowID = -1;
|
||||
private DbUtil mUtil = DbUtil.getInstance();
|
||||
private static final Object LOCK = new Object();
|
||||
|
||||
protected DbEntity() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
*
|
||||
* @return 没有数据返回null
|
||||
*/
|
||||
public static <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
|
||||
DbUtil util = DbUtil.getInstance();
|
||||
return util.findAllData(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一组数据
|
||||
*
|
||||
* @return 没有数据返回null
|
||||
*/
|
||||
public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, @NonNull String[] wheres,
|
||||
@NonNull String[] values) {
|
||||
DbUtil util = DbUtil.getInstance();
|
||||
return util.findData(clazz, wheres, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一行数据
|
||||
*
|
||||
* @return 没有数据返回null
|
||||
*/
|
||||
public static <T extends DbEntity> T findData(Class<T> clazz, @NonNull String[] wheres,
|
||||
@NonNull String[] values) {
|
||||
DbUtil util = DbUtil.getInstance();
|
||||
List<T> datas = util.findData(clazz, wheres, values);
|
||||
return datas == null ? null : datas.size() > 0 ? datas.get(0) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有行的rowid
|
||||
*/
|
||||
@ -106,37 +138,4 @@ public class DbEntity {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
*
|
||||
* @return 没有数据返回null
|
||||
*/
|
||||
public static <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
|
||||
DbUtil util = DbUtil.getInstance();
|
||||
return util.findAllData(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一组数据
|
||||
*
|
||||
* @return 没有数据返回null
|
||||
*/
|
||||
public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, @NonNull String[] wheres,
|
||||
@NonNull String[] values) {
|
||||
DbUtil util = DbUtil.getInstance();
|
||||
return util.findData(clazz, wheres, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一行数据
|
||||
*
|
||||
* @return 没有数据返回null
|
||||
*/
|
||||
public static <T extends DbEntity> T findData(Class<T> clazz, @NonNull String[] wheres,
|
||||
@NonNull String[] values) {
|
||||
DbUtil util = DbUtil.getInstance();
|
||||
List<T> datas = util.findData(clazz, wheres, values);
|
||||
return datas == null ? null : datas.size() > 0 ? datas.get(0) : null;
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ import java.util.List;
|
||||
*/
|
||||
public class DbUtil {
|
||||
private static final String TAG = "DbUtil";
|
||||
private volatile static DbUtil INSTANCE = null;
|
||||
private static final Object LOCK = new Object();
|
||||
private volatile static DbUtil INSTANCE = null;
|
||||
private int CREATE_TABLE = 0;
|
||||
private int TABLE_EXISTS = 1;
|
||||
private int INSERT_DATA = 2;
|
||||
@ -35,6 +35,10 @@ public class DbUtil {
|
||||
|
||||
}
|
||||
|
||||
private DbUtil(Context context) {
|
||||
mHelper = new SqlHelper(context.getApplicationContext());
|
||||
}
|
||||
|
||||
public static DbUtil init(Context context) {
|
||||
if (context instanceof Application) {
|
||||
synchronized (LOCK) {
|
||||
@ -46,10 +50,6 @@ public class DbUtil {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private DbUtil(Context context) {
|
||||
mHelper = new SqlHelper(context.getApplicationContext());
|
||||
}
|
||||
|
||||
protected static DbUtil getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
throw new NullPointerException("请在Application中调用init进行数据库工具注册注册");
|
||||
@ -292,7 +292,7 @@ public class DbUtil {
|
||||
* @param type {@link DbUtil}
|
||||
*/
|
||||
private void print(int type, String sql) {
|
||||
if (true){
|
||||
if (true) {
|
||||
return;
|
||||
}
|
||||
String str = "";
|
||||
|
@ -159,7 +159,6 @@ public class Util {
|
||||
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "t";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建目录 当目录不存在的时候创建文件,否则返回false
|
||||
*/
|
||||
|
Reference in New Issue
Block a user