pull/2/head
AriaLyy 8 years ago
parent 8a49447fa3
commit 853571bc00
  1. 5
      downloadutil/src/main/java/com/arialyy/downloadutil/core/AMTarget.java
  2. 11
      downloadutil/src/main/java/com/arialyy/downloadutil/core/Aria.java
  3. 77
      downloadutil/src/main/java/com/arialyy/downloadutil/core/AriaManager.java

@ -3,7 +3,8 @@ package com.arialyy.downloadutil.core;
import android.content.Context;
import com.arialyy.downloadutil.core.scheduler.OnSchedulerListener;
public class AMEntity {
Context context;
public class AMTarget {
Context context;
OnSchedulerListener listener;
DownloadEntity entity;
}

@ -42,14 +42,9 @@ public class Aria {
mDownloadManager = DownloadManager.init(context);
}
public static Aria get(Context context) {
if (INSTANCE == null) {
synchronized (LOCK) {
INSTANCE = new Aria();
}
}
return INSTANCE;
}
//public static AriaManager whit(Context context) {
// return AriaManager.getInstance().get(context);
//}
/**
* 开始下载

@ -1,36 +1,93 @@
package com.arialyy.downloadutil.core;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import com.arialyy.downloadutil.core.scheduler.OnSchedulerListener;
import android.os.Build;
import android.os.Bundle;
import java.util.HashMap;
import java.util.Map;
/**
* Created by lyy on 2016/12/1.
*/
public class AriaManager {
private Map<String, AMEntity> mAria = new HashMap<>();
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
private static final Object LOCK = new Object();
private static volatile AriaManager INSTANCE = null;
private Map<String, AMTarget> mTargets = new HashMap<>();
private DownloadManager mManager;
private LifeCallback mLifeCallback;
private static final Object LOCK = new Object();
private static volatile AriaManager INSTANCE = null;
private AriaManager(){
private AriaManager(Context context) {
regAppLifeCallback(context);
mManager = DownloadManager.init(context);
}
public static AriaManager getInstance() {
public static AriaManager getInstance(Context context) {
if (INSTANCE == null) {
synchronized (LOCK) {
INSTANCE = new AriaManager();
INSTANCE = new AriaManager(context);
}
}
return INSTANCE;
}
public synchronized void get(Context context){
private void putTarget(Context context) {
String clsName = context.getClass().getName();
AMTarget target = mTargets.get(clsName);
if (target == null) {
target = new AMTarget();
mTargets.put(clsName, target);
}
}
private AMTarget getTarget(Context context) {
return mTargets.get(context.getClass().getName());
}
/**
* 注册APP生命周期回调
*/
private void regAppLifeCallback(Context context) {
Context app = context.getApplicationContext();
if (app instanceof Application) {
mLifeCallback = new LifeCallback();
((Application) app).registerActivityLifecycleCallbacks(mLifeCallback);
}
}
/**
* Activity生命周期
*/
private class LifeCallback implements Application.ActivityLifecycleCallbacks {
@Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
}
@Override public void onActivityStarted(Activity activity) {
}
@Override public void onActivityResumed(Activity activity) {
}
@Override public void onActivityPaused(Activity activity) {
}
@Override public void onActivityStopped(Activity activity) {
}
@Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override public void onActivityDestroyed(Activity activity) {
}
}
}

Loading…
Cancel
Save