pull/330/head
AriaLyy 8 years ago
parent 5d77e917ad
commit 6f24f76fdb
  1. 2
      .idea/modules.xml
  2. 17
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  3. 4
      Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java
  4. 1
      Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
  5. 56
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  6. 1
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java
  7. 14
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  8. 22
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadStateConstance.java
  9. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  10. 18
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  11. 35
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java
  12. 1
      Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java
  14. 17
      Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
  15. 1
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  16. 7
      Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java
  17. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  18. 12
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
  19. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java
  20. 23
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  21. 29
      Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulerListener.java
  22. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulerListener.java
  23. 13
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java
  24. 20
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  25. 15
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  26. 17
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadListener.java
  27. 8
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  28. 21
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  29. 12
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
  30. 15
      Aria/src/main/java/com/arialyy/aria/exception/FileException.java
  31. 14
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  32. 42
      Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
  33. 1
      Aria/src/main/java/com/arialyy/aria/orm/Id.java
  34. 1
      Aria/src/main/java/com/arialyy/aria/orm/Ignore.java
  35. 1
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  36. 16
      Aria/src/main/java/com/arialyy/aria/util/BufferedRandomAccessFile.java
  37. 2
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  38. 10
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  39. 18
      Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
  40. 1
      Aria/src/main/java/com/arialyy/aria/util/PathUtil.java
  41. 27
      Aria/src/main/java/com/arialyy/aria/util/Speed.java
  42. 842
      Aria/src/main/java/com/arialyy/aria/util/WeakHandler.java
  43. 18
      Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java
  44. 15
      Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java
  45. 15
      Aria/src/main/java/com/arialyy/aria/window/FileEntity.java
  46. 2
      app/src/main/AndroidManifest.xml
  47. 16
      app/src/main/java/com/arialyy/simple/MainActivity.java
  48. 1
      app/src/main/java/com/arialyy/simple/base/BaseApplication.java
  49. 5
      app/src/main/java/com/arialyy/simple/base/BaseDialog.java
  50. 1
      app/src/main/java/com/arialyy/simple/base/BaseModule.java
  51. 4
      app/src/main/java/com/arialyy/simple/download/DownloadActivity.java
  52. 30
      app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
  53. 11
      app/src/main/java/com/arialyy/simple/download/DownloadModule.java
  54. 30
      app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java
  55. 16
      app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
  56. 8
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  57. 20
      app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
  58. 16
      app/src/main/java/com/arialyy/simple/download/fragment_download/FragmentActivity.java
  59. 20
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  60. 1
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadNumDialog.java
  61. 22
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java
  62. 16
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListEntity.java
  63. 16
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  64. 6
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  65. 55
      app/src/main/java/com/arialyy/simple/download/service_download/DownloadNotification.java
  66. 102
      app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java
  67. 16
      app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
  68. 50
      app/src/main/java/com/arialyy/simple/widget/HorizontalProgressBarWithNumber.java
  69. 9
      app/src/main/res/layout/activity_download_mean.xml
  70. 1
      app/src/main/res/layout/content_single.xml

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

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

@ -32,9 +32,9 @@ class AddCmd<T extends ITaskEntity> extends AbsCmd<T> {
@Override public void executeCmd() { @Override public void executeCmd() {
ITask task = mQueue.getTask(mEntity.getEntity()); ITask task = mQueue.getTask(mEntity.getEntity());
if (task == null){ if (task == null) {
mQueue.createTask(mTargetName, mEntity); mQueue.createTask(mTargetName, mEntity);
}else { } else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】"); Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
} }
} }

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

