@Override public void registerComponents(Context context, Glide glide, Registry registry) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient client = new OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .addInterceptor(loggingInterceptor) .build(); registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); }
@Override public void registerComponents( @NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { // デフォルト実装は何もしないらしい super.registerComponents( context,glide,registry ); // App1を初期化してからOkHttp3Factoryと連動させる App1.Companion.prepare( context.getApplicationContext() ); App1.Companion.registerGlideComponents(context,glide,registry); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { super.registerComponents(context, glide, registry); //Glide默认使用HttpURLConnection做网络请求,在这切换成okhttp请求 registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(RepositoryUtils.INSTANCE.obtainRepositoryComponent(context).okHttpClient())); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.replace( GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory( request -> GlobalApplication.getOkHttpClient().newCall(request) ) ); }
@Override public void registerComponents(Context context, Registry registry) { registry.register(Bitmap.class, PalettizedBitmapDrawable.class, PalettizedBitmapDrawableTranscoder.create(context)); registry.register(Bitmap.class, Palette.class, PaletteBitmapTranscoder.create()); }
@Override public void registerComponents(Context context, Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); }
@Override public void registerComponents(Context context, Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context)); }
@Override public void registerComponents(Context context, Registry registry) { registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder()) .append(InputStream.class, SVG.class, new SvgDecoder()); }
@Override public void registerComponents(Context context, Registry registry) { registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory()); }
@Override public void registerComponents(Context context, Registry registry) { registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory()); }
@Override public void registerComponents(Context context, Registry registry) { // Default empty impl. }
List<ModelLoader<File, ?>> getModelLoaders(File file) throws Registry.NoModelLoaderAvailableException { return glideContext.getRegistry().getModelLoaders(file); }
<X> Encoder<X> getSourceEncoder(X data) throws Registry.NoSourceEncoderAvailableException { return glideContext.getRegistry().getSourceEncoder(data); }
@Override public Resource<Z> onResourceDecoded(Resource<Z> decoded) { Class<Z> resourceSubClass = getResourceClass(decoded); Transformation<Z> appliedTransformation = null; Resource<Z> transformed = decoded; if (dataSource != DataSource.RESOURCE_DISK_CACHE) { appliedTransformation = decodeHelper.getTransformation(resourceSubClass); transformed = appliedTransformation.transform(glideContext, decoded, width, height); } // TODO: Make this the responsibility of the Transformation. if (!decoded.equals(transformed)) { decoded.recycle(); } final EncodeStrategy encodeStrategy; final ResourceEncoder<Z> encoder; if (decodeHelper.isResourceEncoderAvailable(transformed)) { encoder = decodeHelper.getResultEncoder(transformed); encodeStrategy = encoder.getEncodeStrategy(options); } else { encoder = null; encodeStrategy = EncodeStrategy.NONE; } Resource<Z> result = transformed; boolean isFromAlternateCacheKey = !decodeHelper.isSourceKey(currentSourceKey); if (diskCacheStrategy.isResourceCacheable(isFromAlternateCacheKey, dataSource, encodeStrategy)) { if (encoder == null) { throw new Registry.NoResultEncoderAvailableException(transformed.get().getClass()); } final Key key; if (encodeStrategy == EncodeStrategy.SOURCE) { key = new DataCacheKey(currentSourceKey, signature); } else if (encodeStrategy == EncodeStrategy.TRANSFORMED) { key = new ResourceCacheKey(currentSourceKey, signature, width, height, appliedTransformation, resourceSubClass, options); } else { throw new IllegalArgumentException("Unknown strategy: " + encodeStrategy); } LockedResource<Z> lockedResult = LockedResource.obtain(transformed); deferredEncodeManager.init(key, encoder, lockedResult); result = lockedResult; } return result; }
@Override public void registerComponents(Context context, Registry registry) { }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context)); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder()) .append(InputStream.class, SVG.class, new SvgDecoder()); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory()); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory()); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { // Default empty impl. }
@Override public Resource<Z> onResourceDecoded(Resource<Z> decoded) { Class<Z> resourceSubClass = getResourceClass(decoded); Transformation<Z> appliedTransformation = null; Resource<Z> transformed = decoded; if (dataSource != DataSource.RESOURCE_DISK_CACHE) { appliedTransformation = decodeHelper.getTransformation(resourceSubClass); transformed = appliedTransformation.transform(glideContext, decoded, width, height); } // TODO: Make this the responsibility of the Transformation. if (!decoded.equals(transformed)) { decoded.recycle(); } final EncodeStrategy encodeStrategy; final ResourceEncoder<Z> encoder; if (decodeHelper.isResourceEncoderAvailable(transformed)) { encoder = decodeHelper.getResultEncoder(transformed); encodeStrategy = encoder.getEncodeStrategy(options); } else { encoder = null; encodeStrategy = EncodeStrategy.NONE; } Resource<Z> result = transformed; boolean isFromAlternateCacheKey = !decodeHelper.isSourceKey(currentSourceKey); if (diskCacheStrategy.isResourceCacheable(isFromAlternateCacheKey, dataSource, encodeStrategy)) { if (encoder == null) { throw new Registry.NoResultEncoderAvailableException(transformed.get().getClass()); } final Key key; if (encodeStrategy == EncodeStrategy.SOURCE) { key = new DataCacheKey(currentSourceKey, signature); } else if (encodeStrategy == EncodeStrategy.TRANSFORMED) { key = new ResourceCacheKey( decodeHelper.getArrayPool(), currentSourceKey, signature, width, height, appliedTransformation, resourceSubClass, options); } else { throw new IllegalArgumentException("Unknown strategy: " + encodeStrategy); } LockedResource<Z> lockedResult = LockedResource.obtain(transformed); deferredEncodeManager.init(key, encoder, lockedResult); result = lockedResult; } return result; }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { BaseApplication application = (BaseApplication) context.getApplicationContext(); //Glide 底层默认使用 HttpConnection 进行网络请求,这里替换为 Okhttp 后才能使用本框架,进行 Glide 的加载进度监听 registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(application.getOkHttpClient())); }
@Override public void registerComponents(Context context, Registry registry) { // Default empty impl. registry.append(String.class, InputStream.class, new ArtworkModeLoader.Factory()); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { //Glide 默认使用 HttpURLConnection 做网络请求,在这切换成 Okhttp 请求 AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context); registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient())); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.append(StorageReference.class, InputStream.class, new FirebaseImageLoader.Factory()); }