parent
a842f74c6f
commit
374fdd12b9
@ -0,0 +1,59 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(DownloadUtil) |
||||
* |
||||
* 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.downloadutil.core; |
||||
|
||||
import android.content.Context; |
||||
import com.arialyy.downloadutil.core.command.CmdFactory; |
||||
import com.arialyy.downloadutil.core.command.IDownloadCmd; |
||||
import com.arialyy.downloadutil.core.scheduler.OnSchedulerListener; |
||||
import com.arialyy.downloadutil.core.task.Task; |
||||
import com.arialyy.downloadutil.util.CommonUtil; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* AM 接收器 |
||||
*/ |
||||
public class AMReceiver { |
||||
Context context; |
||||
OnSchedulerListener listener; |
||||
DownloadEntity entity; |
||||
DownloadManager manager = DownloadManager.getInstance(); |
||||
|
||||
public AMTarget load(DownloadEntity entity) { |
||||
this.entity = entity; |
||||
return new AMTarget(this); |
||||
} |
||||
|
||||
/** |
||||
* 添加调度器回调 |
||||
*/ |
||||
public AMReceiver addSchedulerListener(OnSchedulerListener listener) { |
||||
this.listener = listener; |
||||
manager.getTaskQueue().getDownloadSchedulers().addSchedulerListener(context, listener); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 移除回调 |
||||
*/ |
||||
public AMReceiver removeSchedulerListener() { |
||||
if (listener != null) { |
||||
manager.getTaskQueue().getDownloadSchedulers().removeSchedulerListener(listener); |
||||
} |
||||
return this; |
||||
} |
||||
} |
@ -1,16 +1,87 @@ |
||||
package com.arialyy.downloadutil.core; |
||||
|
||||
import android.content.Context; |
||||
import com.arialyy.downloadutil.core.command.CmdFactory; |
||||
import com.arialyy.downloadutil.core.command.IDownloadCmd; |
||||
import com.arialyy.downloadutil.core.scheduler.OnSchedulerListener; |
||||
import com.arialyy.downloadutil.core.task.Task; |
||||
import com.arialyy.downloadutil.util.CommonUtil; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by utstarcom on 2016/12/5. |
||||
*/ |
||||
public class AMTarget { |
||||
Context context; |
||||
OnSchedulerListener listener; |
||||
DownloadEntity entity; |
||||
private AMReceiver receiver; |
||||
|
||||
public AMTarget(AMReceiver receiver){ |
||||
this.receiver = receiver; |
||||
} |
||||
|
||||
//public DownloadManager load(DownloadEntity entity){
|
||||
// this.entity = entity;
|
||||
//}
|
||||
/** |
||||
* 开始下载 |
||||
*/ |
||||
public void start() { |
||||
List<IDownloadCmd> cmds = new ArrayList<>(); |
||||
cmds.add(CommonUtil.createCmd(receiver.entity, CmdFactory.TASK_CREATE)); |
||||
cmds.add(CommonUtil.createCmd(receiver.entity, CmdFactory.TASK_START)); |
||||
receiver.manager.setCmds(cmds).exe(); |
||||
} |
||||
|
||||
} |
||||
/** |
||||
* 停止下载 |
||||
*/ |
||||
public void stop() { |
||||
receiver.manager.setCmd(CommonUtil.createCmd(receiver.entity, CmdFactory.TASK_STOP)).exe(); |
||||
} |
||||
|
||||
/** |
||||
* 恢复下载 |
||||
*/ |
||||
public void resume() { |
||||
receiver.manager.setCmd(CommonUtil.createCmd(receiver.entity, CmdFactory.TASK_START)).exe(); |
||||
} |
||||
|
||||
/** |
||||
* 取消下载 |
||||
*/ |
||||
public void cancel() { |
||||
receiver.manager.setCmd(CommonUtil.createCmd(receiver.entity, CmdFactory.TASK_CANCEL)).exe(); |
||||
} |
||||
|
||||
public static class SimpleSchedulerListener implements OnSchedulerListener { |
||||
|
||||
@Override public void onTaskPre(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskResume(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskStart(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskStop(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskCancel(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskFail(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskComplete(Task task) { |
||||
|
||||
} |
||||
|
||||
@Override public void onTaskRunning(Task task) { |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue