RequestManagerRetriever
RequestManager
FragmentManager fm = activity.getSupportFragmentManager();
FragmentManager fm = fragment.getChildFragmentManager();
fm.beginTransaction.add()
ModelLoader<T, InputStream> streamModelLoader = Glide.buildStreamModelLoader(modelClass, context); ModelLoader<T, ParcelFileDescriptor> fileDescriptorModelLoader = Glide.buildFileDescriptorModelLoader(modelClass, context); ModelLoader<Model = URL ,Data >
ModelLoader<T,InputStream> ParcelFileDescriptor buildStreamModelLoader buildFileDescriptorModelLoader
placeholder error diskCacheStrategy override
DrawableTypeRequest
into
return into(glide.buildImageViewTarget(view, transcodeClass));
<R> Target<R> buildImageViewTarget(ImageView imageView, Class<R> transcodedClass) { return imageViewTargetFactory.buildTarget(imageView, transcodedClass); }
BitmapImageViewTarget
GlideDrawableImageViewTarget
Request request = buildRequest(target); target.setRequest(request);
obtainRequest
buildRequestRecursive
GenericRequest obtain
placeholderId、errorPlaceholder、diskCacheStrategy
ModelLoader<Model = URL ,Data >
@Override public void begin() { startTime = LogTime.getLogTime(); if (model == null) { onException(null); return; } status = Status.WAITING_FOR_SIZE; if (Util.isValidDimensions(overrideWidth, overrideHeight)) { onSizeReady(overrideWidth, overrideHeight); } else { target.getSize(this); } if (!isComplete() && !isFailed() && canNotifyStatusChanged()) { target.onLoadStarted(getPlaceholderDrawable()); } if (Log.isLoggable(TAG, Log.VERBOSE)) { logV("finished run method in " + LogTime.getElapsedMillis(startTime)); } }
onSizeReady overrideWidth overrideHeight
private final ModelLoader<ModelType, InputStream> streamModelLoader; private final ModelLoader<ModelType, ParcelFileDescriptor> fileDescriptorModelLoader; private final RequestManager.OptionsApplier optionsApplier;
ModelLoader<ModelType,InputStream> streamDecoder ParcelFileDescriptor
buildProvider(glide, streamModelLoader, fileDescriptorModelLoader, GifBitmapWrapper.class, GlideDrawable.class, null), glide, requestTracker, lifecycle);
public interface ModelLoader<T, Y> {
DataFetcher<Y> getResourceFetcher(T model, int width, int height);
DataFetcher<InputStream> streamFetcher = null; if (streamLoader != null) { streamFetcher = streamLoader.getResourceFetcher(model, width, height); } DataFetcher<ParcelFileDescriptor> fileDescriptorFetcher = null; if (fileDescriptorLoader != null) { fileDescriptorFetcher = fileDescriptorLoader.getResourceFetcher(model, width, height); }
DataFetcher<InputStream> streamLoader.getResourceFetcher
public class HttpUrlFetcher implements DataFetcher<InputStream> {
HttpUrlFetcher
loadStatus = engine.load(signature, width, height, dataFetcher, loadProvider, transformation, transcoder, priority, isMemoryCacheable, diskCacheStrategy, this);
DiskCacheStrategy diskCacheStrategy ResourceCallback cb
EngineResource<?> cached = loadFromCache(key, isMemoryCacheable)
cb.onResourceReady(cached);
EngineResource<?> active = loadFromActiveResources(key, isMemoryCacheable); if (active != null) {
cb.onResourceReady(active);
EngineJob current = jobs.get(key); if (current != null) { current.addCallback(cb);
EngineJob engineJob = engineJobFactory.build(key, isMemoryCacheable); DecodeJob<T, Z, R> decodeJob = new DecodeJob<T, Z, R>(key, width, height, fetcher, loadProvider, transformation, transcoder, diskCacheProvider, diskCacheStrategy, priority); EngineRunnable runnable = new EngineRunnable(engineJob, decodeJob, priority); jobs.put(key, engineJob); engineJob.addCallback(cb); engineJob.start(runnable);
final EngineResource result;
private final MemoryCache cache; private final EngineJobFactory engineJobFactory; private final Map<Key, WeakReference<EngineResource<?>>> activeResources;
WeakReference<EngineResource<?>> act iveResources;
MemoryCache cache; private final Map<Key, EngineJob> jobs; Key ,EngineJob jobs; private final ExecutorService diskCacheService; private final ExecutorService sourceService; ExecutorService diskCacheService sourceService private Set<ResourceCallback> ignoredCallbacks; private EngineRunnable engineRunnable; private EngineResource<?> engineResource; DecodeJob decodeFromSource decodeSource final A data = fetcher.loadData(priority); public ImageVideoWrapper loadData(Priority priority) throws Exception { InputStream is = streamFetcher.loadData(priority); HttpUrlFetcher = streamFetcher fileDescriptor = fileDescriptorFetcher.loadData(priority); return loadDataWithRedirects(glideUrl.toURL(), 0 /*redirects*/, null /*lastUrl*/, glideUrl.getHeaders()); ResourceDecoder resourceDecoder Resource<Z> decode(T source, int width, int height) throws IOException; public class GifBitmapWrapperStreamResourceDecoder implements ResourceDecoder<InputStream, GifBitmapWrapper> { public GifBitmapWrapper(Resource<Bitmap> bitmapResource, Resource<GifDrawable> gifResource) { GifBitmapWrapperStreamResourceDecoder ResourceDecoder GifBitmapWrapper 就调用decodeGifWrapper()方法来进行解码,如果是普通的静图就用调用decodeBitmapWrapper()方法来进行解码 public class ImageVideoBitmapDecoder implements ResourceDecoder<ImageVideoWrapper, Bitmap> { public class BitmapResource implements Resource<Bitmap> { BitmapResource public class StreamBitmapDecoder implements ResourceDecoder<InputStream, Bitmap> { public Resource<GlideDrawable> transcode(Resource<GifBitmapWrapper> toTranscode) { Resource<Bitmap> bitmapResource = gifBitmap.getBitmapResource @Override public Resource<GlideBitmapDrawable> transcode(Resource<Bitmap> toTranscode) { GlideBitmapDrawable drawable = new GlideBitmapDrawable(resources, toTranscode.get()); return new GlideBitmapDrawableResource(drawable, bitmapPool); }
GlideBitmapDrawable Resource<Bitmap> toTranscode
GlideBitmapDrawable
Resource<GlideDrawable>
EngineJob engineJob = engineJobFactory.build(key, isMemoryCacheable); DecodeJob<T, Z, R> decodeJob = new DecodeJob<T, Z, R>(key, width, height, fetcher, loadProvider, transformation, transcoder, diskCacheProvider, diskCacheStrategy, priority); EngineRunnable runnable = new EngineRunnable(engineJob, decodeJob, priority); jobs.put(key, engineJob); engineJob.addCallback(cb); engineJob.start(runnable); EngineJob engineJobFactory.build DecodeJob decodeJob =