Home | History | Annotate | Download | only in gifbitmap
      1 package com.bumptech.glide.load.resource.gifbitmap;
      2 
      3 import android.graphics.Bitmap;
      4 
      5 import com.bumptech.glide.load.Encoder;
      6 import com.bumptech.glide.load.ResourceDecoder;
      7 import com.bumptech.glide.load.ResourceEncoder;
      8 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
      9 import com.bumptech.glide.load.model.ImageVideoWrapper;
     10 import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
     11 import com.bumptech.glide.load.resource.gif.GifDrawable;
     12 import com.bumptech.glide.provider.DataLoadProvider;
     13 
     14 import java.io.File;
     15 import java.io.InputStream;
     16 
     17 /**
     18  * An {@link com.bumptech.glide.provider.DataLoadProvider} that can load either an
     19  * {@link com.bumptech.glide.load.resource.gif.GifDrawable} or an {@link Bitmap} from either an
     20  * {@link java.io.InputStream} or an {@link android.os.ParcelFileDescriptor}.
     21  */
     22 public class ImageVideoGifDrawableLoadProvider implements DataLoadProvider<ImageVideoWrapper, GifBitmapWrapper> {
     23     private final ResourceDecoder<File, GifBitmapWrapper> cacheDecoder;
     24     private final ResourceDecoder<ImageVideoWrapper, GifBitmapWrapper> sourceDecoder;
     25     private final ResourceEncoder<GifBitmapWrapper> encoder;
     26     private final Encoder<ImageVideoWrapper> sourceEncoder;
     27 
     28     public ImageVideoGifDrawableLoadProvider(DataLoadProvider<ImageVideoWrapper, Bitmap> bitmapProvider,
     29             DataLoadProvider<InputStream, GifDrawable> gifProvider, BitmapPool bitmapPool) {
     30 
     31         final GifBitmapWrapperResourceDecoder decoder = new GifBitmapWrapperResourceDecoder(
     32                 bitmapProvider.getSourceDecoder(),
     33                 gifProvider.getSourceDecoder(),
     34                 bitmapPool
     35         );
     36         cacheDecoder = new FileToStreamDecoder<GifBitmapWrapper>(new GifBitmapWrapperStreamResourceDecoder(decoder));
     37         sourceDecoder = decoder;
     38         encoder = new GifBitmapWrapperResourceEncoder(bitmapProvider.getEncoder(), gifProvider.getEncoder());
     39 
     40         //TODO: what about the gif provider?
     41         sourceEncoder = bitmapProvider.getSourceEncoder();
     42     }
     43 
     44     @Override
     45     public ResourceDecoder<File, GifBitmapWrapper> getCacheDecoder() {
     46         return cacheDecoder;
     47     }
     48 
     49     @Override
     50     public ResourceDecoder<ImageVideoWrapper, GifBitmapWrapper> getSourceDecoder() {
     51         return sourceDecoder;
     52     }
     53 
     54     @Override
     55     public Encoder<ImageVideoWrapper> getSourceEncoder() {
     56         return sourceEncoder;
     57     }
     58 
     59     @Override
     60     public ResourceEncoder<GifBitmapWrapper> getEncoder() {
     61         return encoder;
     62     }
     63 }
     64