package com.bumptech.glide.load.resource.gifbitmap; import android.graphics.Bitmap; import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.load.resource.gif.GifDrawableTransformation; /** * A {@link com.bumptech.glide.load.Transformation} that can apply a wrapped {@link android.graphics.Bitmap} * transformation to both {@link android.graphics.Bitmap}s and {@link com.bumptech.glide.load.resource.gif.GifDrawable}. */ public class GifBitmapWrapperTransformation implements Transformation { private final Transformation bitmapTransformation; private final Transformation gifDataTransformation; public GifBitmapWrapperTransformation(BitmapPool bitmapPool, Transformation bitmapTransformation) { this(bitmapTransformation, new GifDrawableTransformation(bitmapTransformation, bitmapPool)); } GifBitmapWrapperTransformation(Transformation bitmapTransformation, Transformation gifDataTransformation) { this.bitmapTransformation = bitmapTransformation; this.gifDataTransformation = gifDataTransformation; } @Override public Resource transform(Resource resource, int outWidth, int outHeight) { Resource bitmapResource = resource.get().getBitmapResource(); Resource gifResource = resource.get().getGifResource(); if (bitmapResource != null && bitmapTransformation != null) { Resource transformed = bitmapTransformation.transform(bitmapResource, outWidth, outHeight); if (!bitmapResource.equals(transformed)) { GifBitmapWrapper gifBitmap = new GifBitmapWrapper(transformed, resource.get().getGifResource()); return new GifBitmapWrapperResource(gifBitmap); } } else if (gifResource != null && gifDataTransformation != null) { Resource transformed = gifDataTransformation.transform(gifResource, outWidth, outHeight); if (!gifResource.equals(transformed)) { GifBitmapWrapper gifBitmap = new GifBitmapWrapper(resource.get().getBitmapResource(), transformed); return new GifBitmapWrapperResource(gifBitmap); } } return resource; } @Override public String getId() { return bitmapTransformation.getId(); } }