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. 36
      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. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  9. 16
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  10. 5
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java
  11. 1
      Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java
  12. 2
      Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java
  13. 1
      Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
  14. 1
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  15. 7
      Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java
  16. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  17. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java
  18. 19
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  19. 29
      Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulerListener.java
  20. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulerListener.java
  21. 13
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java
  22. 18
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  23. 15
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  24. 17
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadListener.java
  25. 8
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  26. 19
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  27. 10
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
  28. 15
      Aria/src/main/java/com/arialyy/aria/exception/FileException.java
  29. 1
      Aria/src/main/java/com/arialyy/aria/orm/Id.java
  30. 1
      Aria/src/main/java/com/arialyy/aria/orm/Ignore.java
  31. 1
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  32. 2
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  33. 2
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  34. 18
      Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
  35. 1
      Aria/src/main/java/com/arialyy/aria/util/PathUtil.java
  36. 27
      Aria/src/main/java/com/arialyy/aria/util/Speed.java
  37. 48
      Aria/src/main/java/com/arialyy/aria/util/WeakHandler.java
  38. 18
      Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java
  39. 15
      Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java
  40. 15
      Aria/src/main/java/com/arialyy/aria/window/FileEntity.java
  41. 2
      app/src/main/AndroidManifest.xml
  42. 16
      app/src/main/java/com/arialyy/simple/MainActivity.java
  43. 1
      app/src/main/java/com/arialyy/simple/base/BaseApplication.java
  44. 5
      app/src/main/java/com/arialyy/simple/base/BaseDialog.java
  45. 1
      app/src/main/java/com/arialyy/simple/base/BaseModule.java
  46. 4
      app/src/main/java/com/arialyy/simple/download/DownloadActivity.java
  47. 16
      app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
  48. 11
      app/src/main/java/com/arialyy/simple/download/DownloadModule.java
  49. 16
      app/src/main/java/com/arialyy/simple/download/DownloadPopupWindow.java
  50. 16
      app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
  51. 8
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  52. 16
      app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
  53. 16
      app/src/main/java/com/arialyy/simple/download/fragment_download/FragmentActivity.java
  54. 1
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadNumDialog.java
  55. 16
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java
  56. 16
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListEntity.java
  57. 16
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  58. 55
      app/src/main/java/com/arialyy/simple/download/service_download/DownloadNotification.java
  59. 102
      app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java
  60. 16
      app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
  61. 10
      app/src/main/java/com/arialyy/simple/widget/HorizontalProgressBarWithNumber.java
  62. 9
      app/src/main/res/layout/activity_download_mean.xml
  63. 1
      app/src/main/res/layout/content_single.xml

