@Override public Resource<File> decode(@NonNull File source, int width, int height, @NonNull Options options) { return new FileResource(source); } }
@Before public void setUp() { decoder = new FileDecoder(); options = new Options(); }
@Test public void testReturnsGivenFile() { assertEquals(file, resource.get()); } }
public StreamBitmapDataLoadProvider(BitmapPool bitmapPool, DecodeFormat decodeFormat) { sourceEncoder = new StreamEncoder(); decoder = new StreamBitmapDecoder(bitmapPool, decodeFormat); encoder = new BitmapEncoder(); cacheDecoder = new FileToStreamDecoder<Bitmap>(decoder); }
@Test public void testReturnsGivenFileAsResource() throws IOException { File expected = new File("testFile"); Resource<File> decoded = Preconditions.checkNotNull(decoder.decode(expected, 1, 1, options)); assertEquals(expected, decoded.get()); } }
@Override public Resource<T> decode(File source, int width, int height) throws IOException { InputStream is = null; Resource<T> result = null; try { is = fileOpener.open(source); result = streamDecoder.decode(is, width, height); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // Do nothing. } } } return result; }
new ImageVideoGifDrawableLoadProvider(imageVideoDataLoadProvider, gifDrawableLoadProvider, bitmapPool)); dataLoadProviderRegistry.register(InputStream.class, File.class, new StreamFileDataLoadProvider());
@Before public void setUp() { file = new File("Test"); resource = new FileResource(file); }
public StreamFileDataLoadProvider() { cacheDecoder = new FileDecoder(); encoder = new StreamEncoder(); }
public GifDrawableLoadProvider(Context context, BitmapPool bitmapPool) { decoder = new GifResourceDecoder(context, bitmapPool); cacheDecoder = new FileToStreamDecoder<GifDrawable>(decoder); encoder = new GifResourceEncoder(bitmapPool); sourceEncoder = new StreamEncoder(); }
@Override public Resource<File> decode(File source, int width, int height) { return new FileResource(source); }
.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())
public FileDescriptorBitmapDataLoadProvider(BitmapPool bitmapPool, DecodeFormat decodeFormat) { cacheDecoder = new FileToStreamDecoder<Bitmap>(new StreamBitmapDecoder(bitmapPool, decodeFormat)); sourceDecoder = new FileDescriptorBitmapDecoder(bitmapPool, decodeFormat); encoder = new BitmapEncoder(); sourceEncoder = NullEncoder.get(); }
@Override public Resource<File> decode(File source, int width, int height, Options options) { return new FileResource(source); } }
.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())
public ImageVideoGifDrawableLoadProvider(DataLoadProvider<ImageVideoWrapper, Bitmap> bitmapProvider, DataLoadProvider<InputStream, GifDrawable> gifProvider, BitmapPool bitmapPool) { final GifBitmapWrapperResourceDecoder decoder = new GifBitmapWrapperResourceDecoder( bitmapProvider.getSourceDecoder(), gifProvider.getSourceDecoder(), bitmapPool ); cacheDecoder = new FileToStreamDecoder<GifBitmapWrapper>(new GifBitmapWrapperStreamResourceDecoder(decoder)); sourceDecoder = decoder; encoder = new GifBitmapWrapperResourceEncoder(bitmapProvider.getEncoder(), gifProvider.getEncoder()); //TODO: what about the gif provider? sourceEncoder = bitmapProvider.getSourceEncoder(); }
/** * Sets the preferred format for {@link Bitmap}s decoded in this request. Defaults to * {@link DecodeFormat#PREFER_RGB_565}. This replaces any previous calls to {@link #imageDecoder(ResourceDecoder)}, * {@link #videoDecoder(ResourceDecoder)}, {@link #decoder(ResourceDecoder)} and * {@link #cacheDecoder(ResourceDecoder)}} with default decoders with the appropriate * options set. * * <p> * Note - If using a {@link Transformation} that expect bitmaps to support transparency, this should always be * set to ALWAYS_ARGB_8888. RGB_565 requires fewer bytes per pixel and is generally preferable, but it does not * support transparency. * </p> * * @see DecodeFormat * * @param format The format to use. * @return This request builder. */ public BitmapRequestBuilder<ModelType, TranscodeType> format(DecodeFormat format) { this.decodeFormat = format; imageDecoder = new StreamBitmapDecoder(downsampler, bitmapPool, format); videoDecoder = new FileDescriptorBitmapDecoder(new VideoBitmapDecoder(), bitmapPool, format); super.cacheDecoder(new FileToStreamDecoder<Bitmap>(new StreamBitmapDecoder(downsampler, bitmapPool, format))); super.decoder(new ImageVideoBitmapDecoder(imageDecoder, videoDecoder)); return this; }
public static GenericRequestBuilder<String, InputStream, byte[], GifDrawable> gif(Context context) { return Glide .with(context) .using(new StreamStringLoader(context), InputStream.class) .from(String.class) // change this if you have a different model like a File and use StreamFileLoader above .as(byte[].class) .transcode(new GifDrawableByteTranscoder(), GifDrawable.class) // pass it on .diskCacheStrategy(DiskCacheStrategy.SOURCE) // cache original .decoder(new StreamByteArrayResourceDecoder()) // load original .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<byte[]>(new StreamByteArrayResourceDecoder())); } }