1 package com.bumptech.glide.load.resource.gifbitmap; 2 3 import android.graphics.Bitmap; 4 5 import com.bumptech.glide.load.Transformation; 6 import com.bumptech.glide.load.engine.Resource; 7 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 8 import com.bumptech.glide.load.resource.gif.GifDrawable; 9 import com.bumptech.glide.load.resource.gif.GifDrawableTransformation; 10 11 /** 12 * A {@link com.bumptech.glide.load.Transformation} that can apply a wrapped {@link android.graphics.Bitmap} 13 * transformation to both {@link android.graphics.Bitmap}s and {@link com.bumptech.glide.load.resource.gif.GifDrawable}. 14 */ 15 public class GifBitmapWrapperTransformation implements Transformation<GifBitmapWrapper> { 16 private final Transformation<Bitmap> bitmapTransformation; 17 private final Transformation<GifDrawable> gifDataTransformation; 18 19 public GifBitmapWrapperTransformation(BitmapPool bitmapPool, Transformation<Bitmap> bitmapTransformation) { 20 this(bitmapTransformation, new GifDrawableTransformation(bitmapTransformation, bitmapPool)); 21 } 22 23 GifBitmapWrapperTransformation(Transformation<Bitmap> bitmapTransformation, 24 Transformation<GifDrawable> gifDataTransformation) { 25 this.bitmapTransformation = bitmapTransformation; 26 this.gifDataTransformation = gifDataTransformation; 27 } 28 29 @Override 30 public Resource<GifBitmapWrapper> transform(Resource<GifBitmapWrapper> resource, int outWidth, int outHeight) { 31 Resource<Bitmap> bitmapResource = resource.get().getBitmapResource(); 32 Resource<GifDrawable> gifResource = resource.get().getGifResource(); 33 if (bitmapResource != null && bitmapTransformation != null) { 34 Resource<Bitmap> transformed = bitmapTransformation.transform(bitmapResource, outWidth, outHeight); 35 if (!bitmapResource.equals(transformed)) { 36 GifBitmapWrapper gifBitmap = new GifBitmapWrapper(transformed, resource.get().getGifResource()); 37 return new GifBitmapWrapperResource(gifBitmap); 38 } 39 } else if (gifResource != null && gifDataTransformation != null) { 40 Resource<GifDrawable> transformed = gifDataTransformation.transform(gifResource, outWidth, outHeight); 41 if (!gifResource.equals(transformed)) { 42 GifBitmapWrapper gifBitmap = new GifBitmapWrapper(resource.get().getBitmapResource(), transformed); 43 return new GifBitmapWrapperResource(gifBitmap); 44 } 45 } 46 return resource; 47 } 48 49 @Override 50 public String getId() { 51 return bitmapTransformation.getId(); 52 } 53 } 54