1 package com.bumptech.glide.load.resource.gifbitmap; 2 3 import android.graphics.Bitmap; 4 5 import com.bumptech.glide.load.engine.Resource; 6 import com.bumptech.glide.load.resource.gif.GifDrawable; 7 8 /** 9 * A wrapper that contains either an {@link android.graphics.Bitmap} resource or an 10 * {@link com.bumptech.glide.load.resource.gif.GifDrawable} resource. 11 */ 12 public class GifBitmapWrapper { 13 private final Resource<GifDrawable> gifResource; 14 private final Resource<Bitmap> bitmapResource; 15 16 public GifBitmapWrapper(Resource<Bitmap> bitmapResource, Resource<GifDrawable> gifResource) { 17 if (bitmapResource != null && gifResource != null) { 18 throw new IllegalArgumentException("Can only contain either a bitmap resource or a gif resource, not both"); 19 } 20 if (bitmapResource == null && gifResource == null) { 21 throw new IllegalArgumentException("Must contain either a bitmap resource or a gif resource"); 22 } 23 this.bitmapResource = bitmapResource; 24 this.gifResource = gifResource; 25 } 26 27 /** 28 * Returns the size of the wrapped resource. 29 */ 30 public int getSize() { 31 if (bitmapResource != null) { 32 return bitmapResource.getSize(); 33 } else { 34 return gifResource.getSize(); 35 } 36 } 37 38 /** 39 * Returns the wrapped {@link android.graphics.Bitmap} resource if it exists, or null. 40 */ 41 public Resource<Bitmap> getBitmapResource() { 42 return bitmapResource; 43 } 44 45 /** 46 * Returns the wrapped {@link com.bumptech.glide.load.resource.gif.GifDrawable} resource if it exists, or null. 47 */ 48 public Resource<GifDrawable> getGifResource() { 49 return gifResource; 50 } 51 } 52