From 82e8aee382b5159dc9804f07cf9014a280cc9753 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Wed, 21 Dec 2016 23:35:01 +0800 Subject: [PATCH] =?UTF-8?q?dialog=20=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/arialyy/aria/core/Aria.java | 38 +++++++++++++- .../com/arialyy/aria/core/AriaManager.java | 50 ++++++++++++++++--- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java index bfb884f9..2d2b3aaf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java @@ -19,6 +19,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; @@ -28,14 +30,29 @@ import android.os.Build; * Created by lyy on 2016/12/1. * https://github.com/AriaLyy/Aria * Aria启动,管理全局任务 + *
+ *
+ * DownloadEntity mEntity = new DownloadEntity();
+ * mEntity.setFileName(fileName); //设置文件名
+ * mEntity.setDownloadUrl(downloadUrl); //设置下载链接
+ * mEntity.setDownloadPath(downloadPath); //设置存放路径
+ *
+ * //启动下载
+ * Aria.whit(this).load(mEntity).start();
+ *
+ *
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
private Aria() {
}
+ /**
+ * 接受Activity、Service、Application
+ */
public static AMReceiver whit(Context context) {
- if (context == null) throw new IllegalArgumentException("context 不能为 null");
+ //if (context == null) throw new IllegalArgumentException("context 不能为 null");
+ checkNull(context);
if (context instanceof Activity
|| context instanceof Service
|| context instanceof Application) {
@@ -45,12 +62,31 @@ import android.os.Build;
}
}
+ /**
+ * 处理Fragment、或者DialogFragment
+ */
public static AMReceiver whit(Fragment fragment) {
+ checkNull(fragment);
return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
: fragment.getActivity()).get(fragment);
}
+ /**
+ * 处理Dialog
+ */
+ public static AMReceiver whit(Dialog dialog) {
+ checkNull(dialog);
+ return AriaManager.getInstance(dialog.getContext()).get(dialog);
+ }
+
+ private static void checkNull(Object obj) {
+ if (obj == null) throw new IllegalArgumentException("不能传入空对象");
+ }
+
+ /**
+ * 处理通用事件
+ */
public static AriaManager get(Context context) {
if (context == null) throw new IllegalArgumentException("context 不能为 null");
if (context instanceof Activity
diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
index 8ea0ded5..8310d4b0 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
@@ -18,10 +18,13 @@ package com.arialyy.aria.core;
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.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
+import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
@@ -29,6 +32,7 @@ import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.command.IDownloadCmd;
import com.arialyy.aria.util.Configuration;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -69,7 +73,7 @@ import java.util.Set;
/**
* 获取下载列表
*/
- public List