1 package com.bumptech.glide.load.resource.gifbitmap; 2 3 import android.graphics.Bitmap; 4 5 import com.bumptech.glide.load.ResourceEncoder; 6 import com.bumptech.glide.load.engine.Resource; 7 import com.bumptech.glide.load.resource.gif.GifDrawable; 8 9 import java.io.OutputStream; 10 11 /** 12 * A {@link com.bumptech.glide.load.ResourceEncoder} that can encode either an {@link Bitmap} or 13 * {@link com.bumptech.glide.load.resource.gif.GifDrawable}. 14 */ 15 public class GifBitmapWrapperResourceEncoder implements ResourceEncoder<GifBitmapWrapper> { 16 private final ResourceEncoder<Bitmap> bitmapEncoder; 17 private final ResourceEncoder<GifDrawable> gifEncoder; 18 private String id; 19 20 public GifBitmapWrapperResourceEncoder(ResourceEncoder<Bitmap> bitmapEncoder, 21 ResourceEncoder<GifDrawable> gifEncoder) { 22 this.bitmapEncoder = bitmapEncoder; 23 this.gifEncoder = gifEncoder; 24 } 25 26 @Override 27 public boolean encode(Resource<GifBitmapWrapper> resource, OutputStream os) { 28 final GifBitmapWrapper gifBitmap = resource.get(); 29 final Resource<Bitmap> bitmapResource = gifBitmap.getBitmapResource(); 30 31 if (bitmapResource != null) { 32 return bitmapEncoder.encode(bitmapResource, os); 33 } else { 34 return gifEncoder.encode(gifBitmap.getGifResource(), os); 35 } 36 } 37 38 @Override 39 public String getId() { 40 if (id == null) { 41 id = bitmapEncoder.getId() + gifEncoder.getId(); 42 } 43 return id; 44 } 45 } 46