package com.bumptech.glide.load.resource.gifbitmap; import android.graphics.Bitmap; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.resource.gif.GifData; import com.bumptech.glide.load.resource.gif.GifDataTransformation; public class GifBitmapWrapperTransformation implements Transformation { private Transformation bitmapTransformation; private Transformation gifDataTransformation; public GifBitmapWrapperTransformation(Transformation bitmapTransformation) { this(bitmapTransformation, new GifDataTransformation(bitmapTransformation)); } 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 (transformed != bitmapResource) { 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 (transformed != gifResource) { GifBitmapWrapper gifBitmap = new GifBitmapWrapper(resource.get().getBitmapResource(), transformed); return new GifBitmapWrapperResource(gifBitmap); } } return resource; } @Override public String getId() { return bitmapTransformation.getId(); } }