public class EpicBitmapCache
extends java.lang.Object
Constructor and Description |
---|
EpicBitmapCache()
Basic constructor, builds the memory cache automatically.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Deletes memory and disk cache contents.
|
android.graphics.Bitmap |
getBitmapFromCache(java.lang.String key)
Tries to retrieve a Bitmap by its key from Memory Cache, and if not found, from Disk Cache.
|
android.graphics.Bitmap |
getBitmapFromDiskCache(java.lang.String key)
Gets Bitmap from Disk Cache by its key.
|
android.graphics.Bitmap |
getBitmapFromMemCache(java.lang.String key)
Gets Bitmap from Memory Cache by its key.
|
static java.io.File |
getDiskCacheDir(android.content.Context context,
java.lang.String uniqueName)
Creates a unique subdirectory of the designated app cache directory.
|
void |
initDiskCache(android.content.Context context)
Initializes memory cache.
|
void |
put(java.lang.String key,
android.graphics.Bitmap bitmap)
Adds or updates a
Bitmap to Memory and Disk cache identified by a key. |
void |
put(java.lang.String key,
android.graphics.Bitmap bitmap,
android.graphics.Bitmap.CompressFormat inDiskCompressFormat,
int inDiskCompressQuality)
Adds or updates a
Bitmap to Memory and Disk cache compressed in format and quality specified, identified by a key. |
void |
put(java.lang.String key,
android.graphics.Bitmap bitmap,
java.lang.String outMimeType,
int inDiskCompressQuality)
Adds or updates a
Bitmap to Memory and Disk cache compressed in format and quality specified, identified by a key. |
void |
remove(java.lang.String key)
Removes an entry from memory and disk cache.
|
public EpicBitmapCache()
public void initDiskCache(android.content.Context context)
context
- Context
from where lib is being called. This is used to get application's cache dir for disk cache.public void put(java.lang.String key, android.graphics.Bitmap bitmap, android.graphics.Bitmap.CompressFormat inDiskCompressFormat, int inDiskCompressQuality)
Bitmap
to Memory and Disk cache compressed in format and quality specified, identified by a key.key
- ID of the Bitmap
to retrieve it later.bitmap
- Bitmap
to be stored.inDiskCompressFormat
- Format to compress the image (JPEG, PNG, etc.) to store on disk cache.inDiskCompressQuality
- Compress quality percentage of the image, from 0 to 100, to store on disk cache.public void put(java.lang.String key, android.graphics.Bitmap bitmap, java.lang.String outMimeType, int inDiskCompressQuality) throws java.lang.IllegalArgumentException
Bitmap
to Memory and Disk cache compressed in format and quality specified, identified by a key.key
- ID of the Bitmap
to retrieve it later.bitmap
- Bitmap
to be stored.outMimeType
- Image's mime type (usually in form 'image/format', e.g. 'image/png'), to automatically obtain the compress format to store on disk cache.inDiskCompressQuality
- Compress quality percentage of the image, from 0 to 100, to store on disk cache.java.lang.IllegalArgumentException
- In case Mime Type specified is not image.public void put(java.lang.String key, android.graphics.Bitmap bitmap)
Adds or updates a Bitmap
to Memory and Disk cache identified by a key.
NOTE: This method uses JPEG format 100% quality by default when compressing image to store it on disk cache.
To manually specify format and quality of compression in disk cache, use put(String, Bitmap, Bitmap.CompressFormat, int)
instead.
key
- ID of the Bitmap
to retrieve it laterbitmap
- Bitmap
to be storedpublic void remove(java.lang.String key) throws java.io.IOException
key
- Identifier of value to be removed from cache.java.io.IOException
- In case entry could not be removed from disk cache due to an IO Error.public android.graphics.Bitmap getBitmapFromMemCache(java.lang.String key)
key
- ID of the Bitmap
to be retrieved.Bitmap
object if found, null otherwise.public android.graphics.Bitmap getBitmapFromDiskCache(java.lang.String key)
key
- ID of the Bitmap
to be retrieved.Bitmap
object if found, null otherwise.public android.graphics.Bitmap getBitmapFromCache(java.lang.String key)
key
- ID of the Bitmap
to be retrieved.Bitmap
object if found, null otherwise.public void clear() throws java.io.IOException
java.io.IOException
- In case disk cache could not be cleared due to an IO error.public static java.io.File getDiskCacheDir(android.content.Context context, java.lang.String uniqueName)
context
- Context from where EpicBitmapCache is being used.uniqueName
- Unique name for cache directory.File
pointing to cache directory