控制命令

This commit is contained in:
lyy
2016-08-22 21:30:23 +08:00
parent 01ba765278
commit 3fd6ff7f70
4 changed files with 91 additions and 16 deletions

View File

@ -15,26 +15,31 @@ public class DownloadTarget extends IDownloadTarget {
private static volatile DownloadTarget INSTANCE = null;
private Context mContext;
public static DownloadTarget getInstance() {
public static DownloadTarget getInstance(Context context) {
// if (INSTANCE == null) {
// Log.e(TAG, "请在Application中调用DownloadTarget.init()方法注册下载器");
// return null;
// }
if (INSTANCE == null) {
Log.e(TAG, "请在Application中调用DownloadTarget.init()方法注册下载器");
return null;
synchronized (LOCK) {
INSTANCE = new DownloadTarget(context.getApplicationContext());
}
}
return INSTANCE;
}
/**
* 初始化下载器
*
* @param context 全局Context
*/
public static void init(Context context) {
if (INSTANCE == null) {
synchronized (LOCK) {
INSTANCE = new DownloadTarget(context);
}
}
}
//
// /**
// * 初始化下载器
// *
// * @param context 全局Context
// */
// public static void init(Context context) {
// if (INSTANCE == null) {
// synchronized (LOCK) {
// INSTANCE = new DownloadTarget(context.getApplicationContext());
// }
// }
// }
private DownloadTarget() {
super();

View File

@ -0,0 +1,18 @@
package com.arialyy.downloadutil.core.command;
import com.arialyy.downloadutil.core.IDownloadTarget;
/**
* Created by lyy on 2016/8/22.
* 添加任务的命令
*/
public class AddCommand extends IDownloadCommand {
public AddCommand(IDownloadTarget target) {
super(target);
}
@Override
public void executeComment() {
}
}

View File

@ -0,0 +1,34 @@
package com.arialyy.downloadutil.core.command;
import com.arialyy.downloadutil.core.DownloadTarget;
import com.arialyy.downloadutil.core.IDownloadTarget;
import java.util.List;
/**
* Created by lyy on 2016/8/22.
* 下载命令
*/
public abstract class IDownloadCommand {
private IDownloadTarget target;
public IDownloadCommand(IDownloadTarget target) {
this.target = target;
}
/**
* 执行命令
*/
public abstract void executeComment();
/**
* 设置下载器
*
* @param downloadTarget {@link IDownloadTarget}
*/
public void setDownloadTarget(IDownloadTarget downloadTarget) {
target = downloadTarget;
}
}

View File

@ -0,0 +1,18 @@
package com.arialyy.downloadutil.core.command;
import com.arialyy.downloadutil.core.IDownloadTarget;
/**
* Created by lyy on 2016/8/22.
* 开始命令
*/
public class StartCommand extends IDownloadCommand{
public StartCommand(IDownloadTarget target) {
super(target);
}
@Override
public void executeComment() {
}
}