添加dialog支持、修复一个内存溢出的问题
This commit is contained in:
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||
public class AMTarget {
|
||||
private AMReceiver receiver;
|
||||
|
||||
public AMTarget(AMReceiver receiver) {
|
||||
AMTarget(AMReceiver receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ public class AMTarget {
|
||||
cmds.add(CommonUtil.createCmd(receiver.obj, receiver.entity, CmdFactory.TASK_CREATE));
|
||||
cmds.add(CommonUtil.createCmd(receiver.obj, receiver.entity, CmdFactory.TASK_START));
|
||||
receiver.manager.setCmds(cmds).exe();
|
||||
cmds.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,6 +77,21 @@ public class AMTarget {
|
||||
CommonUtil.createCmd(receiver.obj, receiver.entity, CmdFactory.TASK_CANCEL)).exe();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在下载
|
||||
*/
|
||||
public boolean isDownloading() {
|
||||
return DownloadManager.getInstance().getTaskQueue().getTask(receiver.entity).isDownloading();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新下载
|
||||
*/
|
||||
public void reStart() {
|
||||
cancel();
|
||||
start();
|
||||
}
|
||||
|
||||
public static class SimpleSchedulerListener implements OnSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
|
@ -202,15 +202,15 @@ import java.util.Set;
|
||||
//如果Dialog已经设置Dismiss事件,则查找cancel事件
|
||||
if (dismissMsg != null) {
|
||||
Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage");
|
||||
Message cancelMsg = (Message) dismissField.get(dialog);
|
||||
Message cancelMsg = (Message) cancelField.get(dialog);
|
||||
if (cancelMsg != null) {
|
||||
Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露,"
|
||||
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件");
|
||||
} else {
|
||||
|
||||
dialog.setCancelMessage(createCancelMessage());
|
||||
}
|
||||
} else {
|
||||
|
||||
dialog.setCancelMessage(createDismissMessage());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
@ -236,6 +236,55 @@ import java.util.Set;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Dialog取消消息
|
||||
*/
|
||||
private Message createCancelMessage() {
|
||||
final Message cancelMsg = new Message();
|
||||
cancelMsg.what = 0x44;
|
||||
cancelMsg.obj = new Dialog.OnCancelListener() {
|
||||
|
||||
@Override public void onCancel(DialogInterface dialog) {
|
||||
destroySchedulerListener(dialog);
|
||||
}
|
||||
};
|
||||
return cancelMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Dialog dismiss取消消息
|
||||
*/
|
||||
private Message createDismissMessage() {
|
||||
final Message cancelMsg = new Message();
|
||||
cancelMsg.what = 0x43;
|
||||
cancelMsg.obj = new Dialog.OnDismissListener() {
|
||||
|
||||
@Override public void onDismiss(DialogInterface dialog) {
|
||||
destroySchedulerListener(dialog);
|
||||
}
|
||||
};
|
||||
return cancelMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* onDestroy
|
||||
*/
|
||||
private void destroySchedulerListener(Object obj) {
|
||||
Set<String> keys = mTargets.keySet();
|
||||
String clsName = obj.getClass().getName();
|
||||
for (String key : keys) {
|
||||
if (key.equals(clsName) || key.contains(clsName)) {
|
||||
AMReceiver target = mTargets.get(key);
|
||||
if (target.obj != null) {
|
||||
if (target.obj instanceof Application || target.obj instanceof Service) break;
|
||||
target.removeSchedulerListener();
|
||||
mTargets.remove(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activity生命周期
|
||||
*/
|
||||
@ -266,19 +315,7 @@ import java.util.Set;
|
||||
}
|
||||
|
||||
@Override public void onActivityDestroyed(Activity activity) {
|
||||
Set<String> keys = mTargets.keySet();
|
||||
for (String key : keys) {
|
||||
String clsName = activity.getClass().getName();
|
||||
if (key.equals(clsName) || key.contains(clsName)) {
|
||||
AMReceiver target = mTargets.get(key);
|
||||
if (target.obj != null) {
|
||||
if (target.obj instanceof Application || target.obj instanceof Service) break;
|
||||
target.removeSchedulerListener();
|
||||
mTargets.remove(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
destroySchedulerListener(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,6 +223,8 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException("target 不能为null");
|
||||
}
|
||||
mSchedulerListeners.remove(target.getClass().getName());
|
||||
OnSchedulerListener listener = mSchedulerListeners.get(target.getClass().getName());
|
||||
mSchedulerListeners.remove(listener);
|
||||
listener = null;
|
||||
}
|
||||
}
|
@ -436,7 +436,7 @@ public class DbUtil {
|
||||
}
|
||||
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
|
||||
entitys.add(entity);
|
||||
Log.d(TAG, "rowid ==> " + entity.rowID);
|
||||
//Log.d(TAG, "rowid ==> " + entity.rowID);
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
|
Reference in New Issue
Block a user