@ -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;
@ -30,7 +29,7 @@ import com.arialyy.aria.orm.DbEntity;
* 注意CREATOR要进行@Ignore注解 * 注意CREATOR要进行@Ignore注解
* 并且需要Parcelable时需要手动填写rowID; * 并且需要Parcelable时需要手动填写rowID;
*/ */
public class DownloadEntity extends DbEntity implements Parcelable, IEntity{ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
@Ignore public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() { @Ignore public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() {
@Override public DownloadEntity createFromParcel(Parcel source) { @Override public DownloadEntity createFromParcel(Parcel source) {
return new DownloadEntity(source); return new DownloadEntity(source);
@ -40,16 +39,16 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity{
return new DownloadEntity[size]; return new DownloadEntity[size];
} }
}; };
@Ignore private long speed = 0; //下载速度 @Ignore private long speed = 0; //下载速度
@Ignore private int failNum = 0; @Ignore private int failNum = 0;
private String downloadUrl = ""; //下载路径 private String downloadUrl = ""; //下载路径
private String downloadPath = ""; //保存路径 private String downloadPath = ""; //保存路径
private String fileName = ""; //文件名 private String fileName = ""; //文件名
private String str = ""; //其它字段 private String str = ""; //其它字段
private long fileSize = 1; private long fileSize = 1;
private int state = STATE_WAIT; private int state = STATE_WAIT;
private boolean isDownloadComplete = false; //是否下载完成 private boolean isDownloadComplete = false; //是否下载完成
private long currentProgress = 0; //当前下载进度 private long currentProgress = 0; //当前下载进度
private long completeTime; //完成时间 private long completeTime; //完成时间
public DownloadEntity() { public DownloadEntity() {
@ -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() {

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

@ -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();

@ -20,17 +20,17 @@ package com.arialyy.aria.core.download;
* 下载状态常量 * 下载状态常量
*/ */
final class DownloadStateConstance { final class DownloadStateConstance {
int CANCEL_NUM = 0; int CANCEL_NUM = 0;
int STOP_NUM = 0; int STOP_NUM = 0;
int FAIL_NUM = 0; int FAIL_NUM = 0;
int CONNECT_TIME_OUT = 5000 * 4; //连接超时时间 int CONNECT_TIME_OUT = 5000 * 4; //连接超时时间
int READ_TIME_OUT = 1000 * 20; //流读取的超时时间 int READ_TIME_OUT = 1000 * 20; //流读取的超时时间
int COMPLETE_THREAD_NUM = 0; int COMPLETE_THREAD_NUM = 0;
int THREAD_NUM = 3; int THREAD_NUM = 3;
long CURRENT_LOCATION = 0; long CURRENT_LOCATION = 0;
boolean isDownloading = false; boolean isDownloading = false;
boolean isCancel = false; boolean isCancel = false;
boolean isStop = false; boolean isStop = false;
DownloadStateConstance() { DownloadStateConstance() {
} }

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

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

@ -46,16 +46,16 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
private static final long SUB_LEN = 1024 * 1024; private static final long SUB_LEN = 1024 * 1024;
//下载监听 //下载监听
private IDownloadListener mListener; private IDownloadListener mListener;
private int mConnectTimeOut = 5000 * 4; //连接超时时间 private int mConnectTimeOut = 5000 * 4; //连接超时时间
private int mReadTimeOut = 5000 * 20; //流读取的超时时间 private int mReadTimeOut = 5000 * 20; //流读取的超时时间
private boolean isNewTask = true; private boolean isNewTask = true;
private boolean isSupportBreakpoint = true; private boolean isSupportBreakpoint = true;
private Context mContext; private Context mContext;
private DownloadEntity mDownloadEntity; private DownloadEntity mDownloadEntity;
private DownloadTaskEntity mDownloadTaskEntity; private DownloadTaskEntity mDownloadTaskEntity;
private ExecutorService mFixedThreadPool; private ExecutorService mFixedThreadPool;
private File mDownloadFile; //下载的文件 private File mDownloadFile; //下载的文件
private File mConfigFile;//下载信息配置文件 private File mConfigFile;//下载信息配置文件
private SparseArray<Runnable> mTask = new SparseArray<>(); private SparseArray<Runnable> mTask = new SparseArray<>();
private DownloadStateConstance mConstance; private DownloadStateConstance mConstance;
@ -303,7 +303,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
/** /**
* 处理不支持断点的下载 * 处理不支持断点的下载
*/ */
private void handleNoSupportBreakpointDownload(HttpURLConnection conn){ private void handleNoSupportBreakpointDownload(HttpURLConnection conn) {
ConfigEntity entity = new ConfigEntity(); ConfigEntity entity = new ConfigEntity();
long len = conn.getContentLength(); long len = conn.getContentLength();
entity.FILE_SIZE = len; entity.FILE_SIZE = len;
@ -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);
@ -415,13 +418,13 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
*/ */
final static class ConfigEntity { final static class ConfigEntity {
//文件大小 //文件大小
int THREAD_ID; int THREAD_ID;
long FILE_SIZE; long FILE_SIZE;
long START_LOCATION; long START_LOCATION;
long END_LOCATION; long END_LOCATION;
File TEMP_FILE; File TEMP_FILE;
String DOWNLOAD_URL; String DOWNLOAD_URL;
String CONFIG_FILE_PATH; String CONFIG_FILE_PATH;
DownloadTaskEntity DOWNLOAD_TASK_ENTITY; DownloadTaskEntity DOWNLOAD_TASK_ENTITY;
boolean isSupportBreakpoint = true; boolean isSupportBreakpoint = true;
} }

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

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

@ -25,23 +25,23 @@ public interface IEntity {
/** /**
* 其它状态 * 其它状态
*/ */
@Ignore public static final int STATE_OTHER = -1; @Ignore public static final int STATE_OTHER = -1;
/** /**
* 失败状态 * 失败状态
*/ */
@Ignore public static final int STATE_FAIL = 0; @Ignore public static final int STATE_FAIL = 0;
/** /**
* 完成状态 * 完成状态
*/ */
@Ignore public static final int STATE_COMPLETE = 1; @Ignore public static final int STATE_COMPLETE = 1;
/** /**
* 停止状态 * 停止状态
*/ */
@Ignore public static final int STATE_STOP = 2; @Ignore public static final int STATE_STOP = 2;
/** /**
* 未开始状态 * 未开始状态
*/ */
@Ignore public static final int STATE_WAIT = 3; @Ignore public static final int STATE_WAIT = 3;
/** /**
* 下载中 * 下载中
*/ */
@ -49,16 +49,15 @@ public interface IEntity {
/** /**
* 预处理 * 预处理
*/ */
@Ignore public static final int STATE_PRE = 5; @Ignore public static final int STATE_PRE = 5;
/** /**
* 预处理完成 * 预处理完成
*/ */
@Ignore public static final int STATE_POST_PRE = 6; @Ignore public static final int STATE_POST_PRE = 6;
/** /**
* 取消下载 * 取消下载
*/ */
@Ignore public static final int STATE_CANCEL = 7; @Ignore public static final int STATE_CANCEL = 7;
public int getState(); public int getState();
} }

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

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

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

@ -30,11 +30,11 @@ import java.util.concurrent.TimeUnit;
* 任务缓存池所有下载任务最先缓存在这个池中 * 任务缓存池所有下载任务最先缓存在这个池中
*/ */
public class CachePool<TASK extends ITask> implements IPool<TASK> { public class CachePool<TASK extends ITask> implements IPool<TASK> {
private static final String TAG = "CachePool"; private static final String TAG = "CachePool";
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数 private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
private static final long TIME_OUT = 1000; private static final long TIME_OUT = 1000;
private Map<String, TASK> mCacheArray; private Map<String, TASK> mCacheArray;
private LinkedBlockingQueue<TASK> mCacheQueue; private LinkedBlockingQueue<TASK> mCacheQueue;
public CachePool() { public CachePool() {
@ -110,7 +110,7 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
Log.e(TAG, "请传入有效的下载链接"); Log.e(TAG, "请传入有效的下载链接");
return false; return false;
} }
String key = CommonUtil.keyToHashKey(downloadUrl); String key = CommonUtil.keyToHashKey(downloadUrl);
TASK task = mCacheArray.get(key); TASK task = mCacheArray.get(key);
mCacheArray.remove(key); mCacheArray.remove(key);
return mCacheQueue.remove(task); return mCacheQueue.remove(task);

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

@ -34,14 +34,14 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
public class DownloadSchedulers implements ISchedulers<DownloadTask> { public class DownloadSchedulers implements ISchedulers<DownloadTask> {
private static final String TAG = "DownloadSchedulers"; private static final String TAG = "DownloadSchedulers";
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static volatile DownloadSchedulers INSTANCE = null; private static volatile DownloadSchedulers INSTANCE = null;
/** /**
* 下载器任务监听 * 下载器任务监听
*/ */
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;
} }
} }
} }

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

@ -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> {
/** /**
* 任务预加载 * 任务预加载
*/ */

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

@ -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 = private static volatile UploadSchedulers INSTANCE = null;
new Object(); private Map<String, ISchedulerListener<UploadTask>> mSchedulerListeners =
private static volatile UploadSchedulers INSTANCE = null;
private Map<String, OnSchedulerListener<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,回调失败");

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

@ -1,10 +1,25 @@
/*
* 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;
/** /**
* Created by Aria.Lao on 2017/2/23. * Created by Aria.Lao on 2017/2/23.
*/ */
public class UploadListener implements IUploadListener{ public class UploadListener implements IUploadListener {
@Override public void onPre() { @Override public void onPre() {
} }

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

@ -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,14 +220,13 @@ 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);
}
} }
} }

@ -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() {
mListener.onFail(); try {
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)

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

@ -27,9 +27,9 @@ import java.util.List;
* 所有数据库实体父类 * 所有数据库实体父类
*/ */
public class DbEntity { public class DbEntity {
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
protected int rowID = -1; protected int rowID = -1;
private DbUtil mUtil = DbUtil.getInstance(); private DbUtil mUtil = DbUtil.getInstance();
protected DbEntity() { protected DbEntity() {
@ -75,7 +75,7 @@ public class DbEntity {
* @return 没有数据返回null * @return 没有数据返回null
*/ */
public static <T extends DbEntity> T findData(Class<T> clazz, String... expression) { public static <T extends DbEntity> T findData(Class<T> clazz, String... expression) {
DbUtil util = DbUtil.getInstance(); DbUtil util = DbUtil.getInstance();
List<T> datas = util.findData(clazz, expression); List<T> datas = util.findData(clazz, expression);
return datas == null ? null : datas.size() > 0 ? datas.get(0) : null; return datas == null ? null : datas.size() > 0 ? datas.get(0) : null;
} }
@ -150,15 +150,15 @@ public class DbEntity {
private <T extends DbEntity> T findData(Class<T> clazz, @NonNull String[] wheres, private <T extends DbEntity> T findData(Class<T> clazz, @NonNull String[] wheres,
@NonNull String[] values) { @NonNull String[] values) {
DbUtil util = DbUtil.getInstance(); DbUtil util = DbUtil.getInstance();
List<T> list = util.findData(clazz, wheres, values); List<T> list = util.findData(clazz, wheres, values);
return list == null ? null : list.get(0); return list == null ? null : list.get(0);
} }
private void updateRowID() { private void updateRowID() {
try { try {
Field[] fields = CommonUtil.getFields(getClass()); Field[] fields = CommonUtil.getFields(getClass());
List<String> where = new ArrayList<>(); List<String> where = new ArrayList<>();
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
for (Field field : fields) { for (Field field : fields) {
field.setAccessible(true); field.setAccessible(true);

@ -34,19 +34,19 @@ import java.util.List;
* 数据库操作工具 * 数据库操作工具
*/ */
public class DbUtil { public class DbUtil {
private static final String TAG = "DbUtil"; private static final String TAG = "DbUtil";
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private volatile static DbUtil INSTANCE = null; private volatile static DbUtil INSTANCE = null;
private int CREATE_TABLE = 0; private int CREATE_TABLE = 0;
private int TABLE_EXISTS = 1; private int TABLE_EXISTS = 1;
private int INSERT_DATA = 2; private int INSERT_DATA = 2;
private int MODIFY_DATA = 3; private int MODIFY_DATA = 3;
private int FIND_DATA = 4; private int FIND_DATA = 4;
private int FIND_ALL_DATA = 5; private int FIND_ALL_DATA = 5;
private int DEL_DATA = 6; private int DEL_DATA = 6;
private int ROW_ID = 7; private int ROW_ID = 7;
private SQLiteDatabase mDb; private SQLiteDatabase mDb;
private SqlHelper mHelper; private SqlHelper mHelper;
private DbUtil() { private DbUtil() {
@ -123,8 +123,8 @@ public class DbUtil {
*/ */
synchronized void modifyData(DbEntity dbEntity) { synchronized void modifyData(DbEntity dbEntity) {
mDb = mHelper.getWritableDatabase(); mDb = mHelper.getWritableDatabase();
Class<?> clazz = dbEntity.getClass(); Class<?> clazz = dbEntity.getClass();
Field[] fields = CommonUtil.getFields(clazz); Field[] fields = CommonUtil.getFields(clazz);
if (fields != null && fields.length > 0) { if (fields != null && fields.length > 0) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET "); sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET ");
@ -398,8 +398,8 @@ public class DbUtil {
synchronized int[] getRowId(Class clazz) { synchronized int[] getRowId(Class clazz) {
mDb = mHelper.getReadableDatabase(); mDb = mHelper.getReadableDatabase();
Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null); Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null);
int[] ids = new int[cursor.getCount()]; int[] ids = new int[cursor.getCount()];
int i = 0; int i = 0;
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
ids[i] = cursor.getInt(cursor.getColumnIndex("rowid")); ids[i] = cursor.getInt(cursor.getColumnIndex("rowid"));
i++; i++;
@ -430,8 +430,8 @@ public class DbUtil {
i++; i++;
} }
print(ROW_ID, sb.toString()); print(ROW_ID, sb.toString());
Cursor c = mDb.rawQuery(sb.toString(), null); Cursor c = mDb.rawQuery(sb.toString(), null);
int id = c.getColumnIndex("rowid"); int id = c.getColumnIndex("rowid");
c.close(); c.close();
close(); close();
return id; return id;
@ -442,7 +442,7 @@ public class DbUtil {
*/ */
private synchronized <T extends DbEntity> List<T> newInstanceEntity(Class<T> clazz, private synchronized <T extends DbEntity> List<T> newInstanceEntity(Class<T> clazz,
Cursor cursor) { Cursor cursor) {
Field[] fields = CommonUtil.getFields(clazz); Field[] fields = CommonUtil.getFields(clazz);
List<T> entitys = new ArrayList<>(); List<T> entitys = new ArrayList<>();
if (fields != null && fields.length > 0) { if (fields != null && fields.length > 0) {
try { try {
@ -453,8 +453,8 @@ public class DbUtil {
if (ignoreField(field)) { if (ignoreField(field)) {
continue; continue;
} }
Class<?> type = field.getType(); Class<?> type = field.getType();
int column = cursor.getColumnIndex(field.getName()); int column = cursor.getColumnIndex(field.getName());
if (type == String.class) { if (type == String.class) {
field.set(entity, cursor.getString(column)); field.set(entity, cursor.getString(column));
} else if (type == int.class || type == Integer.class) { } else if (type == int.class || type == Integer.class) {

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

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

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

@ -41,9 +41,9 @@ import java.util.Arrays;
public final class BufferedRandomAccessFile extends RandomAccessFile { public final class BufferedRandomAccessFile extends RandomAccessFile {
//private static final Logger logger_ = Logger.getLogger(BufferedRandomAccessFile.class); //private static final Logger logger_ = Logger.getLogger(BufferedRandomAccessFile.class);
static final int LogBuffSz_ = 16; // 64K buffer static final int LogBuffSz_ = 16; // 64K buffer
public static final int BuffSz_ = (1 << LogBuffSz_); public static final int BuffSz_ = (1 << LogBuffSz_);
static final long BuffMask_ = ~(((long) BuffSz_) - 1L); static final long BuffMask_ = ~(((long) BuffSz_) - 1L);
/* /*
* This implementation is based on the buffer implementation in Modula-3's * This implementation is based on the buffer implementation in Modula-3's
@ -51,12 +51,12 @@ public final class BufferedRandomAccessFile extends RandomAccessFile {
*/ */
private boolean dirty_; // true iff unflushed bytes exist private boolean dirty_; // true iff unflushed bytes exist
private boolean closed_; // true iff the file is closed private boolean closed_; // true iff the file is closed
private long curr_; // current position in file private long curr_; // current position in file
private long lo_, hi_; // bounds on characters in "buff" private long lo_, hi_; // bounds on characters in "buff"
private byte[] buff_; // local buffer private byte[] buff_; // local buffer
private long maxHi_; // this.lo + this.buff.length private long maxHi_; // this.lo + this.buff.length
private boolean hitEOF_; // buffer contains last file block? private boolean hitEOF_; // buffer contains last file block?
private long diskPos_; // disk position private long diskPos_; // disk position
/* /*
* To describe the above fields, we introduce the following abstractions for * To describe the above fields, we introduce the following abstractions for

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

@ -50,7 +50,7 @@ public class CommonUtil {
public static Intent createIntent(String packageName, String action) { public static Intent createIntent(String packageName, String action) {
Uri.Builder builder = new Uri.Builder(); Uri.Builder builder = new Uri.Builder();
builder.scheme(packageName); builder.scheme(packageName);
Uri uri = builder.build(); Uri uri = builder.build();
Intent intent = new Intent(action); Intent intent = new Intent(action);
intent.setData(uri); intent.setData(uri);
return intent; return intent;
@ -65,7 +65,7 @@ public class CommonUtil {
* @return 成功标志 * @return 成功标志
*/ */
public static Boolean putString(String preName, Context context, String key, String value) { public static Boolean putString(String preName, Context context, String key, String value) {
SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE); SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pre.edit(); SharedPreferences.Editor editor = pre.edit();
editor.putString(key, value); editor.putString(key, value);
return editor.commit(); return editor.commit();
@ -298,9 +298,9 @@ public class CommonUtil {
* 读取下载配置文件 * 读取下载配置文件
*/ */
public static Properties loadConfig(File file) { public static Properties loadConfig(File file) {
Properties properties = new Properties(); Properties properties = new Properties();
FileInputStream fis = null; FileInputStream fis = null;
if (!file.exists()){ if (!file.exists()) {
createFile(file.getPath()); createFile(file.getPath());
} }
try { try {

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

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

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

@ -47,467 +47,451 @@ 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 * current thread.
* current thread. *
* * If this thread does not have a looper, this handler won't be able to receive messages
* If this thread does not have a looper, this handler won't be able to receive messages * so an exception is thrown.
* so an exception is thrown. */
*/ public WeakHandler() {
public WeakHandler() { mCallback = null;
mCallback = null; mExec = new ExecHandler();
mExec = new ExecHandler(); }
/**
* Constructor associates this handler with the {@link Looper} for the
* current thread and takes a callback interface in which you can handle
* messages.
*
* If this thread does not have a looper, this handler won't be able to receive messages
* so an exception is thrown.
*
* @param callback The callback interface in which to handle messages, or null.
*/
public WeakHandler(@Nullable Handler.Callback callback) {
mCallback = callback; // Hard referencing body
mExec = new ExecHandler(new WeakReference<>(callback)); // Weak referencing inside ExecHandler
}
/**
* Use the provided {@link Looper} instead of the default one.
*
* @param looper The looper, must not be null.
*/
public WeakHandler(@NonNull Looper looper) {
mCallback = null;
mExec = new ExecHandler(looper);
}
/**
* Use the provided {@link Looper} instead of the default one and take a callback
* interface in which to handle messages.
*
* @param looper The looper, must not be null.
* @param callback The callback interface in which to handle messages, or null.
*/
public WeakHandler(@NonNull Looper looper, @NonNull Handler.Callback callback) {
mCallback = callback;
mExec = new ExecHandler(looper, new WeakReference<>(callback));
}
/**
* Causes the Runnable r to be added to the message queue.
* The runnable will be run on the thread to which this handler is
* attached.
*
* @param r The Runnable that will be executed.
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean post(@NonNull Runnable r) {
return mExec.post(wrapRunnable(r));
}
/**
* Causes the Runnable r to be added to the message queue, to be run
* at a specific time given by <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* The runnable will be run on the thread to which this handler is attached.
*
* @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base.
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean postAtTime(@NonNull Runnable r, long uptimeMillis) {
return mExec.postAtTime(wrapRunnable(r), uptimeMillis);
}
/**
* Causes the Runnable r to be added to the message queue, to be run
* at a specific time given by <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* The runnable will be run on the thread to which this handler is attached.
*
* @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base.
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
* @see android.os.SystemClock#uptimeMillis
*/
public final boolean postAtTime(Runnable r, Object token, long uptimeMillis) {
return mExec.postAtTime(wrapRunnable(r), token, uptimeMillis);
}
/**
* Causes the Runnable r to be added to the message queue, to be run
* after the specified amount of time elapses.
* The runnable will be run on the thread to which this handler
* is attached.
*
* @param r The Runnable that will be executed.
* @param delayMillis The delay (in milliseconds) until the Runnable
* will be executed.
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed --
* if the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean postDelayed(Runnable r, long delayMillis) {
return mExec.postDelayed(wrapRunnable(r), delayMillis);
}
/**
* Posts a message to an object that implements Runnable.
* Causes the Runnable r to executed on the next iteration through the
* message queue. The runnable will be run on the thread to which this
* handler is attached.
* <b>This method is only for use in very special circumstances -- it
* can easily starve the message queue, cause ordering problems, or have
* other unexpected side-effects.</b>
*
* @param r The Runnable that will be executed.
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean postAtFrontOfQueue(Runnable r) {
return mExec.postAtFrontOfQueue(wrapRunnable(r));
}
/**
* Remove any pending posts of Runnable r that are in the message queue.
*/
public final void removeCallbacks(Runnable r) {
final WeakRunnable runnable = mRunnables.remove(r);
if (runnable != null) {
mExec.removeCallbacks(runnable);
} }
}
/**
* Constructor associates this handler with the {@link Looper} for the /**
* current thread and takes a callback interface in which you can handle * Remove any pending posts of Runnable <var>r</var> with Object
* messages. * <var>token</var> that are in the message queue. If <var>token</var> is null,
* * all callbacks will be removed.
* If this thread does not have a looper, this handler won't be able to receive messages */
* so an exception is thrown. public final void removeCallbacks(Runnable r, Object token) {
* final WeakRunnable runnable = mRunnables.remove(r);
* @param callback The callback interface in which to handle messages, or null. if (runnable != null) {
*/ mExec.removeCallbacks(runnable, token);
public WeakHandler(@Nullable Handler.Callback callback) {
mCallback = callback; // Hard referencing body
mExec = new ExecHandler(new WeakReference<>(callback)); // Weak referencing inside ExecHandler
}
/**
* Use the provided {@link Looper} instead of the default one.
*
* @param looper The looper, must not be null.
*/
public WeakHandler(@NonNull Looper looper) {
mCallback = null;
mExec = new ExecHandler(looper);
} }
}
/**
* Use the provided {@link Looper} instead of the default one and take a callback /**
* interface in which to handle messages. * Pushes a message onto the end of the message queue after all pending messages
* * before the current time. It will be received in callback,
* @param looper The looper, must not be null. * in the thread attached to this handler.
* @param callback The callback interface in which to handle messages, or null. *
*/ * @return Returns true if the message was successfully placed in to the
public WeakHandler(@NonNull Looper looper, @NonNull Handler.Callback callback) { * message queue. Returns false on failure, usually because the
mCallback = callback; * looper processing the message queue is exiting.
mExec = new ExecHandler(looper, new WeakReference<>(callback)); */
} public final boolean sendMessage(Message msg) {
return mExec.sendMessage(msg);
/** }
* Causes the Runnable r to be added to the message queue.
* The runnable will be run on the thread to which this handler is /**
* attached. * Sends a Message containing only the what value.
* *
* @param r The Runnable that will be executed. * @return Returns true if the message was successfully placed in to the
* * message queue. Returns false on failure, usually because the
* @return Returns true if the Runnable was successfully placed in to the * looper processing the message queue is exiting.
* message queue. Returns false on failure, usually because the */
* looper processing the message queue is exiting. public final boolean sendEmptyMessage(int what) {
*/ return mExec.sendEmptyMessage(what);
public final boolean post(@NonNull Runnable r) { }
return mExec.post(wrapRunnable(r));
/**
* Sends a Message containing only the what value, to be delivered
* after the specified amount of time elapses.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
* @see #sendMessageDelayed(android.os.Message, long)
*/
public final boolean sendEmptyMessageDelayed(int what, long delayMillis) {
return mExec.sendEmptyMessageDelayed(what, delayMillis);
}
/**
* Sends a Message containing only the what value, to be delivered
* at a specific time.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
* @see #sendMessageAtTime(android.os.Message, long)
*/
public final boolean sendEmptyMessageAtTime(int what, long uptimeMillis) {
return mExec.sendEmptyMessageAtTime(what, uptimeMillis);
}
/**
* Enqueue a message into the message queue after all pending messages
* before (current time + delayMillis). You will receive it in
* callback, in the thread attached to this handler.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the message will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean sendMessageDelayed(Message msg, long delayMillis) {
return mExec.sendMessageDelayed(msg, delayMillis);
}
/**
* Enqueue a message into the message queue after all pending messages
* before the absolute time (in milliseconds) <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* You will receive it in callback, in the thread attached
* to this handler.
*
* @param uptimeMillis The absolute time at which the message should be
* delivered, using the
* {@link android.os.SystemClock#uptimeMillis} time-base.
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the message will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
return mExec.sendMessageAtTime(msg, uptimeMillis);
}
/**
* Enqueue a message at the front of the message queue, to be processed on
* the next iteration of the message loop. You will receive it in
* callback, in the thread attached to this handler.
* <b>This method is only for use in very special circumstances -- it
* can easily starve the message queue, cause ordering problems, or have
* other unexpected side-effects.</b>
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendMessageAtFrontOfQueue(Message msg) {
return mExec.sendMessageAtFrontOfQueue(msg);
}
/**
* Remove any pending posts of messages with code 'what' that are in the
* message queue.
*/
public final void removeMessages(int what) {
mExec.removeMessages(what);
}
/**
* Remove any pending posts of messages with code 'what' and whose obj is
* 'object' that are in the message queue. If <var>object</var> is null,
* all messages will be removed.
*/
public final void removeMessages(int what, Object object) {
mExec.removeMessages(what, object);
}
/**
* Remove any pending posts of callbacks and sent messages whose
* <var>obj</var> is <var>token</var>. If <var>token</var> is null,
* all callbacks and messages will be removed.
*/
public final void removeCallbacksAndMessages(Object token) {
mExec.removeCallbacksAndMessages(token);
}
/**
* Check if there are any pending posts of messages with code 'what' in
* the message queue.
*/
public final boolean hasMessages(int what) {
return mExec.hasMessages(what);
}
/**
* Check if there are any pending posts of messages with code 'what' and
* whose obj is 'object' in the message queue.
*/
public final boolean hasMessages(int what, Object object) {
return mExec.hasMessages(what, object);
}
public final Looper getLooper() {
return mExec.getLooper();
}
private WeakRunnable wrapRunnable(@NonNull Runnable r) {
//noinspection ConstantConditions
if (r == null) {
throw new NullPointerException("Runnable can't be null");
} }
final ChainedRef hardRef = new ChainedRef(mLock, r);
mRunnables.insertAfter(hardRef);
return hardRef.wrapper;
}
/** private static class ExecHandler extends Handler {
* Causes the Runnable r to be added to the message queue, to be run private final WeakReference<Handler.Callback> mCallback;
* at a specific time given by <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* The runnable will be run on the thread to which this handler is attached.
*
* @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean postAtTime(@NonNull Runnable r, long uptimeMillis) {
return mExec.postAtTime(wrapRunnable(r), uptimeMillis);
}
/** ExecHandler() {
* Causes the Runnable r to be added to the message queue, to be run mCallback = null;
* at a specific time given by <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* The runnable will be run on the thread to which this handler is attached.
*
* @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*
* @see android.os.SystemClock#uptimeMillis
*/
public final boolean postAtTime(Runnable r, Object token, long uptimeMillis) {
return mExec.postAtTime(wrapRunnable(r), token, uptimeMillis);
} }
/** ExecHandler(WeakReference<Handler.Callback> callback) {
* Causes the Runnable r to be added to the message queue, to be run mCallback = callback;
* after the specified amount of time elapses.
* The runnable will be run on the thread to which this handler
* is attached.
*
* @param r The Runnable that will be executed.
* @param delayMillis The delay (in milliseconds) until the Runnable
* will be executed.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed --
* if the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean postDelayed(Runnable r, long delayMillis) {
return mExec.postDelayed(wrapRunnable(r), delayMillis);
} }
/** ExecHandler(Looper looper) {
* Posts a message to an object that implements Runnable. super(looper);
* Causes the Runnable r to executed on the next iteration through the mCallback = null;
* message queue. The runnable will be run on the thread to which this
* handler is attached.
* <b>This method is only for use in very special circumstances -- it
* can easily starve the message queue, cause ordering problems, or have
* other unexpected side-effects.</b>
*
* @param r The Runnable that will be executed.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean postAtFrontOfQueue(Runnable r) {
return mExec.postAtFrontOfQueue(wrapRunnable(r));
} }
/** ExecHandler(Looper looper, WeakReference<Handler.Callback> callback) {
* Remove any pending posts of Runnable r that are in the message queue. super(looper);
*/ mCallback = callback;
public final void removeCallbacks(Runnable r) {
final WeakRunnable runnable = mRunnables.remove(r);
if (runnable != null) {
mExec.removeCallbacks(runnable);
}
} }
/** @Override public void handleMessage(@NonNull Message msg) {
* Remove any pending posts of Runnable <var>r</var> with Object if (mCallback == null) {
* <var>token</var> that are in the message queue. If <var>token</var> is null, return;
* all callbacks will be removed. }
*/ final Handler.Callback callback = mCallback.get();
public final void removeCallbacks(Runnable r, Object token) { if (callback == null) { // Already disposed
final WeakRunnable runnable = mRunnables.remove(r); return;
if (runnable != null) { }
mExec.removeCallbacks(runnable, token); callback.handleMessage(msg);
}
} }
}
/** static class WeakRunnable implements Runnable {
* Pushes a message onto the end of the message queue after all pending messages private final WeakReference<Runnable> mDelegate;
* before the current time. It will be received in callback, private final WeakReference<ChainedRef> mReference;
* in the thread attached to this handler.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendMessage(Message msg) {
return mExec.sendMessage(msg);
}
/** WeakRunnable(WeakReference<Runnable> delegate, WeakReference<ChainedRef> reference) {
* Sends a Message containing only the what value. mDelegate = delegate;
* mReference = reference;
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessage(int what) {
return mExec.sendEmptyMessage(what);
} }
/** @Override public void run() {
* Sends a Message containing only the what value, to be delivered final Runnable delegate = mDelegate.get();
* after the specified amount of time elapses. final ChainedRef reference = mReference.get();
* @see #sendMessageDelayed(android.os.Message, long) if (reference != null) {
* reference.remove();
* @return Returns true if the message was successfully placed in to the }
* message queue. Returns false on failure, usually because the if (delegate != null) {
* looper processing the message queue is exiting. delegate.run();
*/ }
public final boolean sendEmptyMessageDelayed(int what, long delayMillis) {
return mExec.sendEmptyMessageDelayed(what, delayMillis);
} }
}
/** static class ChainedRef {
* Sends a Message containing only the what value, to be delivered @Nullable ChainedRef next;
* at a specific time. @Nullable ChainedRef prev;
* @see #sendMessageAtTime(android.os.Message, long) @NonNull final Runnable runnable;
* @NonNull final WeakRunnable wrapper;
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessageAtTime(int what, long uptimeMillis) {
return mExec.sendEmptyMessageAtTime(what, uptimeMillis);
}
/** @NonNull Lock lock;
* Enqueue a message into the message queue after all pending messages
* before (current time + delayMillis). You will receive it in
* callback, in the thread attached to this handler.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the message will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean sendMessageDelayed(Message msg, long delayMillis) {
return mExec.sendMessageDelayed(msg, delayMillis);
}
/** public ChainedRef(@NonNull Lock lock, @NonNull Runnable r) {
* Enqueue a message into the message queue after all pending messages this.runnable = r;
* before the absolute time (in milliseconds) <var>uptimeMillis</var>. this.lock = lock;
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b> this.wrapper = new WeakRunnable(new WeakReference<>(r), new WeakReference<>(this));
* You will receive it in callback, in the thread attached
* to this handler.
*
* @param uptimeMillis The absolute time at which the message should be
* delivered, using the
* {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the message will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
return mExec.sendMessageAtTime(msg, uptimeMillis);
} }
/** public WeakRunnable remove() {
* Enqueue a message at the front of the message queue, to be processed on lock.lock();
* the next iteration of the message loop. You will receive it in try {
* callback, in the thread attached to this handler. if (prev != null) {
* <b>This method is only for use in very special circumstances -- it prev.next = next;
* can easily starve the message queue, cause ordering problems, or have
* other unexpected side-effects.</b>
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendMessageAtFrontOfQueue(Message msg) {
return mExec.sendMessageAtFrontOfQueue(msg);
}
/**
* Remove any pending posts of messages with code 'what' that are in the
* message queue.
*/
public final void removeMessages(int what) {
mExec.removeMessages(what);
}
/**
* Remove any pending posts of messages with code 'what' and whose obj is
* 'object' that are in the message queue. If <var>object</var> is null,
* all messages will be removed.
*/
public final void removeMessages(int what, Object object) {
mExec.removeMessages(what, object);
}
/**
* Remove any pending posts of callbacks and sent messages whose
* <var>obj</var> is <var>token</var>. If <var>token</var> is null,
* all callbacks and messages will be removed.
*/
public final void removeCallbacksAndMessages(Object token) {
mExec.removeCallbacksAndMessages(token);
}
/**
* Check if there are any pending posts of messages with code 'what' in
* the message queue.
*/
public final boolean hasMessages(int what) {
return mExec.hasMessages(what);
}
/**
* Check if there are any pending posts of messages with code 'what' and
* whose obj is 'object' in the message queue.
*/
public final boolean hasMessages(int what, Object object) {
return mExec.hasMessages(what, object);
}
public final Looper getLooper() {
return mExec.getLooper();
}
private WeakRunnable wrapRunnable(@NonNull Runnable r) {
//noinspection ConstantConditions
if (r == null) {
throw new NullPointerException("Runnable can't be null");
}
final ChainedRef hardRef = new ChainedRef(mLock, r);
mRunnables.insertAfter(hardRef);
return hardRef.wrapper;
}
private static class ExecHandler extends Handler {
private final WeakReference<Handler.Callback> mCallback;
ExecHandler() {
mCallback = null;
}
ExecHandler(WeakReference<Handler.Callback> callback) {
mCallback = callback;
}
ExecHandler(Looper looper) {
super(looper);
mCallback = null;
} }
if (next != null) {
ExecHandler(Looper looper, WeakReference<Handler.Callback> callback) { next.prev = prev;
super(looper);
mCallback = callback;
}
@Override
public void handleMessage(@NonNull Message msg) {
if (mCallback == null) {
return;
}
final Handler.Callback callback = mCallback.get();
if (callback == null) { // Already disposed
return;
}
callback.handleMessage(msg);
} }
prev = null;
next = null;
} finally {
lock.unlock();
}
return wrapper;
} }
static class WeakRunnable implements Runnable { public void insertAfter(@NonNull ChainedRef candidate) {
private final WeakReference<Runnable> mDelegate; lock.lock();
private final WeakReference<ChainedRef> mReference; try {
if (this.next != null) {
WeakRunnable(WeakReference<Runnable> delegate, WeakReference<ChainedRef> reference) { this.next.prev = candidate;
mDelegate = delegate;
mReference = reference;
} }
@Override candidate.next = this.next;
public void run() { this.next = candidate;
final Runnable delegate = mDelegate.get(); candidate.prev = this;
final ChainedRef reference = mReference.get(); } finally {
if (reference != null) { lock.unlock();
reference.remove(); }
}
if (delegate != null) {
delegate.run();
}
}
} }
static class ChainedRef { @Nullable public WeakRunnable remove(Runnable obj) {
@Nullable lock.lock();
ChainedRef next; try {
@Nullable ChainedRef curr = this.next; // Skipping head
ChainedRef prev; while (curr != null) {
@NonNull if (curr.runnable == obj) { // We do comparison exactly how Handler does inside
final Runnable runnable; return curr.remove();
@NonNull }
final WeakRunnable wrapper; curr = curr.next;
@NonNull
Lock lock;
public ChainedRef(@NonNull Lock lock, @NonNull Runnable r) {
this.runnable = r;
this.lock = lock;
this.wrapper = new WeakRunnable(new WeakReference<>(r), new WeakReference<>(this));
}
public WeakRunnable remove() {
lock.lock();
try {
if (prev != null) {
prev.next = next;
}
if (next != null) {
next.prev = prev;
}
prev = null;
next = null;
} finally {
lock.unlock();
}
return wrapper;
}
public void insertAfter(@NonNull ChainedRef candidate) {
lock.lock();
try {
if (this.next != null) {
this.next.prev = candidate;
}
candidate.next = this.next;
this.next = candidate;
candidate.prev = this;
} finally {
lock.unlock();
}
}
@Nullable
public WeakRunnable remove(Runnable obj) {
lock.lock();
try {
ChainedRef curr = this.next; // Skipping head
while (curr != null) {
if (curr.runnable == obj) { // We do comparison exactly how Handler does inside
return curr.remove();
}
curr = curr.next;
}
} finally {
lock.unlock();
}
return null;
} }
} finally {
lock.unlock();
}
return null;
} }
}
} }

@ -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() {
} }
} }

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

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

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

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

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

@ -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;
@ -24,9 +23,9 @@ import com.arialyy.frame.core.AbsDialogFragment;
/** /**
* Created by AriaLyy@outlook.com on 2016/11/14. * Created by AriaLyy@outlook.com on 2016/11/14.
*/ */
public abstract class BaseDialog<VB extends ViewDataBinding> extends AbsDialogFragment<VB>{ public abstract class BaseDialog<VB extends ViewDataBinding> extends AbsDialogFragment<VB> {
protected BaseDialog(Object obj){ protected BaseDialog(Object obj) {
super(obj); super(obj);
} }

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

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

@ -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;
@ -21,11 +37,11 @@ import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
*/ */
public class DownloadDialog extends AbsDialog { public class DownloadDialog extends AbsDialog {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb; @Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
@Bind(R.id.start) Button mStart; @Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop; @Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel; @Bind(R.id.cancel) Button mCancel;
@Bind(R.id.size) TextView mSize; @Bind(R.id.size) TextView mSize;
@Bind(R.id.speed) TextView mSpeed; @Bind(R.id.speed) TextView mSpeed;
private static final String DOWNLOAD_URL = private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk"; "http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
@ -42,7 +58,7 @@ public class DownloadDialog extends AbsDialog {
private void init() { private void init() {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) { if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
@ -107,7 +123,7 @@ public class DownloadDialog extends AbsDialog {
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task); super.onTaskRunning(task);
long current = task.getCurrentProgress(); long current = task.getCurrentProgress();
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
mPb.setProgress(0); mPb.setProgress(0);
} else { } else {

@ -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() {
@ -55,7 +58,7 @@ public class DownloadModule extends BaseModule {
return mTestDownloadUrl.get(i); return mTestDownloadUrl.get(i);
} }
public DownloadEntity createRandomDownloadEntity(){ public DownloadEntity createRandomDownloadEntity() {
return createDownloadEntity(getRadomUrl()); return createDownloadEntity(getRadomUrl());
} }

@ -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;
@ -23,11 +39,11 @@ import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
*/ */
public class DownloadPopupWindow extends AbsPopupWindow { public class DownloadPopupWindow extends AbsPopupWindow {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb; @Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
@Bind(R.id.start) Button mStart; @Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop; @Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel; @Bind(R.id.cancel) Button mCancel;
@Bind(R.id.size) TextView mSize; @Bind(R.id.size) TextView mSize;
@Bind(R.id.speed) TextView mSpeed; @Bind(R.id.speed) TextView mSpeed;
private static final String DOWNLOAD_URL = private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk"; "http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
@ -44,7 +60,7 @@ public class DownloadPopupWindow extends AbsPopupWindow {
private void initWidget() { private void initWidget() {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) { if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
@ -109,7 +125,7 @@ public class DownloadPopupWindow extends AbsPopupWindow {
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task); super.onTaskRunning(task);
long current = task.getCurrentProgress(); long current = task.getCurrentProgress();
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
mPb.setProgress(0); mPb.setProgress(0);
} else { } else {

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

@ -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();

@ -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;
@ -34,7 +50,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) { if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
@ -112,7 +128,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task); super.onTaskRunning(task);
long current = task.getCurrentProgress(); long current = task.getCurrentProgress();
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
mPb.setProgress(0); mPb.setProgress(0);
} else { } else {

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

@ -39,8 +39,8 @@ import java.util.concurrent.ConcurrentHashMap;
* 下载列表适配器 * 下载列表适配器
*/ */
final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> { final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
private static final String TAG = "DownloadAdapter"; private static final String TAG = "DownloadAdapter";
private Map<String, Integer> mPositions = new ConcurrentHashMap<>(); private Map<String, Integer> mPositions = new ConcurrentHashMap<>();
DownloadAdapter(Context context, List<DownloadEntity> data) { DownloadAdapter(Context context, List<DownloadEntity> data) {
super(context, data); super(context, data);
@ -192,14 +192,14 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
} }
class MyHolder extends AbsHolder { class MyHolder extends AbsHolder {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress; @Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
@Bind(R.id.bt) Button bt; @Bind(R.id.bt) Button bt;
@Bind(R.id.speed) TextView speed; @Bind(R.id.speed) TextView speed;
@Bind(R.id.fileSize) TextView fileSize; @Bind(R.id.fileSize) TextView fileSize;
@Bind(R.id.del) TextView cancel; @Bind(R.id.del) TextView cancel;
@Bind(R.id.name) TextView name; @Bind(R.id.name) TextView name;
@Bind(R.id.download_url) TextView url; @Bind(R.id.download_url) TextView url;
@Bind(R.id.download_path) TextView path; @Bind(R.id.download_path) TextView path;
MyHolder(View itemView) { MyHolder(View itemView) {
super(itemView); super(itemView);

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

@ -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;
@ -86,10 +102,10 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
} }
class FileListHolder extends AbsHolder { class FileListHolder extends AbsHolder {
@Bind(R.id.name) TextView name; @Bind(R.id.name) TextView name;
@Bind(R.id.download_url) TextView url; @Bind(R.id.download_url) TextView url;
@Bind(R.id.download_path) TextView path; @Bind(R.id.download_path) TextView path;
@Bind(R.id.bt) Button bt; @Bind(R.id.bt) Button bt;
FileListHolder(View itemView) { FileListHolder(View itemView) {
super(itemView); super(itemView);

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

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

@ -36,9 +36,9 @@ import java.util.List;
* Created by Lyy on 2016/9/27. * Created by Lyy on 2016/9/27.
*/ */
public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> { public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Bind(R.id.list) RecyclerView mList; @Bind(R.id.list) RecyclerView mList;
@Bind(R.id.toolbar) Toolbar mBar; @Bind(R.id.toolbar) Toolbar mBar;
private FileListAdapter mAdapter; private FileListAdapter mAdapter;
List<FileListEntity> mData = new ArrayList<>(); List<FileListEntity> mData = new ArrayList<>();
@Override protected int setLayoutId() { @Override protected int setLayoutId() {

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

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

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

@ -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;
@ -27,53 +26,50 @@ import android.widget.ProgressBar;
import com.arialyy.simple.R; import com.arialyy.simple.R;
public class HorizontalProgressBarWithNumber extends ProgressBar { public class HorizontalProgressBarWithNumber extends ProgressBar {
private static final int DEFAULT_TEXT_SIZE = 10; private static final int DEFAULT_TEXT_SIZE = 10;
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1; private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da; private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2; private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2; private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10; private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
/** /**
* painter of all drawing things * painter of all drawing things
*/ */
protected Paint mPaint = new Paint(); protected Paint mPaint = new Paint();
/** /**
* color of progress number * color of progress number
*/ */
protected int mTextColor = DEFAULT_TEXT_COLOR; protected int mTextColor = DEFAULT_TEXT_COLOR;
/** /**
* size of text (sp) * size of text (sp)
*/ */
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE); protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
/** /**
* 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
*/ */
protected int mReachedBarColor = DEFAULT_TEXT_COLOR; protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
/** /**
* color of unreached bar * color of unreached bar
*/ */
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR; protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
/** /**
* 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
*/ */
protected int mRealWidth; protected int mRealWidth;
protected boolean mIfDrawText = true; protected boolean mIfDrawText = true;
protected static final int VISIBLE = 0; protected static final int VISIBLE = 0;
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) { public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) {
this(context, attrs, 0); this(context, attrs, 0);
@ -87,14 +83,14 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
} }
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec);
int height = measureHeight(heightMeasureSpec); int height = measureHeight(heightMeasureSpec);
setMeasuredDimension(width, height); setMeasuredDimension(width, height);
mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft(); mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
} }
private int measureHeight(int measureSpec) { private int measureHeight(int measureSpec) {
int result = 0; int result = 0;
int specMode = MeasureSpec.getMode(measureSpec); int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec); int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) { if (specMode == MeasureSpec.EXACTLY) {
@ -148,12 +144,12 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
@Override protected synchronized void onDraw(Canvas canvas) { @Override protected synchronized void onDraw(Canvas canvas) {
canvas.save(); canvas.save();
canvas.translate(getPaddingLeft(), getHeight() / 2); canvas.translate(getPaddingLeft(), getHeight() / 2);
boolean noNeedBg = false; boolean noNeedBg = false;
float radio = getProgress() * 1.0f / getMax(); float radio = getProgress() * 1.0f / getMax();
float progressPosX = (int) (mRealWidth * radio); float progressPosX = (int) (mRealWidth * radio);
String text = getProgress() + "%"; String text = getProgress() + "%";
// mPaint.getTextBounds(text, 0, text.length(), mTextBound); // mPaint.getTextBounds(text, 0, text.length(), mTextBound);
float textWidth = mPaint.measureText(text); float textWidth = mPaint.measureText(text);
float textHeight = (mPaint.descent() + mPaint.ascent()) / 2; float textHeight = (mPaint.descent() + mPaint.ascent()) / 2;
if (progressPosX + textWidth > mRealWidth) { if (progressPosX + textWidth > mRealWidth) {
progressPosX = mRealWidth - textWidth; progressPosX = mRealWidth - textWidth;

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

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

Loading…
Cancel
Save