375 lines
11 KiB
Java
375 lines
11 KiB
Java
package com.squareup.picasso;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.net.Uri;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.os.Process;
|
|
import android.widget.ImageView;
|
|
import com.squareup.picasso.Action;
|
|
import com.ubt.jimu.base.entities.Course;
|
|
import java.lang.ref.ReferenceQueue;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.WeakHashMap;
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class Picasso {
|
|
static final Handler p = new Handler(Looper.getMainLooper()) { // from class: com.squareup.picasso.Picasso.1
|
|
@Override // android.os.Handler
|
|
public void handleMessage(Message message) {
|
|
int i = message.what;
|
|
if (i == 3) {
|
|
Action action = (Action) message.obj;
|
|
if (action.f().n) {
|
|
Utils.a("Main", "canceled", action.b.d(), "target got garbage collected");
|
|
}
|
|
action.a.a(action.j());
|
|
return;
|
|
}
|
|
int i2 = 0;
|
|
if (i == 8) {
|
|
List list = (List) message.obj;
|
|
int size = list.size();
|
|
while (i2 < size) {
|
|
BitmapHunter bitmapHunter = (BitmapHunter) list.get(i2);
|
|
bitmapHunter.b.a(bitmapHunter);
|
|
i2++;
|
|
}
|
|
return;
|
|
}
|
|
if (i != 13) {
|
|
throw new AssertionError("Unknown handler message received: " + message.what);
|
|
}
|
|
List list2 = (List) message.obj;
|
|
int size2 = list2.size();
|
|
while (i2 < size2) {
|
|
Action action2 = (Action) list2.get(i2);
|
|
action2.a.b(action2);
|
|
i2++;
|
|
}
|
|
}
|
|
};
|
|
static volatile Picasso q = null;
|
|
private final Listener a;
|
|
private final RequestTransformer b;
|
|
private final CleanupThread c;
|
|
private final List<RequestHandler> d;
|
|
final Context e;
|
|
final Dispatcher f;
|
|
final Cache g;
|
|
final Stats h;
|
|
final Map<Object, Action> i;
|
|
final Map<ImageView, DeferredRequestCreator> j;
|
|
final ReferenceQueue<Object> k;
|
|
final Bitmap.Config l;
|
|
boolean m;
|
|
volatile boolean n;
|
|
boolean o;
|
|
|
|
public static class Builder {
|
|
private final Context a;
|
|
private Downloader b;
|
|
private ExecutorService c;
|
|
private Cache d;
|
|
private Listener e;
|
|
private RequestTransformer f;
|
|
private List<RequestHandler> g;
|
|
private Bitmap.Config h;
|
|
private boolean i;
|
|
private boolean j;
|
|
|
|
public Builder(Context context) {
|
|
if (context == null) {
|
|
throw new IllegalArgumentException("Context must not be null.");
|
|
}
|
|
this.a = context.getApplicationContext();
|
|
}
|
|
|
|
public Picasso a() {
|
|
Context context = this.a;
|
|
if (this.b == null) {
|
|
this.b = Utils.c(context);
|
|
}
|
|
if (this.d == null) {
|
|
this.d = new LruCache(context);
|
|
}
|
|
if (this.c == null) {
|
|
this.c = new PicassoExecutorService();
|
|
}
|
|
if (this.f == null) {
|
|
this.f = RequestTransformer.a;
|
|
}
|
|
Stats stats = new Stats(this.d);
|
|
return new Picasso(context, new Dispatcher(context, this.c, Picasso.p, this.b, this.d, stats), this.d, this.e, this.f, this.g, stats, this.h, this.i, this.j);
|
|
}
|
|
}
|
|
|
|
private static class CleanupThread extends Thread {
|
|
private final ReferenceQueue<Object> a;
|
|
private final Handler b;
|
|
|
|
CleanupThread(ReferenceQueue<Object> referenceQueue, Handler handler) {
|
|
this.a = referenceQueue;
|
|
this.b = handler;
|
|
setDaemon(true);
|
|
setName("Picasso-refQueue");
|
|
}
|
|
|
|
@Override // java.lang.Thread, java.lang.Runnable
|
|
public void run() {
|
|
Process.setThreadPriority(10);
|
|
while (true) {
|
|
try {
|
|
Action.RequestWeakReference requestWeakReference = (Action.RequestWeakReference) this.a.remove(1000L);
|
|
Message obtainMessage = this.b.obtainMessage();
|
|
if (requestWeakReference != null) {
|
|
obtainMessage.what = 3;
|
|
obtainMessage.obj = requestWeakReference.a;
|
|
this.b.sendMessage(obtainMessage);
|
|
} else {
|
|
obtainMessage.recycle();
|
|
}
|
|
} catch (InterruptedException unused) {
|
|
return;
|
|
} catch (Exception e) {
|
|
this.b.post(new Runnable(this) { // from class: com.squareup.picasso.Picasso.CleanupThread.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
throw new RuntimeException(e);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface Listener {
|
|
void a(Picasso picasso, Uri uri, Exception exc);
|
|
}
|
|
|
|
public enum LoadedFrom {
|
|
MEMORY(-16711936),
|
|
DISK(-16776961),
|
|
NETWORK(-65536);
|
|
|
|
final int debugColor;
|
|
|
|
LoadedFrom(int i) {
|
|
this.debugColor = i;
|
|
}
|
|
}
|
|
|
|
public enum Priority {
|
|
LOW,
|
|
NORMAL,
|
|
HIGH
|
|
}
|
|
|
|
public interface RequestTransformer {
|
|
public static final RequestTransformer a = new RequestTransformer() { // from class: com.squareup.picasso.Picasso.RequestTransformer.1
|
|
@Override // com.squareup.picasso.Picasso.RequestTransformer
|
|
public Request a(Request request) {
|
|
return request;
|
|
}
|
|
};
|
|
|
|
Request a(Request request);
|
|
}
|
|
|
|
Picasso(Context context, Dispatcher dispatcher, Cache cache, Listener listener, RequestTransformer requestTransformer, List<RequestHandler> list, Stats stats, Bitmap.Config config, boolean z, boolean z2) {
|
|
this.e = context;
|
|
this.f = dispatcher;
|
|
this.g = cache;
|
|
this.a = listener;
|
|
this.b = requestTransformer;
|
|
this.l = config;
|
|
ArrayList arrayList = new ArrayList((list != null ? list.size() : 0) + 7);
|
|
arrayList.add(new ResourceRequestHandler(context));
|
|
if (list != null) {
|
|
arrayList.addAll(list);
|
|
}
|
|
arrayList.add(new ContactsPhotoRequestHandler(context));
|
|
arrayList.add(new MediaStoreRequestHandler(context));
|
|
arrayList.add(new ContentStreamRequestHandler(context));
|
|
arrayList.add(new AssetRequestHandler(context));
|
|
arrayList.add(new FileRequestHandler(context));
|
|
arrayList.add(new NetworkRequestHandler(dispatcher.d, stats));
|
|
this.d = Collections.unmodifiableList(arrayList);
|
|
this.h = stats;
|
|
this.i = new WeakHashMap();
|
|
this.j = new WeakHashMap();
|
|
this.m = z;
|
|
this.n = z2;
|
|
this.k = new ReferenceQueue<>();
|
|
this.c = new CleanupThread(this.k, p);
|
|
this.c.start();
|
|
}
|
|
|
|
Bitmap b(String str) {
|
|
Bitmap bitmap = this.g.get(str);
|
|
if (bitmap != null) {
|
|
this.h.b();
|
|
} else {
|
|
this.h.c();
|
|
}
|
|
return bitmap;
|
|
}
|
|
|
|
void c(Action action) {
|
|
this.f.b(action);
|
|
}
|
|
|
|
public void a(ImageView imageView) {
|
|
a((Object) imageView);
|
|
}
|
|
|
|
public void a(Target target) {
|
|
a((Object) target);
|
|
}
|
|
|
|
public RequestCreator a(Uri uri) {
|
|
return new RequestCreator(this, uri, 0);
|
|
}
|
|
|
|
void b(Action action) {
|
|
Bitmap b = MemoryPolicy.shouldReadFromMemoryCache(action.e) ? b(action.c()) : null;
|
|
if (b != null) {
|
|
a(b, LoadedFrom.MEMORY, action);
|
|
if (this.n) {
|
|
Utils.a("Main", Course.STATUS_COMPLETED, action.b.d(), "from " + LoadedFrom.MEMORY);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
a(action);
|
|
if (this.n) {
|
|
Utils.a("Main", "resumed", action.b.d());
|
|
}
|
|
}
|
|
|
|
public RequestCreator a(String str) {
|
|
if (str == null) {
|
|
return new RequestCreator(this, null, 0);
|
|
}
|
|
if (str.trim().length() != 0) {
|
|
return a(Uri.parse(str));
|
|
}
|
|
throw new IllegalArgumentException("Path must not be empty.");
|
|
}
|
|
|
|
List<RequestHandler> a() {
|
|
return this.d;
|
|
}
|
|
|
|
Request a(Request request) {
|
|
this.b.a(request);
|
|
if (request != null) {
|
|
return request;
|
|
}
|
|
throw new IllegalStateException("Request transformer " + this.b.getClass().getCanonicalName() + " returned null for " + request);
|
|
}
|
|
|
|
void a(ImageView imageView, DeferredRequestCreator deferredRequestCreator) {
|
|
this.j.put(imageView, deferredRequestCreator);
|
|
}
|
|
|
|
void a(Action action) {
|
|
Object j = action.j();
|
|
if (j != null && this.i.get(j) != action) {
|
|
a(j);
|
|
this.i.put(j, action);
|
|
}
|
|
c(action);
|
|
}
|
|
|
|
void a(BitmapHunter bitmapHunter) {
|
|
Action a = bitmapHunter.a();
|
|
List<Action> b = bitmapHunter.b();
|
|
boolean z = true;
|
|
boolean z2 = (b == null || b.isEmpty()) ? false : true;
|
|
if (a == null && !z2) {
|
|
z = false;
|
|
}
|
|
if (z) {
|
|
Uri uri = bitmapHunter.c().d;
|
|
Exception d = bitmapHunter.d();
|
|
Bitmap m = bitmapHunter.m();
|
|
LoadedFrom f = bitmapHunter.f();
|
|
if (a != null) {
|
|
a(m, f, a);
|
|
}
|
|
if (z2) {
|
|
int size = b.size();
|
|
for (int i = 0; i < size; i++) {
|
|
a(m, f, b.get(i));
|
|
}
|
|
}
|
|
Listener listener = this.a;
|
|
if (listener == null || d == null) {
|
|
return;
|
|
}
|
|
listener.a(this, uri, d);
|
|
}
|
|
}
|
|
|
|
private void a(Bitmap bitmap, LoadedFrom loadedFrom, Action action) {
|
|
if (action.k()) {
|
|
return;
|
|
}
|
|
if (!action.l()) {
|
|
this.i.remove(action.j());
|
|
}
|
|
if (bitmap == null) {
|
|
action.b();
|
|
if (this.n) {
|
|
Utils.a("Main", "errored", action.b.d());
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if (loadedFrom != null) {
|
|
action.a(bitmap, loadedFrom);
|
|
if (this.n) {
|
|
Utils.a("Main", Course.STATUS_COMPLETED, action.b.d(), "from " + loadedFrom);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
throw new AssertionError("LoadedFrom cannot be null.");
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(Object obj) {
|
|
Utils.a();
|
|
Action remove = this.i.remove(obj);
|
|
if (remove != null) {
|
|
remove.a();
|
|
this.f.a(remove);
|
|
}
|
|
if (obj instanceof ImageView) {
|
|
DeferredRequestCreator remove2 = this.j.remove((ImageView) obj);
|
|
if (remove2 != null) {
|
|
remove2.a();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Picasso a(Context context) {
|
|
if (q == null) {
|
|
synchronized (Picasso.class) {
|
|
if (q == null) {
|
|
q = new Builder(context).a();
|
|
}
|
|
}
|
|
}
|
|
return q;
|
|
}
|
|
}
|