Home | History | Annotate | Download | only in bitmap
      1 package com.bumptech.glide.load.resource.bitmap;
      2 
      3 import android.graphics.drawable.BitmapDrawable;
      4 
      5 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
      6 import com.bumptech.glide.load.resource.drawable.DrawableResource;
      7 import com.bumptech.glide.util.Util;
      8 
      9 /**
     10  * A {@link com.bumptech.glide.load.engine.Resource} that wraps an {@link android.graphics.drawable.BitmapDrawable}
     11  * <p>
     12  *     This class ensures that every call to {@link #get()}} always returns a new
     13  *     {@link android.graphics.drawable.BitmapDrawable} to avoid rendering issues if used in multiple views and
     14  *     is also responsible for returning the underlying {@link android.graphics.Bitmap} to the given
     15  *     {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool} when the resource is recycled.
     16  * </p>
     17  */
     18 public class BitmapDrawableResource extends DrawableResource<BitmapDrawable> {
     19     private final BitmapPool bitmapPool;
     20 
     21     public BitmapDrawableResource(BitmapDrawable drawable, BitmapPool bitmapPool) {
     22         super(drawable);
     23         this.bitmapPool = bitmapPool;
     24     }
     25 
     26     @Override
     27     public int getSize() {
     28         return Util.getBitmapByteSize(drawable.getBitmap());
     29     }
     30 
     31     @Override
     32     public void recycle() {
     33         bitmapPool.put(drawable.getBitmap());
     34     }
     35 }
     36