@ -2,8 +2,8 @@
<project version="4">
<component name="ProjectModuleManager">
<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.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$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.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.widget.PopupWindow;
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.upload.UploadReceiver;
import com.arialyy.aria.core.upload.UploadTask;
@ -56,6 +58,10 @@ import com.arialyy.aria.core.upload.UploadTask;
* </pre>
*/
@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) {
@ -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) {
@ -234,5 +241,9 @@ import com.arialyy.aria.core.upload.UploadTask;
@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() {
ITask task = mQueue.getTask(mEntity.getEntity());
if (task == null){
if (task == null) {
mQueue.createTask(mTargetName, mEntity);
}else {
} else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
}
}

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

@ -14,7 +14,6 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download;
import android.os.Parcel;
@ -30,7 +29,7 @@ import com.arialyy.aria.orm.DbEntity;
* 注意CREATOR要进行@Ignore注解
* 并且需要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>() {
@Override public DownloadEntity createFromParcel(Parcel source) {
return new DownloadEntity(source);
@ -129,8 +128,7 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity{
this.fileSize = fileSize;
}
@Override
public int getState() {
@Override public int getState() {
return state;
}
@ -167,16 +165,26 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity{
}
@Override public String toString() {
return "DownloadEntity{" +
"downloadUrl='" + downloadUrl + '\'' +
", downloadPath='" + downloadPath + '\'' +
", completeTime=" + completeTime +
", fileSize=" + fileSize +
", state=" + state +
", isDownloadComplete=" + isDownloadComplete +
", currentProgress=" + currentProgress +
", failNum=" + failNum +
'}';
return "DownloadEntity{"
+ "downloadUrl='"
+ downloadUrl
+ '\''
+ ", downloadPath='"
+ downloadPath
+ '\''
+ ", completeTime="
+ completeTime
+ ", fileSize="
+ fileSize
+ ", state="
+ state
+ ", isDownloadComplete="
+ isDownloadComplete
+ ", currentProgress="
+ currentProgress
+ ", failNum="
+ failNum
+ '}';
}
@Override public int describeContents() {

@ -14,7 +14,6 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download;
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.AbsCmd;
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.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
@ -36,7 +36,7 @@ import java.util.Set;
public class DownloadReceiver implements IReceiver<DownloadEntity> {
private static final String TAG = "DownloadReceiver";
public String targetName;
public OnSchedulerListener<DownloadTask> listener;
public ISchedulerListener<DownloadTask> listener;
/**
* {@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;
DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener);
return this;
@ -110,8 +110,8 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
List<AbsCmd> stopCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
if (entity.getState() == DownloadEntity.STATE_RUNNING) {
stopCmds.add(CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity),
CmdFactory.TASK_STOP));
stopCmds.add(
CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity), CmdFactory.TASK_STOP));
}
}
ariaManager.setCmds(stopCmds).exe();
@ -125,8 +125,8 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
List<DownloadEntity> allEntity = DbEntity.findAllData(DownloadEntity.class);
List<AbsCmd> cancelCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
cancelCmds.add(CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity),
CmdFactory.TASK_CANCEL));
cancelCmds.add(
CommonUtil.createCmd(targetName, new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL));
}
ariaManager.setCmds(cancelCmds).exe();
Set<String> keys = ariaManager.getReceiver().keySet();

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

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

@ -303,7 +303,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
/**
* 处理不支持断点的下载
*/
private void handleNoSupportBreakpointDownload(HttpURLConnection conn){
private void handleNoSupportBreakpointDownload(HttpURLConnection conn) {
ConfigEntity entity = new ConfigEntity();
long len = conn.getContentLength();
entity.FILE_SIZE = len;
@ -315,7 +315,10 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
entity.isSupportBreakpoint = isSupportBreakpoint;
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
THREAD_NUM = 1;
mConstance.THREAD_NUM = THREAD_NUM;
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
mTask.put(0, task);
mFixedThreadPool.execute(task);
mListener.onPostPre(len);
mListener.onStart(0);

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

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

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

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

@ -57,13 +57,14 @@ public class TaskFactory {
* @param <SCHEDULER> {@link DownloadSchedulers}
* @return {@link DownloadTask}{@link UploadTask}
*/
<ENTITY extends ITaskEntity, SCHEDULER extends ISchedulers> ITask createTask(
String targetName, ENTITY entity, SCHEDULER schedulers) {
<ENTITY extends ITaskEntity, SCHEDULER extends ISchedulers> ITask createTask(String targetName,
ENTITY entity, SCHEDULER schedulers) {
if (entity instanceof DownloadTaskEntity) {
return createDownloadTask(targetName, (DownloadTaskEntity) entity, schedulers);
} else if (entity instanceof UploadTaskEntity) {
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) {
Log.e(TAG, "startTask");
if (mExecutePool.putTask(task)) {
mCachePool.removeTask(task);
//task.getEntity().setFailNum(0);

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

@ -41,7 +41,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
/**
* 下载器任务监听
*/
private Map<String, OnSchedulerListener<DownloadTask>> mSchedulerListeners =
private Map<String, IDownloadSchedulerListener<DownloadTask>> mSchedulerListeners =
new ConcurrentHashMap<>();
private DownloadTaskQueue mQueue;
@ -59,16 +59,17 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
}
@Override public void addSchedulerListener(String targetName,
OnSchedulerListener<DownloadTask> schedulerListener) {
mSchedulerListeners.put(targetName, schedulerListener);
ISchedulerListener<DownloadTask> schedulerListener) {
mSchedulerListeners.put(targetName,
(IDownloadSchedulerListener<DownloadTask>) schedulerListener);
}
@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
for (Iterator<Map.Entry<String, OnSchedulerListener<DownloadTask>>> iter =
for (Iterator<Map.Entry<String, IDownloadSchedulerListener<DownloadTask>>> iter =
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();
}
}
@ -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 (task == null) {
Log.e(TAG, "TASK 为null,回调失败");
@ -149,6 +151,9 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
case FAIL:
listener.onTaskFail(task);
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处理任务监听
*/
public interface OnSchedulerListener<TASK extends ITask> {
public interface ISchedulerListener<TASK extends ITask> {
/**
* 任务预加载
*/

@ -17,7 +17,6 @@
package com.arialyy.aria.core.scheduler;
import android.os.Handler;
import com.arialyy.aria.core.download.DownloadEntity;
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 static final int SUPPORT_BREAK_POINT = 8;
/**
* 任务预加载
*/
@ -62,14 +65,14 @@ public interface ISchedulers<Task extends ITask> extends Handler.Callback {
* 注册下载器监听一个观察者只能注册一次监听
*
* @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 观察者创建该监听器的对象类名
* 取消注册监听器
*/
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> {
private static final String TAG =
"UploadSchedulers";
private static final Object LOCK =
new Object();
private static final String TAG = "UploadSchedulers";
private static final Object LOCK = new Object();
private static volatile UploadSchedulers INSTANCE = null;
private Map<String, OnSchedulerListener<UploadTask>> mSchedulerListeners =
private Map<String, ISchedulerListener<UploadTask>> mSchedulerListeners =
new ConcurrentHashMap<>();
private UploadTaskQueue mQueue;
@ -57,15 +55,15 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
}
@Override public void addSchedulerListener(String targetName,
OnSchedulerListener<UploadTask> schedulerListener) {
ISchedulerListener<UploadTask> schedulerListener) {
mSchedulerListeners.put(targetName, schedulerListener);
}
@Override public void removeSchedulerListener(String targetName,
OnSchedulerListener<UploadTask> schedulerListener) {
for (Iterator<Map.Entry<String, OnSchedulerListener<UploadTask>>> iter =
ISchedulerListener<UploadTask> schedulerListener) {
for (Iterator<Map.Entry<String, ISchedulerListener<UploadTask>>> iter =
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();
}
}
@ -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 (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;
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;
/**
* Created by Aria.Lao on 2017/2/23.
*/
public class UploadListener implements IUploadListener{
public class UploadListener implements IUploadListener {
@Override public void onPre() {
}

@ -16,13 +16,12 @@
package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.inf.IEntity;
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.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil;
@ -30,7 +29,6 @@ import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
@ -40,7 +38,7 @@ import java.util.regex.Pattern;
public class UploadReceiver implements IReceiver<UploadEntity> {
private static final String TAG = "DownloadReceiver";
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;
UploadSchedulers.getInstance().addSchedulerListener(targetName, listener);
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;
import android.content.Intent;
@ -57,7 +72,6 @@ public class UploadTask implements ITask {
}
@Override public void start() {
Log.d(TAG, "task_start");
if (mUtil.isRunning()) {
Log.d(TAG, "任务正在下载");
} else {
@ -206,16 +220,15 @@ public class UploadTask implements ITask {
entity.setComplete(action.equals(Aria.ACTION_COMPLETE));
entity.setCurrentProgress(location);
entity.update();
if (!Configuration.isOpenBreadCast) return;
Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action);
intent.putExtra(Aria.ENTITY, entity);
if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location);
}
if (Configuration.isOpenBreadCast) {
AriaManager.APP.sendBroadcast(intent);
}
}
}
public static class Builder {
private Handler mOutHandler;

@ -59,7 +59,6 @@ final class UploadUtil implements Runnable {
}
public void start() {
Log.d(TAG, "start");
isCancel = false;
isRunning = false;
new Thread(this).start();
@ -71,7 +70,6 @@ final class UploadUtil implements Runnable {
}
@Override public void run() {
Log.e(TAG, "run");
File uploadFile = new File(mUploadEntity.getFilePath());
if (!uploadFile.exists()) {
Log.e(TAG, "【" + mUploadEntity.getFilePath() + "】,文件不存在。");
@ -123,7 +121,14 @@ final class UploadUtil implements Runnable {
}
private void fail() {
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)
throws IOException {
Log.e(TAG, "uploadFile");
writer.append(PREFIX).append(BOUNDARY).append(LINE_END);
writer.append("Content-Disposition: form-data; name=\"")
.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;
/**

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

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

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

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

@ -300,7 +300,7 @@ public class CommonUtil {
public static Properties loadConfig(File file) {
Properties properties = new Properties();
FileInputStream fis = null;
if (!file.exists()){
if (!file.exists()) {
createFile(file.getPath());
}
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;
import android.content.Context;
@ -60,7 +75,8 @@ public class FileUtil {
|| exName.equalsIgnoreCase("rm")
|| exName.equalsIgnoreCase("rmvb")) {
//fType = new FileType("视频", );
} return fType;
}
return fType;
}
/**

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

@ -47,14 +47,13 @@ import java.util.concurrent.locks.ReentrantLock;
*
* Created by Dmytro Voronkevych on 17/06/2014.
*/
@SuppressWarnings("unused")
public class WeakHandler {
private final Handler.Callback mCallback; // hard reference to Callback. We need to keep callback in memory
@SuppressWarnings("unused") public class WeakHandler {
private final Handler.Callback mCallback;
// hard reference to Callback. We need to keep callback in memory
private final ExecHandler mExec;
private Lock mLock = new ReentrantLock();
@SuppressWarnings("ConstantConditions")
@VisibleForTesting
final ChainedRef mRunnables = new ChainedRef(mLock, null);
@SuppressWarnings("ConstantConditions") @VisibleForTesting final ChainedRef mRunnables =
new ChainedRef(mLock, null);
/**
* Default constructor associates this handler with the {@link Looper} for the
@ -111,7 +110,6 @@ public class WeakHandler {
* 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.
@ -129,7 +127,6 @@ public class WeakHandler {
* @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
@ -150,14 +147,12 @@ public class WeakHandler {
* @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) {
@ -173,7 +168,6 @@ public class WeakHandler {
* @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
@ -195,7 +189,6 @@ public class WeakHandler {
* 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.
@ -253,11 +246,11 @@ public class WeakHandler {
/**
* Sends a Message containing only the what value, to be delivered
* after the specified amount of time elapses.
* @see #sendMessageDelayed(android.os.Message, long)
*
* @return Returns true if the message was successfully placed in to the
* 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);
@ -266,11 +259,11 @@ public class WeakHandler {
/**
* Sends a Message containing only the what value, to be delivered
* at a specific time.
* @see #sendMessageAtTime(android.os.Message, long)
*
* @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);
@ -302,7 +295,6 @@ public class WeakHandler {
* @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
@ -407,8 +399,7 @@ public class WeakHandler {
mCallback = callback;
}
@Override
public void handleMessage(@NonNull Message msg) {
@Override public void handleMessage(@NonNull Message msg) {
if (mCallback == null) {
return;
}
@ -429,8 +420,7 @@ public class WeakHandler {
mReference = reference;
}
@Override
public void run() {
@Override public void run() {
final Runnable delegate = mDelegate.get();
final ChainedRef reference = mReference.get();
if (reference != null) {
@ -443,17 +433,12 @@ public class WeakHandler {
}
static class ChainedRef {
@Nullable
ChainedRef next;
@Nullable
ChainedRef prev;
@NonNull
final Runnable runnable;
@NonNull
final WeakRunnable wrapper;
@NonNull
Lock lock;
@Nullable ChainedRef next;
@Nullable ChainedRef prev;
@NonNull final Runnable runnable;
@NonNull final WeakRunnable wrapper;
@NonNull Lock lock;
public ChainedRef(@NonNull Lock lock, @NonNull Runnable r) {
this.runnable = r;
@ -493,8 +478,7 @@ public class WeakHandler {
}
}
@Nullable
public WeakRunnable remove(Runnable obj) {
@Nullable public WeakRunnable remove(Runnable obj) {
lock.lock();
try {
ChainedRef curr = this.next; // Skipping head

@ -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;
import android.os.Bundle;
@ -49,7 +64,4 @@ public class AriaFileChangeActivity extends FragmentActivity {
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;
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;
import android.graphics.drawable.Drawable;

@ -29,6 +29,8 @@
<activity android:name=".download.multi_download.MultiTaskActivity"/>
<activity android:name=".download.fragment_download.FragmentActivity"/>
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
<service android:name=".download.service_download.DownloadService"/>
</application>
</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;
import android.content.Intent;

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

@ -14,7 +14,6 @@
* limitations under the License.
*/
package com.arialyy.simple.base;
import android.databinding.ViewDataBinding;
@ -24,9 +23,9 @@ import com.arialyy.frame.core.AbsDialogFragment;
/**
* 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);
}

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

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

@ -44,9 +44,12 @@ public class DownloadModule extends BaseModule {
public DownloadModule(Context context) {
super(context);
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
mTestDownloadUrl.add(
"http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.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() {
@ -55,7 +58,7 @@ public class DownloadModule extends BaseModule {
return mTestDownloadUrl.get(i);
}
public DownloadEntity createRandomDownloadEntity(){
public DownloadEntity createRandomDownloadEntity() {
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;
import android.content.Context;

@ -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;
import android.app.NotificationManager;

@ -26,7 +26,6 @@ import android.os.Message;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
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.Speed;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivitySingleBinding;
@ -239,6 +239,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
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) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
.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;
import android.os.Bundle;

@ -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;
import com.arialyy.simple.R;

@ -14,7 +14,6 @@
* limitations under the License.
*/
package com.arialyy.simple.download.multi_download;
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;
import android.content.Context;

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

@ -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;
import android.os.Bundle;

@ -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;
import android.os.Bundle;

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

@ -65,5 +65,14 @@
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>
</layout>

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

Loading…
Cancel
Save