public class ImageCache
extends java.lang.Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ImageCache.ImageCacheParams
A holder class that contains cache parameters.
|
static class |
ImageCache.RetainFragment
A simple non-UI Fragment that stores a single Object and is retained over configuration
changes.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addBitmapToCache(java.lang.String data,
android.graphics.drawable.BitmapDrawable value)
Adds a bitmap to both memory and disk cache.
|
static int |
calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
Calculate an inSampleSize for use in a
BitmapFactory.Options object when decoding
bitmaps using the decode* methods from BitmapFactory. |
void |
clearCache()
Clears both the memory and disk cache associated with this ImageCache object.
|
void |
close()
Closes the disk cache associated with this ImageCache object.
|
static android.graphics.Bitmap |
decodeSampledBitmapFromDescriptor(java.io.FileDescriptor fileDescriptor,
int reqWidth,
int reqHeight,
ImageCache cache)
Decode and sample down a bitmap from a file input stream to the requested width and height.
|
void |
flush()
Flushes the disk cache associated with this ImageCache object.
|
android.graphics.Bitmap |
getBitmapFromDiskCache(java.lang.String data)
Get from disk cache.
|
protected android.graphics.Bitmap |
getBitmapFromReusableSet(android.graphics.BitmapFactory.Options options) |
static int |
getBitmapSize(android.graphics.drawable.BitmapDrawable value)
Get the size in bytes of a bitmap in a BitmapDrawable.
|
static java.io.File |
getDiskCacheDir(android.content.Context context,
java.lang.String uniqueName)
Get a usable cache directory (external if available, internal otherwise).
|
static java.io.File |
getExternalCacheDir(android.content.Context context)
Get the external app cache directory.
|
static ImageCache |
getInstance(android.support.v4.app.FragmentManager fragmentManager,
ImageCache.ImageCacheParams cacheParams)
Return an
ImageCache instance. |
static long |
getUsableSpace(java.io.File path)
Check how much usable space is available at a given path.
|
static java.lang.String |
hashKeyForDisk(java.lang.String key)
A hashing method that changes a string (like a URL) into a hash suitable for using as a
disk filename.
|
void |
initDiskCache()
Initializes the disk cache.
|
static boolean |
isExternalStorageRemovable()
Check if external storage is built-in or removable.
|
public static ImageCache getInstance(android.support.v4.app.FragmentManager fragmentManager, ImageCache.ImageCacheParams cacheParams)
ImageCache instance. A ImageCache.RetainFragment is used to retain the
ImageCache object across configuration changes such as a change in device orientation.fragmentManager - The fragment manager to use when dealing with the retained fragment.cacheParams - The cache parameters to use if the ImageCache needs instantiation.public void initDiskCache()
public void addBitmapToCache(java.lang.String data,
android.graphics.drawable.BitmapDrawable value)
data - Unique identifier for the bitmap to storevalue - The bitmap drawable to storepublic android.graphics.Bitmap getBitmapFromDiskCache(java.lang.String data)
data - Unique identifier for which item to getpublic static android.graphics.Bitmap decodeSampledBitmapFromDescriptor(java.io.FileDescriptor fileDescriptor,
int reqWidth,
int reqHeight,
ImageCache cache)
fileDescriptor - The file descriptor to read fromreqWidth - The requested width of the resulting bitmapreqHeight - The requested height of the resulting bitmapcache - The ImageCache used to find candidate bitmaps for use with inBitmappublic static int calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
BitmapFactory.Options object when decoding
bitmaps using the decode* methods from BitmapFactory. This implementation calculates
the closest inSampleSize that is a power of 2 and will result in the final decoded bitmap
having a width and height equal to or larger than the requested width and height.options - An options object with out* params already populated (run through a decode*
method with inJustDecodeBounds==truereqWidth - The requested width of the resulting bitmapreqHeight - The requested height of the resulting bitmapprotected android.graphics.Bitmap getBitmapFromReusableSet(android.graphics.BitmapFactory.Options options)
options - - BitmapFactory.Options with out* options populatedpublic void clearCache()
public void flush()
public void close()
public static java.io.File getDiskCacheDir(android.content.Context context,
java.lang.String uniqueName)
context - The context to useuniqueName - A unique directory name to append to the cache dirpublic static java.lang.String hashKeyForDisk(java.lang.String key)
public static int getBitmapSize(android.graphics.drawable.BitmapDrawable value)
value - public static boolean isExternalStorageRemovable()
public static java.io.File getExternalCacheDir(android.content.Context context)
context - The context to usepublic static long getUsableSpace(java.io.File path)
path - The path to check