jimu-decompiled/sources/com/bumptech/glide/Glide.java
2025-05-13 19:24:51 +02:00

414 lines
19 KiB
Java

package com.bumptech.glide;
import android.app.Activity;
import android.content.ComponentCallbacks2;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.ImageHeaderParser;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.ResourceEncoder;
import com.bumptech.glide.load.data.DataRewinder;
import com.bumptech.glide.load.data.InputStreamRewinder;
import com.bumptech.glide.load.engine.Engine;
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.engine.cache.MemoryCache;
import com.bumptech.glide.load.engine.prefill.BitmapPreFiller;
import com.bumptech.glide.load.model.AssetUriLoader;
import com.bumptech.glide.load.model.ByteArrayLoader;
import com.bumptech.glide.load.model.ByteBufferEncoder;
import com.bumptech.glide.load.model.ByteBufferFileLoader;
import com.bumptech.glide.load.model.DataUrlLoader;
import com.bumptech.glide.load.model.FileLoader;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.MediaStoreFileLoader;
import com.bumptech.glide.load.model.ResourceLoader;
import com.bumptech.glide.load.model.StreamEncoder;
import com.bumptech.glide.load.model.StringLoader;
import com.bumptech.glide.load.model.UnitModelLoader;
import com.bumptech.glide.load.model.UriLoader;
import com.bumptech.glide.load.model.UrlUriLoader;
import com.bumptech.glide.load.model.stream.HttpGlideUrlLoader;
import com.bumptech.glide.load.model.stream.HttpUriLoader;
import com.bumptech.glide.load.model.stream.MediaStoreImageThumbLoader;
import com.bumptech.glide.load.model.stream.MediaStoreVideoThumbLoader;
import com.bumptech.glide.load.model.stream.UrlLoader;
import com.bumptech.glide.load.resource.bitmap.BitmapDrawableDecoder;
import com.bumptech.glide.load.resource.bitmap.BitmapDrawableEncoder;
import com.bumptech.glide.load.resource.bitmap.BitmapEncoder;
import com.bumptech.glide.load.resource.bitmap.ByteBufferBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser;
import com.bumptech.glide.load.resource.bitmap.Downsampler;
import com.bumptech.glide.load.resource.bitmap.ResourceBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.UnitBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.VideoDecoder;
import com.bumptech.glide.load.resource.bytes.ByteBufferRewinder;
import com.bumptech.glide.load.resource.drawable.ResourceDrawableDecoder;
import com.bumptech.glide.load.resource.drawable.UnitDrawableDecoder;
import com.bumptech.glide.load.resource.file.FileDecoder;
import com.bumptech.glide.load.resource.gif.ByteBufferGifDecoder;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.load.resource.gif.GifDrawableEncoder;
import com.bumptech.glide.load.resource.gif.GifFrameResourceDecoder;
import com.bumptech.glide.load.resource.gif.StreamGifDecoder;
import com.bumptech.glide.load.resource.transcode.BitmapBytesTranscoder;
import com.bumptech.glide.load.resource.transcode.BitmapDrawableTranscoder;
import com.bumptech.glide.load.resource.transcode.DrawableBytesTranscoder;
import com.bumptech.glide.load.resource.transcode.GifDrawableBytesTranscoder;
import com.bumptech.glide.manager.ConnectivityMonitorFactory;
import com.bumptech.glide.manager.RequestManagerRetriever;
import com.bumptech.glide.module.GlideModule;
import com.bumptech.glide.module.ManifestParser;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.ImageViewTargetFactory;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Preconditions;
import com.bumptech.glide.util.Util;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/* loaded from: classes.dex */
public class Glide implements ComponentCallbacks2 {
private static volatile Glide j;
private static volatile boolean k;
private final Engine a;
private final BitmapPool b;
private final MemoryCache c;
private final GlideContext d;
private final Registry e;
private final ArrayPool f;
private final RequestManagerRetriever g;
private final ConnectivityMonitorFactory h;
private final List<RequestManager> i = new ArrayList();
Glide(Context context, Engine engine, MemoryCache memoryCache, BitmapPool bitmapPool, ArrayPool arrayPool, RequestManagerRetriever requestManagerRetriever, ConnectivityMonitorFactory connectivityMonitorFactory, int i, RequestOptions requestOptions, Map<Class<?>, TransitionOptions<?, ?>> map) {
MemoryCategory memoryCategory = MemoryCategory.NORMAL;
this.a = engine;
this.b = bitmapPool;
this.f = arrayPool;
this.c = memoryCache;
this.g = requestManagerRetriever;
this.h = connectivityMonitorFactory;
new BitmapPreFiller(memoryCache, bitmapPool, (DecodeFormat) requestOptions.p().a(Downsampler.f));
Resources resources = context.getResources();
this.e = new Registry();
this.e.a((ImageHeaderParser) new DefaultImageHeaderParser());
Downsampler downsampler = new Downsampler(this.e.a(), resources.getDisplayMetrics(), bitmapPool, arrayPool);
ByteBufferGifDecoder byteBufferGifDecoder = new ByteBufferGifDecoder(context, this.e.a(), bitmapPool, arrayPool);
ResourceDecoder<ParcelFileDescriptor, Bitmap> b = VideoDecoder.b(bitmapPool);
ByteBufferBitmapDecoder byteBufferBitmapDecoder = new ByteBufferBitmapDecoder(downsampler);
StreamBitmapDecoder streamBitmapDecoder = new StreamBitmapDecoder(downsampler, arrayPool);
ResourceDrawableDecoder resourceDrawableDecoder = new ResourceDrawableDecoder(context);
ResourceLoader.StreamFactory streamFactory = new ResourceLoader.StreamFactory(resources);
ResourceLoader.UriFactory uriFactory = new ResourceLoader.UriFactory(resources);
ResourceLoader.FileDescriptorFactory fileDescriptorFactory = new ResourceLoader.FileDescriptorFactory(resources);
ResourceLoader.AssetFileDescriptorFactory assetFileDescriptorFactory = new ResourceLoader.AssetFileDescriptorFactory(resources);
BitmapEncoder bitmapEncoder = new BitmapEncoder(arrayPool);
BitmapBytesTranscoder bitmapBytesTranscoder = new BitmapBytesTranscoder();
GifDrawableBytesTranscoder gifDrawableBytesTranscoder = new GifDrawableBytesTranscoder();
ContentResolver contentResolver = context.getContentResolver();
Registry registry = this.e;
registry.a(ByteBuffer.class, new ByteBufferEncoder());
registry.a(InputStream.class, new StreamEncoder(arrayPool));
registry.a("Bitmap", ByteBuffer.class, Bitmap.class, byteBufferBitmapDecoder);
registry.a("Bitmap", InputStream.class, Bitmap.class, streamBitmapDecoder);
registry.a("Bitmap", ParcelFileDescriptor.class, Bitmap.class, b);
registry.a("Bitmap", AssetFileDescriptor.class, Bitmap.class, VideoDecoder.a(bitmapPool));
registry.a(Bitmap.class, Bitmap.class, UnitModelLoader.Factory.b());
registry.a("Bitmap", Bitmap.class, Bitmap.class, new UnitBitmapDecoder());
registry.a(Bitmap.class, (ResourceEncoder) bitmapEncoder);
registry.a("BitmapDrawable", ByteBuffer.class, BitmapDrawable.class, new BitmapDrawableDecoder(resources, byteBufferBitmapDecoder));
registry.a("BitmapDrawable", InputStream.class, BitmapDrawable.class, new BitmapDrawableDecoder(resources, streamBitmapDecoder));
registry.a("BitmapDrawable", ParcelFileDescriptor.class, BitmapDrawable.class, new BitmapDrawableDecoder(resources, b));
registry.a(BitmapDrawable.class, (ResourceEncoder) new BitmapDrawableEncoder(bitmapPool, bitmapEncoder));
registry.a("Gif", InputStream.class, GifDrawable.class, new StreamGifDecoder(this.e.a(), byteBufferGifDecoder, arrayPool));
registry.a("Gif", ByteBuffer.class, GifDrawable.class, byteBufferGifDecoder);
registry.a(GifDrawable.class, (ResourceEncoder) new GifDrawableEncoder());
registry.a(GifDecoder.class, GifDecoder.class, UnitModelLoader.Factory.b());
registry.a("Bitmap", GifDecoder.class, Bitmap.class, new GifFrameResourceDecoder(bitmapPool));
registry.a(Uri.class, Drawable.class, resourceDrawableDecoder);
registry.a(Uri.class, Bitmap.class, new ResourceBitmapDecoder(resourceDrawableDecoder, bitmapPool));
registry.a((DataRewinder.Factory<?>) new ByteBufferRewinder.Factory());
registry.a(File.class, ByteBuffer.class, new ByteBufferFileLoader.Factory());
registry.a(File.class, InputStream.class, new FileLoader.StreamFactory());
registry.a(File.class, File.class, new FileDecoder());
registry.a(File.class, ParcelFileDescriptor.class, new FileLoader.FileDescriptorFactory());
registry.a(File.class, File.class, UnitModelLoader.Factory.b());
registry.a((DataRewinder.Factory<?>) new InputStreamRewinder.Factory(arrayPool));
registry.a(Integer.TYPE, InputStream.class, streamFactory);
registry.a(Integer.TYPE, ParcelFileDescriptor.class, fileDescriptorFactory);
registry.a(Integer.class, InputStream.class, streamFactory);
registry.a(Integer.class, ParcelFileDescriptor.class, fileDescriptorFactory);
registry.a(Integer.class, Uri.class, uriFactory);
registry.a(Integer.TYPE, AssetFileDescriptor.class, assetFileDescriptorFactory);
registry.a(Integer.class, AssetFileDescriptor.class, assetFileDescriptorFactory);
registry.a(Integer.TYPE, Uri.class, uriFactory);
registry.a(String.class, InputStream.class, new DataUrlLoader.StreamFactory());
registry.a(Uri.class, InputStream.class, new DataUrlLoader.StreamFactory());
registry.a(String.class, InputStream.class, new StringLoader.StreamFactory());
registry.a(String.class, ParcelFileDescriptor.class, new StringLoader.FileDescriptorFactory());
registry.a(String.class, AssetFileDescriptor.class, new StringLoader.AssetFileDescriptorFactory());
registry.a(Uri.class, InputStream.class, new HttpUriLoader.Factory());
registry.a(Uri.class, InputStream.class, new AssetUriLoader.StreamFactory(context.getAssets()));
registry.a(Uri.class, ParcelFileDescriptor.class, new AssetUriLoader.FileDescriptorFactory(context.getAssets()));
registry.a(Uri.class, InputStream.class, new MediaStoreImageThumbLoader.Factory(context));
registry.a(Uri.class, InputStream.class, new MediaStoreVideoThumbLoader.Factory(context));
registry.a(Uri.class, InputStream.class, new UriLoader.StreamFactory(contentResolver));
registry.a(Uri.class, ParcelFileDescriptor.class, new UriLoader.FileDescriptorFactory(contentResolver));
registry.a(Uri.class, AssetFileDescriptor.class, new UriLoader.AssetFileDescriptorFactory(contentResolver));
registry.a(Uri.class, InputStream.class, new UrlUriLoader.StreamFactory());
registry.a(URL.class, InputStream.class, new UrlLoader.StreamFactory());
registry.a(Uri.class, File.class, new MediaStoreFileLoader.Factory(context));
registry.a(GlideUrl.class, InputStream.class, new HttpGlideUrlLoader.Factory());
registry.a(byte[].class, ByteBuffer.class, new ByteArrayLoader.ByteBufferFactory());
registry.a(byte[].class, InputStream.class, new ByteArrayLoader.StreamFactory());
registry.a(Uri.class, Uri.class, UnitModelLoader.Factory.b());
registry.a(Drawable.class, Drawable.class, UnitModelLoader.Factory.b());
registry.a(Drawable.class, Drawable.class, new UnitDrawableDecoder());
registry.a(Bitmap.class, BitmapDrawable.class, new BitmapDrawableTranscoder(resources));
registry.a(Bitmap.class, byte[].class, bitmapBytesTranscoder);
registry.a(Drawable.class, byte[].class, new DrawableBytesTranscoder(bitmapPool, bitmapBytesTranscoder, gifDrawableBytesTranscoder));
registry.a(GifDrawable.class, byte[].class, gifDrawableBytesTranscoder);
this.d = new GlideContext(context, arrayPool, this.e, new ImageViewTargetFactory(), requestOptions, map, engine, i);
}
private static void a(Context context) {
if (k) {
throw new IllegalStateException("You cannot call Glide.get() in registerComponents(), use the provided Glide instance instead");
}
k = true;
d(context);
k = false;
}
public static Glide b(Context context) {
if (j == null) {
synchronized (Glide.class) {
if (j == null) {
a(context);
}
}
}
return j;
}
private static void d(Context context) {
a(context, new GlideBuilder());
}
private static GeneratedAppGlideModule j() {
try {
return (GeneratedAppGlideModule) Class.forName("com.bumptech.glide.GeneratedAppGlideModuleImpl").getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
} catch (ClassNotFoundException unused) {
if (Log.isLoggable("Glide", 5)) {
Log.w("Glide", "Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored");
}
return null;
} catch (IllegalAccessException e) {
a(e);
throw null;
} catch (InstantiationException e2) {
a(e2);
throw null;
} catch (NoSuchMethodException e3) {
a(e3);
throw null;
} catch (InvocationTargetException e4) {
a(e4);
throw null;
}
}
public ArrayPool c() {
return this.f;
}
ConnectivityMonitorFactory e() {
return this.h;
}
public Context f() {
return this.d.getBaseContext();
}
GlideContext g() {
return this.d;
}
public Registry h() {
return this.e;
}
public RequestManagerRetriever i() {
return this.g;
}
@Override // android.content.ComponentCallbacks
public void onConfigurationChanged(Configuration configuration) {
}
@Override // android.content.ComponentCallbacks
public void onLowMemory() {
b();
}
@Override // android.content.ComponentCallbacks2
public void onTrimMemory(int i) {
a(i);
}
private static RequestManagerRetriever c(Context context) {
Preconditions.a(context, "You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).");
return b(context).i();
}
public static RequestManager e(Context context) {
return c(context).a(context);
}
public BitmapPool d() {
return this.b;
}
private static void a(Context context, GlideBuilder glideBuilder) {
Context applicationContext = context.getApplicationContext();
GeneratedAppGlideModule j2 = j();
List<GlideModule> emptyList = Collections.emptyList();
if (j2 == null || j2.isManifestParsingEnabled()) {
emptyList = new ManifestParser(applicationContext).a();
}
if (j2 != null && !j2.a().isEmpty()) {
Set<Class<?>> a = j2.a();
Iterator<GlideModule> it = emptyList.iterator();
while (it.hasNext()) {
GlideModule next = it.next();
if (a.contains(next.getClass())) {
if (Log.isLoggable("Glide", 3)) {
Log.d("Glide", "AppGlideModule excludes manifest GlideModule: " + next);
}
it.remove();
}
}
}
if (Log.isLoggable("Glide", 3)) {
Iterator<GlideModule> it2 = emptyList.iterator();
while (it2.hasNext()) {
Log.d("Glide", "Discovered GlideModule from manifest: " + it2.next().getClass());
}
}
glideBuilder.a(j2 != null ? j2.b() : null);
Iterator<GlideModule> it3 = emptyList.iterator();
while (it3.hasNext()) {
it3.next().applyOptions(applicationContext, glideBuilder);
}
if (j2 != null) {
j2.applyOptions(applicationContext, glideBuilder);
}
Glide a2 = glideBuilder.a(applicationContext);
Iterator<GlideModule> it4 = emptyList.iterator();
while (it4.hasNext()) {
it4.next().registerComponents(applicationContext, a2, a2.e);
}
if (j2 != null) {
j2.registerComponents(applicationContext, a2, a2.e);
}
applicationContext.registerComponentCallbacks(a2);
j = a2;
}
public void b() {
Util.b();
this.c.a();
this.b.a();
this.f.a();
}
void b(RequestManager requestManager) {
synchronized (this.i) {
if (this.i.contains(requestManager)) {
this.i.remove(requestManager);
} else {
throw new IllegalStateException("Cannot unregister not yet registered manager");
}
}
}
private static void a(Exception exc) {
throw new IllegalStateException("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", exc);
}
public void a(int i) {
Util.b();
this.c.a(i);
this.b.a(i);
this.f.a(i);
}
public void a() {
Util.a();
this.a.a();
}
public static RequestManager a(Activity activity) {
return c(activity).a(activity);
}
public static RequestManager a(FragmentActivity fragmentActivity) {
return c(fragmentActivity).a(fragmentActivity);
}
public static RequestManager a(Fragment fragment) {
return c(fragment.getActivity()).a(fragment);
}
public static RequestManager a(View view) {
return c(view.getContext()).a(view);
}
boolean a(Target<?> target) {
synchronized (this.i) {
Iterator<RequestManager> it = this.i.iterator();
while (it.hasNext()) {
if (it.next().b(target)) {
return true;
}
}
return false;
}
}
void a(RequestManager requestManager) {
synchronized (this.i) {
if (!this.i.contains(requestManager)) {
this.i.add(requestManager);
} else {
throw new IllegalStateException("Cannot register already registered manager");
}
}
}
}