任意类使用aria
This commit is contained in:
@@ -17,15 +17,8 @@
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.Fragment;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.widget.PopupWindow;
|
||||
import com.arialyy.aria.core.download.DownloadReceiver;
|
||||
import com.arialyy.aria.core.upload.UploadReceiver;
|
||||
|
||||
@@ -60,52 +53,69 @@ import com.arialyy.aria.core.upload.UploadReceiver;
|
||||
/**
|
||||
* 初始化下载
|
||||
*
|
||||
* @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
* @param context 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
*/
|
||||
public static DownloadReceiver download(Object obj) {
|
||||
return get(obj).download(obj);
|
||||
public static DownloadReceiver download(Context context) {
|
||||
return get(context).download(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化上传
|
||||
*
|
||||
* @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
* @param context 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
*/
|
||||
public static UploadReceiver upload(Object obj) {
|
||||
return get(obj).upload(obj);
|
||||
public static UploadReceiver upload(Context context) {
|
||||
return get(context).upload(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在任意对象中初始化下载
|
||||
*
|
||||
* @param obj 任意对象
|
||||
*/
|
||||
public static DownloadReceiver download(Context context, Object obj) {
|
||||
return get(context).download(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在任意对象中初始化上传
|
||||
*
|
||||
* @param obj 任意对象
|
||||
*/
|
||||
public static UploadReceiver upload(Context context, Object obj) {
|
||||
return get(context).upload(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理通用事件
|
||||
*
|
||||
* @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
*/
|
||||
public static AriaManager get(Object obj) {
|
||||
if (obj instanceof Activity || obj instanceof Service || obj instanceof Application) {
|
||||
return AriaManager.getInstance((Context) obj);
|
||||
} else if (obj instanceof DialogFragment) {
|
||||
DialogFragment dialog = (DialogFragment) obj;
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext()
|
||||
: dialog.getActivity());
|
||||
} else if (obj instanceof android.support.v4.app.Fragment) {
|
||||
android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
: fragment.getActivity());
|
||||
} else if (obj instanceof Fragment) {
|
||||
Fragment fragment = (Fragment) obj;
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
: fragment.getActivity());
|
||||
} else if (obj instanceof PopupWindow) {
|
||||
PopupWindow popupWindow = (PopupWindow) obj;
|
||||
return AriaManager.getInstance(popupWindow.getContentView().getContext());
|
||||
} else if (obj instanceof Dialog) {
|
||||
Dialog dialog = (Dialog) obj;
|
||||
return AriaManager.getInstance(dialog.getContext());
|
||||
} else {
|
||||
throw new IllegalArgumentException("不支持的类型");
|
||||
}
|
||||
public static AriaManager get(Context context) {
|
||||
return AriaManager.getInstance(context);
|
||||
//if (obj instanceof Activity || obj instanceof Service || obj instanceof Application) {
|
||||
// return AriaManager.getInstance((Context) obj);
|
||||
//} else if (obj instanceof DialogFragment) {
|
||||
// DialogFragment dialog = (DialogFragment) obj;
|
||||
// return AriaManager.getInstance(
|
||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext()
|
||||
// : dialog.getActivity());
|
||||
//} else if (obj instanceof android.support.v4.app.Fragment) {
|
||||
// android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
|
||||
// return AriaManager.getInstance(
|
||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
// : fragment.getActivity());
|
||||
//} else if (obj instanceof Fragment) {
|
||||
// Fragment fragment = (Fragment) obj;
|
||||
// return AriaManager.getInstance(
|
||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
// : fragment.getActivity());
|
||||
//} else if (obj instanceof PopupWindow) {
|
||||
// PopupWindow popupWindow = (PopupWindow) obj;
|
||||
// return AriaManager.getInstance(popupWindow.getContentView().getContext());
|
||||
//} else if (obj instanceof Dialog) {
|
||||
// Dialog dialog = (Dialog) obj;
|
||||
// return AriaManager.getInstance(dialog.getContext());
|
||||
//} else {
|
||||
// throw new IllegalArgumentException("不支持的类型");
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,11 @@ import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.app.Dialog;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.PopupWindow;
|
||||
import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.common.QueueMod;
|
||||
@@ -258,6 +256,7 @@ import org.xml.sax.SAXException;
|
||||
final String key = getKey(isDownload, obj);
|
||||
IReceiver receiver = mReceivers.get(key);
|
||||
boolean needRmReceiver = false;
|
||||
// 监控Dialog、fragment、popupWindow的生命周期
|
||||
final WidgetLiftManager widgetLiftManager = new WidgetLiftManager();
|
||||
if (obj instanceof Dialog) {
|
||||
needRmReceiver = widgetLiftManager.handleDialogLift((Dialog) obj);
|
||||
@@ -323,45 +322,32 @@ import org.xml.sax.SAXException;
|
||||
* 根据功能类型和控件类型获取对应的key
|
||||
*/
|
||||
private String getKey(boolean isDownload, Object obj) {
|
||||
// TODO: 2018/4/12 不做限制了,让所有类都可以使用
|
||||
String clsName = obj.getClass().getName();
|
||||
String key = "";
|
||||
if (!(obj instanceof Activity)) {
|
||||
if (obj instanceof DialogFragment) {
|
||||
key = clsName + "_" + ((DialogFragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof android.app.DialogFragment) {
|
||||
key = clsName + "_" + ((android.app.DialogFragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof android.support.v4.app.Fragment) {
|
||||
key = clsName + "_" + ((Fragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof android.app.Fragment) {
|
||||
key = clsName + "_" + ((android.app.Fragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof Dialog) {
|
||||
Activity activity = ((Dialog) obj).getOwnerActivity();
|
||||
if (activity != null) {
|
||||
key = clsName + "_" + activity.getClass().getName();
|
||||
} else {
|
||||
key = clsName;
|
||||
}
|
||||
} else if (obj instanceof PopupWindow) {
|
||||
Context context = ((PopupWindow) obj).getContentView().getContext();
|
||||
if (context instanceof Activity) {
|
||||
key = clsName + "_" + context.getClass().getName();
|
||||
} else {
|
||||
key = clsName;
|
||||
}
|
||||
} else if (obj instanceof Service) {
|
||||
key = clsName;
|
||||
} else if (obj instanceof Application) {
|
||||
String key;
|
||||
if (obj instanceof DialogFragment) {
|
||||
key = clsName + "_" + ((DialogFragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof android.app.DialogFragment) {
|
||||
key = clsName + "_" + ((android.app.DialogFragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof android.support.v4.app.Fragment) {
|
||||
key = clsName + "_" + ((Fragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof android.app.Fragment) {
|
||||
key = clsName + "_" + ((android.app.Fragment) obj).getActivity().getClass().getName();
|
||||
} else if (obj instanceof Dialog) {
|
||||
Activity activity = ((Dialog) obj).getOwnerActivity();
|
||||
if (activity != null) {
|
||||
key = clsName + "_" + activity.getClass().getName();
|
||||
} else {
|
||||
key = clsName;
|
||||
}
|
||||
}
|
||||
if (obj instanceof Activity || obj instanceof Service) {
|
||||
} else if (obj instanceof PopupWindow) {
|
||||
Context context = ((PopupWindow) obj).getContentView().getContext();
|
||||
if (context instanceof Activity) {
|
||||
key = clsName + "_" + context.getClass().getName();
|
||||
} else {
|
||||
key = clsName;
|
||||
}
|
||||
} else {
|
||||
key = clsName;
|
||||
} else if (obj instanceof Application) {
|
||||
key = clsName;
|
||||
}
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException("未知类型");
|
||||
}
|
||||
key += (isDownload ? DOWNLOAD : UPLOAD) + obj.hashCode();
|
||||
return key;
|
||||
|
||||
@@ -137,6 +137,8 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
filePath += mEntity.getFileName();
|
||||
}
|
||||
}
|
||||
mEntity.setFileName(file.getName());
|
||||
|
||||
//设置文件保存路径,如果新文件路径和就文件路径不同,则修改路径
|
||||
if (!filePath.equals(mEntity.getDownloadPath())) {
|
||||
if (!mTaskEntity.refreshInfo && DbEntity.checkDataExist(DownloadEntity.class,
|
||||
@@ -146,11 +148,12 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
}
|
||||
File oldFile = new File(mEntity.getDownloadPath());
|
||||
File newFile = new File(filePath);
|
||||
if (TextUtils.isEmpty(mEntity.getDownloadPath()) || oldFile.renameTo(newFile)) {
|
||||
mEntity.setDownloadPath(filePath);
|
||||
mEntity.setFileName(newFile.getName());
|
||||
mTaskEntity.key = filePath;
|
||||
//mTaskEntity.update();
|
||||
mEntity.setDownloadPath(filePath);
|
||||
mEntity.setFileName(newFile.getName());
|
||||
mTaskEntity.key = filePath;
|
||||
//mTaskEntity.update();
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(newFile);
|
||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newFile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,14 +45,12 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
|
||||
/**
|
||||
* 重置状态,将任务状态设置为未开始状态
|
||||
* 注意:如果在后续方法调用链中没有调用 {@link #start()}、{@link #stop()}、{@link #cancel()}、{@link #resume()}
|
||||
* 等操作任务的方法,那么你需要调用{@link #save()}才能将修改保存到数据库
|
||||
*/
|
||||
public TARGET resetState() {
|
||||
if (checkEntity()) {
|
||||
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
|
||||
mTaskEntity.refreshInfo = true;
|
||||
} else {
|
||||
ALog.e(TAG, "重置状态失败");
|
||||
}
|
||||
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
|
||||
mTaskEntity.refreshInfo = true;
|
||||
return (TARGET) this;
|
||||
}
|
||||
|
||||
@@ -99,19 +97,17 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
|
||||
/**
|
||||
* 设置扩展字段,用来保存你的其它数据,如果你的数据比较多,你可以把你的数据转换为JSON字符串,然后再存到Aria中
|
||||
* 注意:如果在后续方法调用链中没有调用 {@link #start()}、{@link #stop()}、{@link #cancel()}、{@link #resume()}
|
||||
* 等操作任务的方法,那么你需要调用{@link #save()}才能将修改保存到数据库
|
||||
*
|
||||
* @param str 扩展数据
|
||||
*/
|
||||
public TARGET setExtendField(String str) {
|
||||
if (TextUtils.isEmpty(str)) return (TARGET) this;
|
||||
if (checkEntity()) {
|
||||
if (TextUtils.isEmpty(mEntity.getStr()) || !mEntity.getStr().equals(str)) {
|
||||
mEntity.setStr(str);
|
||||
} else {
|
||||
ALog.e(TAG, "设置扩展字段失败,扩展字段为null");
|
||||
}
|
||||
if (TextUtils.isEmpty(mEntity.getStr()) || !mEntity.getStr().equals(str)) {
|
||||
mEntity.setStr(str);
|
||||
} else {
|
||||
ALog.e(TAG, "设置扩展字段失败");
|
||||
ALog.e(TAG, "设置扩展字段失败,扩展字段为null");
|
||||
}
|
||||
|
||||
return (TARGET) this;
|
||||
@@ -170,6 +166,15 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
return taskType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存修改
|
||||
*/
|
||||
public void save() {
|
||||
if (!checkEntity()) {
|
||||
ALog.e(TAG, "保存修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始任务
|
||||
*/
|
||||
|
||||
@@ -139,11 +139,4 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
||||
}
|
||||
|
||||
public abstract String getKey();
|
||||
|
||||
@Override public void update() {
|
||||
if (getEntity() != null) {
|
||||
getEntity().update();
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
@@ -89,6 +90,7 @@ class DTEFactory implements INormalTEFactory<DownloadEntity, DownloadTaskEntity>
|
||||
entity.setUrl(downloadUrl);
|
||||
entity.setGroupChild(false);
|
||||
entity.setGroupName(null);
|
||||
entity.setDownloadPath(UUID.randomUUID().toString().replace("-", "")); //设置临时路径
|
||||
}
|
||||
File file = new File(entity.getDownloadPath());
|
||||
if (!file.exists()) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.arialyy.aria.orm;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -128,7 +129,7 @@ abstract class AbsDelegate {
|
||||
* @return 转换后的内容
|
||||
*/
|
||||
String convertValue(String value) {
|
||||
if (value.contains("'")) {
|
||||
if (!TextUtils.isEmpty(value) && value.contains("'")) {
|
||||
return URLEncoder.encode(value);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<!--android:name=".MainActivity"-->
|
||||
<!--android:name=".test.TestActivity"-->
|
||||
<!--android:name=".test.TestGroupActivity"-->
|
||||
<activity
|
||||
android:name=".test.TestGroupActivity"
|
||||
android:name=".test.AnyRunActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
@@ -57,8 +57,8 @@ public class DownloadDialog extends AbsDialog {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int p = (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
|
||||
@@ -73,16 +73,16 @@ public class DownloadDialog extends AbsDialog {
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/飞机大战.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
getBinding().setProgress((int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
|
||||
@@ -45,7 +45,7 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
Aria.download(getContext()).unRegister();
|
||||
}
|
||||
|
||||
@Download.onPre(DOWNLOAD_URL) protected void onPre(DownloadTask task) {
|
||||
@@ -96,16 +96,16 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,13 +59,13 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
if (Aria.download(getContext()).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(getContext()).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
@@ -78,16 +78,16 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
private static final String DOWNLOAD_URL = "https://res5.d.cn/2137e42d610b3488d9420c6421529386eee5bdbfd9be1fafe0a05d6dabaec8c156ddbd00581055bbaeac03904fb63310e80010680235d16bd4c040b50096a0c20dd1c4b0854529a1.apk";
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
if (Aria.download(getContext()).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(getContext()).load(DOWNLOAD_URL);
|
||||
getBinding().setProgress(target.getPercent());
|
||||
}
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
@@ -57,22 +57,22 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
Aria.download(this).register();
|
||||
Aria.download(getContext()).register();
|
||||
}
|
||||
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ import java.util.List;
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
Aria.download(getContext()).register();
|
||||
initWidget();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
Aria.download(getContext()).unRegister();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
@@ -134,10 +134,10 @@ import java.util.List;
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this).load(mUrls).getSubTaskManager().startSubTask(mChildEntity.getUrl());
|
||||
Aria.download(getContext()).load(mUrls).getSubTaskManager().startSubTask(mChildEntity.getUrl());
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(mUrls).getSubTaskManager().stopSubTask(mChildEntity.getUrl());
|
||||
Aria.download(getContext()).load(mUrls).getSubTaskManager().stopSubTask(mChildEntity.getUrl());
|
||||
break;
|
||||
//case R.id.cancel:
|
||||
// Aria.download(this).load(mUrls).getSubTaskManager().cancelSubTask(mChildEntity.getUrl());
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.arialyy.simple.test;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityTestBinding;
|
||||
|
||||
/**
|
||||
* Created by laoyuyu on 2018/4/13.
|
||||
*/
|
||||
|
||||
public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
||||
AnyRunnModule module;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_test;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mBar.setVisibility(View.GONE);
|
||||
module = new AnyRunnModule(this);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
module.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
module.stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
module.cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
module.unRegist();
|
||||
}
|
||||
}
|
||||
86
app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
Normal file
86
app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.arialyy.simple.test;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by laoyuyu on 2018/4/13.
|
||||
*/
|
||||
|
||||
public class AnyRunnModule {
|
||||
String TAG = "TestActivity";
|
||||
String URL = "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||
private Context mContext;
|
||||
|
||||
public AnyRunnModule(Context context) {
|
||||
Aria.download(context, this).register();
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Download.onWait void onWait(DownloadTask task) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
|
||||
@Download.onPre protected void onPre(DownloadTask task) {
|
||||
Log.d(TAG, "onPre");
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
Log.d(TAG, "onStart");
|
||||
}
|
||||
|
||||
@Download.onTaskRunning protected void running(DownloadTask task) {
|
||||
Log.d(TAG, "running");
|
||||
}
|
||||
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
Log.d(TAG, "resume");
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
Log.d(TAG, "stop");
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
Log.d(TAG, "cancel");
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
Log.d(TAG, "fail");
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
|
||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||
}
|
||||
|
||||
void start() {
|
||||
Aria.download(mContext, this)
|
||||
.load(URL)
|
||||
.addHeader("Accept-Encoding", "gzip, deflate")
|
||||
.setRequestMode(RequestEnum.GET)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
||||
.resetState()
|
||||
.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
Aria.download(mContext, this).load(URL).stop();
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
Aria.download(mContext, this).load(URL).cancel();
|
||||
}
|
||||
|
||||
void unRegist() {
|
||||
Aria.download(mContext, this).unRegister();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user