public class BitmapImageCache extends java.lang.Object implements ImageCache
| Modifier and Type | Class and Description |
|---|---|
static class |
BitmapImageCache.RetainFragment
A simple non-UI Fragment that stores a single Object and is retained over configuration
changes.
|
| Constructor and Description |
|---|
BitmapImageCache(int memCacheSize)
Don't instantiate this class directly, use
#getInstance(android.support.v4.app.FragmentManager, float). |
| 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 int |
getBitmapSize(android.graphics.drawable.BitmapDrawable value)
Get the size in bytes of a bitmap in a BitmapDrawable.
|
static BitmapImageCache |
getInstance(FragmentManager fragmentManger) |
static BitmapImageCache |
getInstance(FragmentManager fragmentManger,
DiskLruBasedCache.ImageCacheParams imageCacheParams) |
static BitmapImageCache |
getInstance(FragmentManager fragmentManager,
float memCachePercent) |
static BitmapImageCache |
getInstance(FragmentManager fragmentManager,
int memCacheSize) |
static BitmapImageCache |
getInstance(FragmentManager fragmentManager,
java.lang.String fragmentTag,
int memCacheSize)
Find and return an existing BitmapCache stored in a
BitmapImageCache.RetainFragment, if not found a
new one is created using the supplied params and saved to a BitmapImageCache.RetainFragment. |
static long |
getUsableSpace(java.io.File path)
Check how much usable space is available at a given path.
|
void |
invalidateBitmap(java.lang.String url) |
void |
putBitmap(java.lang.String key,
android.graphics.Bitmap bitmap) |
public BitmapImageCache(int memCacheSize)
#getInstance(android.support.v4.app.FragmentManager, float).memCacheSize - Memory cache size in KB.public static BitmapImageCache getInstance(FragmentManager fragmentManager, java.lang.String fragmentTag, int memCacheSize)
BitmapImageCache.RetainFragment, if not found a
new one is created using the supplied params and saved to a BitmapImageCache.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 BitmapImageCache getInstance(FragmentManager fragmentManager, int memCacheSize)
public static BitmapImageCache getInstance(FragmentManager fragmentManager, float memCachePercent)
public static BitmapImageCache getInstance(FragmentManager fragmentManger)
public static BitmapImageCache getInstance(FragmentManager fragmentManger, DiskLruBasedCache.ImageCacheParams imageCacheParams)
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 static int getBitmapSize(android.graphics.drawable.BitmapDrawable value)
value - public static long getUsableSpace(java.io.File path)
path - The path to checkpublic 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