com.bumptech.glide.Registry.append()方法的使用及代码示例

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

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

Registry.append介绍

[英]Appends the given Encoder onto the list of available Encoders so that it is attempted after all earlier and default Encoders for the given data class.

The Encoder will be used both for the exact data class and any subtypes. For example, registering an Encoder for java.io.InputStream will result in the Encoder being used for android.content.res.AssetFileDescriptor.AutoCloseInputStream, java.io.FileInputStream and any other subclass.

If multiple Encoders are registered for the same type or super type, the Encoder that is registered first will be used.
[中]将给定的编码器追加到可用编码器列表中,以便在给定数据类的所有早期和默认编码器之后尝试。
编码器将用于精确的数据类和任何子类型。例如,为java注册编码器。伊奥。InputStream将导致编码器用于android。所容纳之物res.AssetFileDescriptor。自动关闭输入流,java。伊奥。FileInputStream和任何其他子类。
如果为同一类型或超级类型注册了多个编码器,则将使用首先注册的编码器。

代码示例

代码示例来源: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

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

代码示例来源: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

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

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

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

代码示例来源: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

@Test
public void getRegisteredResourceClasses_withOneDataAndResourceClass_noTranscodeClass_isEmpty() {
 registry.append(Model.class, Data.class, modelLoaderFactory);
 registry.append(Data.class, ResourceOne.class, resourceOneDecoder);
 assertThat(getRegisteredResourceClasses()).isEmpty();
}

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

.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,

代码示例来源: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

@Test
public void getRegisteredResourceClasses_withOneDataClass_noResourceClasses_isEmpty() {
 registry.append(Model.class, Data.class, modelLoaderFactory);
 assertThat(getRegisteredResourceClasses()).isEmpty();
}

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

registry.append(Model.class, Data.class, modelLoaderFactory);
registry.append(Data.class, ResourceOne.class, resourceOneDecoder);
registry.append(Data.class, ResourceTwo.class, resourceTwoDecoder);

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

registry.append(Model.class, Data.class, modelLoaderFactory);
registry.append(Data.class, ResourceOne.class, resourceOneDecoder);

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

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

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

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

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

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

代码示例来源:origin: rockon999/LeanbackLauncher

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

代码示例来源:origin: developerHaoz/GlideUtils

/**
 * 为App注册一个自定义的String类型的BaseGlideUrlLoader
 *
 * @param context
 * @param registry
 */
@Override
public void registerComponents(Context context, Registry registry) {
  registry.append(String.class, InputStream.class,new CustomBaseGlideUrlLoader.Factory());
}

代码示例来源:origin: leftcoding/GankLy

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

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

.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))

相关文章