com.bumptech.glide.Registry类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中com.bumptech.glide.Registry类的一些代码示例,展示了Registry类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry类的具体详情如下:
包路径:com.bumptech.glide.Registry
类名称:Registry

Registry介绍

[英]Manages component registration to extend or replace Glide's default loading, decoding, and encoding logic.
[中]管理组件注册以扩展或替换Glide的默认加载、解码和编码逻辑。

代码示例

代码示例来源:origin: bumptech/glide

@Override
 public void registerComponents(Context context, Glide glide, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
 }
}

代码示例来源:origin: bumptech/glide

@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
  @NonNull Registry registry) {
 registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory());
}

代码示例来源:origin: bumptech/glide

/**
 * Prepends the given {@link ResourceDecoder} into the list of all available
 * {@link ResourceDecoder}s so that it is attempted before all later and default
 * {@link ResourceDecoder}s for the given types.
 *
 * <p>This method allows you to replace the default {@link ResourceDecoder} because it ensures
 * the registered {@link ResourceDecoder} will run first. You can use the
 * {@link ResourceDecoder#handles(Object, Options)} to fall back to the default
 * {@link ResourceDecoder}s if you only want to change the default functionality for certain
 * types of data.
 *
 * @see #prepend(String, Class, Class, ResourceDecoder)
 * @see #append(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 prepend(
  @NonNull Class<Data> dataClass,
  @NonNull Class<TResource> resourceClass,
  @NonNull ResourceDecoder<Data, TResource> decoder) {
 prepend(BUCKET_PREPEND_ALL, dataClass, resourceClass, decoder);
 return this;
}

代码示例来源:origin: bumptech/glide

@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());
}

代码示例来源:origin: bumptech/glide

Registry registry = new Registry();
registry.append(Model.class, Data.class, modelLoaderFactory);
registry.append(Data.class, ResourceOne.class, resourceOneDecoder);
registry.append(Data.class, ResourceTwo.class, resourceTwoDecoder);
registry.register(ResourceOne.class, TranscodeOne.class, resourceOneTranscodeOneTranscoder);
if (i == 0) {
 resourceOneClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceOne.class, TranscodeOne.class);
 resourceTwoClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceTwo.class, TranscodeOne.class);
} else {
 resourceTwoClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceTwo.class, TranscodeOne.class);
 resourceOneClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceOne.class, TranscodeOne.class);

代码示例来源:origin: bumptech/glide

registry = new Registry();
registry.register(new DefaultImageHeaderParser());
 registry.register(new ExifInterfaceImageHeaderParser());
List<ImageHeaderParser> imageHeaderParsers = registry.getImageHeaderParsers();
Downsampler downsampler =
  new Downsampler(
  .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)

代码示例来源:origin: bumptech/glide

private List<Class<?>> getRegisteredResourceClasses() {
 return registry.getRegisteredResourceClasses(
   Model.class, ResourceOne.class, TranscodeOne.class);
}

代码示例来源:origin: bumptech/glide

@Before
public void setUp() {
 MockitoAnnotations.initMocks(this);
 registry = new Registry();
}

代码示例来源:origin: bumptech/glide

Registry registry = new Registry();
registry.append(Model.class, Data.class, modelLoaderFactory);
registry.append(Data.class, ResourceOne.class, resourceOneDecoder);
registry.register(ResourceOne.class, TranscodeOne.class, resourceOneTranscodeOneTranscoder);
if (i == 0) {
 transcodeOneClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceOne.class, TranscodeOne.class);
 transcodeTwoClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceOne.class, TranscodeTwo.class);
} else {
 transcodeTwoClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceOne.class, TranscodeTwo.class);
 transcodeOneClasses =
   registry.getRegisteredResourceClasses(
     Model.class, ResourceOne.class, TranscodeOne.class);

代码示例来源:origin: mozilla-tw/Rocket

registry = new Registry();
registry.register(new DefaultImageHeaderParser());
Downsampler downsampler = new Downsampler(registry.getImageHeaderParsers(),
  resources.getDisplayMetrics(), bitmapPool, arrayPool);
  .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()))
  .register(new ByteBufferRewinder.Factory())
  .append(File.class, ByteBuffer.class, new ByteBufferFileLoader.Factory())

代码示例来源:origin: bumptech/glide

@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);
}

代码示例来源:origin: bumptech/glide

List<Class<?>> getRegisteredResourceClasses() {
 return glideContext.getRegistry()
   .getRegisteredResourceClasses(model.getClass(), resourceClass, transcodeClass);
}

代码示例来源:origin: bumptech/glide

@Before
public void setUp() {
 Application app = RuntimeEnvironment.application;
 transitionOptions = new HashMap<>();
 context = new GlideContext(
   app,
   new LruArrayPool(),
   new Registry(),
   new ImageViewTargetFactory(),
   new RequestOptions(),
   transitionOptions,
   /*defaultRequestListeners=*/ Collections.<RequestListener<Object>>emptyList(),
   mock(Engine.class),
   /*isLoggingRequestOriginsEnabled=*/ false,
   Log.DEBUG);
}

代码示例来源:origin: bumptech/glide

@Override
 public void registerComponents(@NonNull Context context, @NonNull Glide glide,
   @NonNull Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
 }
}

代码示例来源:origin: bumptech/glide

@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
  @NonNull Registry registry) {
 registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory());
}

代码示例来源:origin: Piasy/BigImageViewer

@Override
  public void registerComponents(@NonNull Context context, @NonNull Glide glide,
    @NonNull Registry registry) {
    glide.getRegistry().prepend(CustomImageSizeModel.class, InputStream.class, new
      CustomImageSizeUrlLoaderFactory());
  }
}

代码示例来源:origin: mozilla-tw/Rocket

List<Class<?>> getRegisteredResourceClasses() {
 return glideContext.getRegistry()
   .getRegisteredResourceClasses(model.getClass(), resourceClass, transcodeClass);
}

代码示例来源:origin: bumptech/glide

@Override
 public void registerComponents(Context context, Glide glide, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
 }
}

代码示例来源:origin: bumptech/glide

/**
 * 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);
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("unchecked")
private <T> void registerMockStreamModelLoader(final Class<T> modelClass) {
 ModelLoader<T, InputStream> modelLoader = mockStreamModelLoader(modelClass);
 ModelLoaderFactory<T, InputStream> modelLoaderFactory = mock(ModelLoaderFactory.class);
 when(modelLoaderFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(modelLoader);
 Glide.get(context).getRegistry()
   .prepend(modelClass, InputStream.class, modelLoaderFactory);
}

相关文章