public class BitmapCache extends java.lang.Object implements ImageCache
| Modifier and Type | Class and Description |
|---|---|
static class |
BitmapCache.RetainFragment
A simple non-UI Fragment that stores a single Object and is retained over configuration
changes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBitmapToCache(java.lang.String data,
android.graphics.Bitmap bitmap)
Adds a bitmap to both memory and disk cache.
|
static int |
calculateMemCacheSize(float percent)
Sets the memory cache size based on a percentage of the max available VM memory.
|
void |
clear() |
void |
clearCache()
Clears the memory cache.
|
android.graphics.Bitmap |
getBitmap(java.lang.String key) |
android.graphics.Bitmap |
getBitmapFromMemCache(java.lang.String data)
Get from memory cache.
|
static int |
getBitmapSize(android.graphics.Bitmap bitmap)
Get the size in bytes of a bitmap.
|
static BitmapCache |
getInstance(FragmentManager fragmentManger) |
static BitmapCache |
getInstance(FragmentManager fragmentManager,
float memCachePercent) |
static BitmapCache |
getInstance(FragmentManager fragmentManager,
int memCacheSize) |
static BitmapCache |
getInstance(FragmentManager fragmentManager,
java.lang.String fragmentTag,
int memCacheSize)
Find and return an existing BitmapCache stored in a
BitmapCache.RetainFragment, if not found a
new one is created using the supplied params and saved to a BitmapCache.RetainFragment. |
void |
invalidateBitmap(java.lang.String url) |
void |
putBitmap(java.lang.String key,
android.graphics.Bitmap bitmap) |
public static BitmapCache getInstance(FragmentManager fragmentManager, java.lang.String fragmentTag, int memCacheSize)
BitmapCache.RetainFragment, if not found a
new one is created using the supplied params and saved to a BitmapCache.RetainFragment.fragmentManager - The fragment manager to use when dealing with the retained fragment.fragmentTag - The tag of the retained fragment (should be unique for each memory cache
that needs to be retained).memCacheSize - Memory cache size in KB.public static BitmapCache getInstance(FragmentManager fragmentManager, int memCacheSize)
public static BitmapCache getInstance(FragmentManager fragmentManager, float memCachePercent)
public static BitmapCache getInstance(FragmentManager fragmentManger)
public void addBitmapToCache(java.lang.String data,
android.graphics.Bitmap bitmap)
data - Unique identifier for the bitmap to storebitmap - The bitmap to storepublic android.graphics.Bitmap getBitmapFromMemCache(java.lang.String data)
data - Unique identifier for which item to getpublic void clearCache()
public static int calculateMemCacheSize(float percent)
IllegalArgumentException if percent is < 0.05 or > .8.
memCacheSize is stored in kilobytes instead of bytes as this will eventually be passed
to construct a LruCache which takes an int in its constructor.
This value should be chosen carefully based on a number of factors
Refer to the corresponding Android Training class for more discussion:
http://developer.android.com/training/displaying-bitmaps/percent - Percent of memory class to use to size memory cachepublic static int getBitmapSize(android.graphics.Bitmap bitmap)
public android.graphics.Bitmap getBitmap(java.lang.String key)
getBitmap in interface ImageCachepublic void putBitmap(java.lang.String key,
android.graphics.Bitmap bitmap)
putBitmap in interface ImageCachepublic void invalidateBitmap(java.lang.String url)
invalidateBitmap in interface ImageCachepublic void clear()
clear in interface ImageCache