public class BitmapPoolAdapter extends Object implements BitmapPool
Constructor and Description |
---|
BitmapPoolAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
clearMemory()
Removes all
Bitmap s from the pool. |
Bitmap |
get(int width,
int height,
Bitmap.Config config)
Returns a
Bitmap of exactly the given width, height, and
configuration, and containing only transparent pixels. |
Bitmap |
getDirty(int width,
int height,
Bitmap.Config config)
Identical to
BitmapPool.get(int, int, android.graphics.Bitmap.Config) except that any returned
Bitmap may not have been erased and may contain random data. |
int |
getMaxSize()
Returns the current maximum size of the pool in bytes.
|
void |
put(Bitmap bitmap)
Adds the given
Bitmap if it is eligible to be re-used and the pool
can fit it, or calls Bitmap.recycle() on the Bitmap and discards it. |
void |
setSizeMultiplier(float sizeMultiplier)
Multiplies the initial size of the pool by the given multiplier to dynamically and
synchronously allow users to adjust the size of the pool.
|
void |
trimMemory(int level)
Reduces the size of the cache by evicting items based on the given level.
|
public int getMaxSize()
BitmapPool
getMaxSize
in interface BitmapPool
public void setSizeMultiplier(float sizeMultiplier)
BitmapPool
If the current total size of the pool is larger than the max size after the given
multiplier is applied, Bitmap
s should be evicted until the pool is smaller than the new
max size.
setSizeMultiplier
in interface BitmapPool
sizeMultiplier
- The size multiplier to apply between 0 and 1.public void put(Bitmap bitmap)
BitmapPool
Bitmap
if it is eligible to be re-used and the pool
can fit it, or calls Bitmap.recycle()
on the Bitmap and discards it.
Callers must not continue to use the Bitmap after calling this method.
put
in interface BitmapPool
bitmap
- The Bitmap
to attempt to add.Bitmap.isMutable()
,
Bitmap.recycle()
@NonNull public Bitmap get(int width, int height, Bitmap.Config config)
BitmapPool
Bitmap
of exactly the given width, height, and
configuration, and containing only transparent pixels.
If no Bitmap with the requested attributes is present in the pool, a new one will be allocated.
Because this method erases all pixels in the Bitmap
, this method is slightly slower
than BitmapPool.getDirty(int, int, android.graphics.Bitmap.Config)
. If the Bitmap
is being obtained to be used in BitmapFactory
or in any other case where every pixel in the Bitmap
will always be
overwritten or cleared, BitmapPool.getDirty(int, int, android.graphics.Bitmap.Config)
will be
faster. When in doubt, use this method to ensure correctness.
Implementations can should clear out every returned Bitmap using the following:
bitmap.eraseColor(Color.TRANSPARENT);
get
in interface BitmapPool
width
- The width in pixels of the desired Bitmap
.height
- The height in pixels of the desired Bitmap
.config
- The Bitmap.Config
of the desired Bitmap
.BitmapPool.getDirty(int, int, android.graphics.Bitmap.Config)
@NonNull public Bitmap getDirty(int width, int height, Bitmap.Config config)
BitmapPool
BitmapPool.get(int, int, android.graphics.Bitmap.Config)
except that any returned
Bitmap
may not have been erased and may contain random data.
If no Bitmap with the requested attributes is present in the pool, a new one will be allocated.
Although this method is slightly more efficient than BitmapPool.get(int, int,
android.graphics.Bitmap.Config)
it should be used with caution and only when the caller is
sure that they are going to erase the Bitmap
entirely before writing
new data to it.
getDirty
in interface BitmapPool
width
- The width in pixels of the desired Bitmap
.height
- The height in pixels of the desired Bitmap
.config
- The Bitmap.Config
of the desired Bitmap
.Bitmap
with exactly the given width, height, and config
potentially containing random image data or null if no such Bitmap
could be obtained from the pool.BitmapPool.get(int, int, android.graphics.Bitmap.Config)
public void clearMemory()
BitmapPool
Bitmap
s from the pool.clearMemory
in interface BitmapPool
public void trimMemory(int level)
BitmapPool
trimMemory
in interface BitmapPool
level
- The level from ComponentCallbacks2
to use to determine how
many Bitmap
s to evict.ComponentCallbacks2