代码格式化

pull/2/head
lyy 8 years ago
parent 131b9c2770
commit d1b48b2f64
  1. 20
      downloadutil/jcenter.gradle
  2. 54
      downloadutil/src/main/java/com/arialyy/downloadutil/core/DownLoadUtil.java
  3. 56
      downloadutil/src/main/java/com/arialyy/downloadutil/core/DownloadEntity.java
  4. 22
      downloadutil/src/main/java/com/arialyy/downloadutil/core/DownloadManager.java
  5. 75
      downloadutil/src/main/java/com/arialyy/downloadutil/core/DownloadSchedulers.java
  6. 16
      downloadutil/src/main/java/com/arialyy/downloadutil/core/DownloadTaskQueue.java
  7. 96
      downloadutil/src/main/java/com/arialyy/downloadutil/core/Task.java
  8. 12
      downloadutil/src/main/java/com/arialyy/downloadutil/core/pool/CachePool.java
  9. 12
      downloadutil/src/main/java/com/arialyy/downloadutil/core/pool/ExecutePool.java
  10. 2
      downloadutil/src/main/java/com/arialyy/downloadutil/help/Lockhelp.java
  11. 69
      downloadutil/src/main/java/com/arialyy/downloadutil/orm/DbEntity.java
  12. 12
      downloadutil/src/main/java/com/arialyy/downloadutil/orm/DbUtil.java
  13. 1
      downloadutil/src/main/java/com/arialyy/downloadutil/util/Util.java

@ -40,7 +40,8 @@ javadoc {
// : xxxx
android.libraryVariants.all { variant ->
println variant.javaCompile.classpath.files
if (variant.name == 'release') { // release javadoc
if (variant.name == 'release') {
// release javadoc
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
// title = ''
// description = ''
@ -54,7 +55,8 @@ android.libraryVariants.all { variant ->
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
task("javadoc${variant.name.capitalize()}Jar", type: Jar, dependsOn: "generate${variant.name.capitalize()}Javadoc") {
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
}
@ -91,13 +93,13 @@ def pomConfig = {
}
}
"dependencies " {
// dependency {
// groupId "com.alibaba"
// artifactId "fastjson"
// "version " "1.2.6"
// //dependencies
// }
// }
// dependency {
// groupId "com.alibaba"
// artifactId "fastjson"
// "version " "1.2.6"
// //dependencies
// }
// }
}
}

@ -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
*/

Loading…
Cancel
Save