Glide Deep Learning
Glide.with(this).load("").into(xxx);
with: Get requestManager.Divided into application and non-application, the former returns the requestManager bound to the application, and the latter adds a hidden fragment to the current activity (glide cannot get the activity life cycle, so starting from the fragment, their cycles are synchronized, and the activity is destroyed. After that, the fragment can be monitored, so that glide can capture it and stop loading the picture)
load: Returns DrawableTypeRequest.
return (DrawableTypeRequest) fromString().load(string); loadGeneric in fromString, create a new DrawableTypeRequest, and pass the parameters in the past, so that the load method is called after the DrawableTypeRequest is obtained. The load method is in the parent class GenericRequestBuilder, which contains a large number of glide apis, The builder pattern builds the api. (DrawableTypeRequest is a subclass of GenericRequestBuilder)
into: Make a network request and transcode
into(glide.buildImageViewTarget(view, transcodeClass)); In parentheses, the target view obtained is roughly divided into two types: static image and dynamic image, and then enters the into method. In the into method, the transformation is performed without looking, and the request object is obtained to run and then begin, call the load in the onSizeReady method, and enter the EngineRunnable thread to view decode(), which is divided into decodeFromCache and decodeFromSource, without the cache, enter the decodeFromSource() of DecodeJob, fetcher.loadData() calls the network request in HttpUrlFetcher, and returns It is InputStream, and finally returns to decodeFromSourceData in Decodejob and then transcodes to return Resource, EngineRunnable executes onLoadComplete->onResourceReady, and static images call the onResourceReady method in ImageViewTarget to setResource (setResource in BitmapImageViewTarget)
Cache mechanism:
Process: First read from the memory cache, if not, execute the decode of the run method in EngineRunnable, which is divided into decodeFromCache() and decodeFromSource(), decodeFromCache is divided into disk cache read (result), disk original cache image (source) , if the disk cache is not used, decodeFromSource reads the image from the network, and then decodeFromSourceData writes it to the original disk cache. After the end, transformEncodeAndTranscode(decoded) caches the transcoded image, and finally calls back onLoadComplete after the image is loaded to execute the memory cache write. enter. There are many key generation conditions, id, width, height, etc. have an impact.
Memory cache:
Read: loadFromCache (LruCache) will be obtained from memory before obtaining network pictures. If it is empty, continue down loadFromActiveResources (weak reference), otherwise directly onResourceReady (two kinds of memory caches are used together to prevent pictures in use in Lruche from being recycled. ) Write: (weak reference) After the image is loaded, onLoadComplete sends a message that the handler is MSG_COMPLETE to indicate that the loading is complete, then handleResultOnMainThread is executed, and the activeResources.put method is executed in onEngineJobComplete
(LruCache) engineResource.acquire() times +1, release-1, when the acquired variable is greater than 0, it means that the image is in use, and it should be placed in the activeResources weak reference cache. After release(), if the acquired variable is equal to 0, indicating that the picture is no longer used, then the listener's onResourceReleased() method will be called to release the resource activeResources.remove(cacheKey) to remove it from the weak reference, Then cache.put(cacheKey, resource) is added to LruCache, which realizes the function of using weak reference to cache images in use, and using LruCache to cache images not in use.
Transformations: https://github.com/wasabeef/glide-transformations
Customization: 1. Configuration (meta configuration in AndroidManifest, initialization information will be configured before glide is created)
public class MyGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
builder.setDiskCache(new ExternalCacheDiskCacheFactory(context));
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
@Override
public void registerComponents(Context context, Glide glide) {
}
}
2. Component okhttp: HttpUrlFetcher is replaced by OkHttpFetcher public class MyGlideModule implements GlideModule {
...
@Override
public void registerComponents(Context context, Glide glide) {
glide.register(GlideUrl.class, InputStream.class, new OkHttpGlideUrlLoader.Factory());
}
}
3. Progress barpublic class MyGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
}
@Override
public void registerComponents(Context context, Glide glide) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new ProgressInterceptor());
OkHttpClient okHttpClient = builder.build();
glide.register(GlideUrl.class, InputStream.class, new OkHttpGlideUrlLoader.Factory(okHttpClient));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.