@Override public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory()); }
@Override public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory()); }
/** * Registers the given {@link Encoder} for the given data class (InputStream, FileDescriptor etc). * * <p>The {@link Encoder} will be used both for the exact data class and any subtypes. For * example, registering an {@link Encoder} for {@link java.io.InputStream} will result in the * {@link Encoder} being used for * {@link android.content.res.AssetFileDescriptor.AutoCloseInputStream}, * {@link java.io.FileInputStream} and any other subclass. * * <p>If multiple {@link Encoder}s are registered for the same type or super type, the * {@link Encoder} that is registered first will be used. * * @deprecated Use the equivalent {@link #append(Class, Class, ModelLoaderFactory)} method * instead. */ @NonNull @Deprecated public <Data> Registry register(@NonNull Class<Data> dataClass, @NonNull Encoder<Data> encoder) { return append(dataClass, encoder); }
/** * Appends the given {@link ResourceEncoder} into the list of available {@link ResourceEncoder}s * so that it is attempted after all earlier and default {@link ResourceEncoder}s for the given * data type. * * <p>The {@link ResourceEncoder} will be used both for the exact resource class and any subtypes. * For example, registering an {@link ResourceEncoder} for * {@link android.graphics.drawable.Drawable} (not recommended) will result in the * {@link ResourceEncoder} being used for {@link android.graphics.drawable.BitmapDrawable} and * {@link com.bumptech.glide.load.resource.gif.GifDrawable} and any other subclass. * * <p>If multiple {@link ResourceEncoder}s are registered for the same type or super type, the * {@link ResourceEncoder} that is registered first will be used. * * @deprecated Use the equivalent {@link #append(Class, ResourceEncoder)} method instead. */ @NonNull @Deprecated public <TResource> Registry register( @NonNull Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder) { return append(resourceClass, encoder); }
/** * Appends the given {@link ResourceDecoder} onto the list of all available * {@link ResourceDecoder}s allowing it to be used if all earlier and default * {@link ResourceDecoder}s for the given types fail (or there are none). * * <p>If you're attempting to replace an existing {@link ResourceDecoder} or would like to ensure * that your {@link ResourceDecoder} gets the chance to run before an existing * {@link ResourceDecoder}, use {@link #prepend(Class, Class, ResourceDecoder)}. This method is * best for new types of resources and data or as a way to add an additional fallback decoder * for an existing type of data. * * @see #append(String, Class, Class, ResourceDecoder) * @see #prepend(Class, Class, ResourceDecoder) * * @param dataClass The data that will be decoded from * ({@link java.io.InputStream}, {@link java.io.FileDescriptor} etc). * @param resourceClass The resource that will be decoded to ({@link android.graphics.Bitmap}, * {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc). * @param decoder The {@link ResourceDecoder} to register. */ @NonNull public <Data, TResource> Registry append( @NonNull Class<Data> dataClass, @NonNull Class<TResource> resourceClass, @NonNull ResourceDecoder<Data, TResource> decoder) { append(BUCKET_APPEND_ALL, dataClass, resourceClass, decoder); return this; }
@Override public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder()) .append(InputStream.class, SVG.class, new SvgDecoder()); }
.append(ByteBuffer.class, new ByteBufferEncoder()) .append(InputStream.class, new StreamEncoder(arrayPool)) .append(Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, byteBufferBitmapDecoder) .append(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, streamBitmapDecoder) .append( Registry.BUCKET_BITMAP, ParcelFileDescriptor.class, Bitmap.class, parcelFileDescriptorVideoDecoder) .append( Registry.BUCKET_BITMAP, AssetFileDescriptor.class, Bitmap.class, VideoDecoder.asset(bitmapPool)) .append(Bitmap.class, Bitmap.class, UnitModelLoader.Factory.<Bitmap>getInstance()) .append( Registry.BUCKET_BITMAP, Bitmap.class, Bitmap.class, new UnitBitmapDecoder()) .append(Bitmap.class, bitmapEncoder) .append( Registry.BUCKET_BITMAP_DRAWABLE, ByteBuffer.class, BitmapDrawable.class, new BitmapDrawableDecoder<>(resources, byteBufferBitmapDecoder)) .append( Registry.BUCKET_BITMAP_DRAWABLE, InputStream.class, BitmapDrawable.class,
@Test public void getRegisteredResourceClasses_withOneDataAndResourceAndTranscodeClass_isNotEmpty() { registry.append(Model.class, Data.class, modelLoaderFactory); registry.append(Data.class, ResourceOne.class, resourceOneDecoder); registry.register(ResourceOne.class, TranscodeOne.class, resourceOneTranscodeOneTranscoder); assertThat(getRegisteredResourceClasses()).containsExactly(ResourceOne.class); }
@Test public void getRegisteredResourceClasses_withOneDataClass_noResourceClasses_isEmpty() { registry.append(Model.class, Data.class, modelLoaderFactory); assertThat(getRegisteredResourceClasses()).isEmpty(); }
/** * Appends the given {@link ResourceDecoder} onto the list of all available * {@link ResourceDecoder}s allowing it to be used if all earlier and default * {@link ResourceDecoder}s for the given types fail (or there are none). * * <p>If you're attempting to replace an existing {@link ResourceDecoder} or would like to ensure * that your {@link ResourceDecoder} gets the chance to run before an existing * {@link ResourceDecoder}, use {@link #prepend(Class, Class, ResourceDecoder)}. This method is * best for new types of resources and data or as a way to add an additional fallback decoder * for an existing type of data. * * @see #append(String, Class, Class, ResourceDecoder) * @see #prepend(Class, Class, ResourceDecoder) * * @param dataClass The data that will be decoded from * ({@link java.io.InputStream}, {@link java.io.FileDescriptor} etc). * @param resourceClass The resource that will be decoded to ({@link android.graphics.Bitmap}, * {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc). * @param decoder The {@link ResourceDecoder} to register. */ public <Data, TResource> Registry append( Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data, TResource> decoder) { append(BUCKET_APPEND_ALL, dataClass, resourceClass, decoder); return this; }
/** * Registers the given {@link Encoder} for the given data class (InputStream, FileDescriptor etc). * * <p>The {@link Encoder} will be used both for the exact data class and any subtypes. For * example, registering an {@link Encoder} for {@link java.io.InputStream} will result in the * {@link Encoder} being used for * {@link android.content.res.AssetFileDescriptor.AutoCloseInputStream}, * {@link java.io.FileInputStream} and any other subclass. * * <p>If multiple {@link Encoder}s are registered for the same type or super type, the * {@link Encoder} that is registered first will be used. * * @deprecated Use the equivalent {@link #append(Class, Class, ModelLoaderFactory)} method * instead. */ @Deprecated public <Data> Registry register(Class<Data> dataClass, Encoder<Data> encoder) { return append(dataClass, encoder); }
/** * Appends the given {@link ResourceEncoder} into the list of available {@link ResourceEncoder}s * so that it is attempted after all earlier and default {@link ResourceEncoder}s for the given * data type. * * <p>The {@link ResourceEncoder} will be used both for the exact resource class and any subtypes. * For example, registering an {@link ResourceEncoder} for * {@link android.graphics.drawable.Drawable} (not recommended) will result in the * {@link ResourceEncoder} being used for {@link android.graphics.drawable.BitmapDrawable} and * {@link com.bumptech.glide.load.resource.gif.GifDrawable} and any other subclass. * * <p>If multiple {@link ResourceEncoder}s are registered for the same type or super type, the * {@link ResourceEncoder} that is registered first will be used. * * @deprecated Use the equivalent {@link #append(Class, ResourceEncoder)} method instead. */ @Deprecated public <TResource> Registry register( Class<TResource> resourceClass, ResourceEncoder<TResource> encoder) { return append(resourceClass, encoder); }
public void registerComponents(final Context context, Registry registry) { registry.append(RecommendationImageKey.class, Bitmap.class, new RecommendationImageLoaderFactory(context)); registry.append(Bitmap.class, Bitmap.class, new ResourceDecoder<Bitmap, Bitmap>() { private BitmapPool mBitmapPool; public Resource<Bitmap> decode(Bitmap source, int width, int height, Options options) { if (this.mBitmapPool == null) { this.mBitmapPool = Glide.get(context).getBitmapPool(); } return new BitmapResource(source, this.mBitmapPool); } public boolean handles(Bitmap source, Options options) throws IOException { return true; } }); }
/** * 为App注册一个自定义的String类型的BaseGlideUrlLoader * * @param context * @param registry */ @Override public void registerComponents(Context context, Registry registry) { registry.append(String.class, InputStream.class,new CustomBaseGlideUrlLoader.Factory()); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.append(GlideUrl.class, InputStream.class, new WifiOnlyLoader.Factory()); }
.append(ByteBuffer.class, new ByteBufferEncoder()) .append(InputStream.class, new StreamEncoder(arrayPool)) .append(Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, new ByteBufferBitmapDecoder(downsampler)) .append(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, new StreamBitmapDecoder(downsampler, arrayPool)) .append(Registry.BUCKET_BITMAP, ParcelFileDescriptor.class, Bitmap.class, new VideoBitmapDecoder(bitmapPool)) .append(Bitmap.class, new BitmapEncoder()) .append(Registry.BUCKET_BITMAP_DRAWABLE, ByteBuffer.class, BitmapDrawable.class, new BitmapDrawableDecoder<>(resources, bitmapPool, new ByteBufferBitmapDecoder(downsampler))) .append(Registry.BUCKET_BITMAP_DRAWABLE, InputStream.class, BitmapDrawable.class, new BitmapDrawableDecoder<>(resources, bitmapPool, new StreamBitmapDecoder(downsampler, arrayPool))) .append(Registry.BUCKET_BITMAP_DRAWABLE, ParcelFileDescriptor.class, BitmapDrawable.class, new BitmapDrawableDecoder<>(resources, bitmapPool, new VideoBitmapDecoder(bitmapPool))) .append(BitmapDrawable.class, new BitmapDrawableEncoder(bitmapPool, new BitmapEncoder())) .append(File.class, ByteBuffer.class, new ByteBufferFileLoader.Factory()) .append(File.class, InputStream.class, new FileLoader.StreamFactory()) .append(File.class, File.class, new FileDecoder()) .append(File.class, ParcelFileDescriptor.class, new FileLoader.FileDescriptorFactory()) .append(File.class, File.class, new UnitModelLoader.Factory<File>()) .append(int.class, InputStream.class, new ResourceLoader.StreamFactory(resources))