public class ImageSDCardCache extends PreloadDataCache<String,String>
ImageMemoryCache.setOnImageSDCallbackListener(OnImageSDCallbackListener) set callback interface when getting imageget(String, List, View) get image asynchronous and preload other images asynchronous according to
urlListget(String, View) get image asynchronousinitData(Context, String) or loadDataFromDb(Context, String) to init data when app start,
saveDataToDb(Context, String) to save data when app exitsetFileNameRule(FileNameRule) set file name rule which be used when saving images, default is
FileNameRuleImageUrlsetCacheFolder(String) set cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDERsetHttpReadTimeOut(int) set http read image time out, if less than 0, not set. default is not setsetOpenWaitingQueue(boolean) set whether open waiting queue, default is true. If true, save all view
waiting for image loaded, else only save the newest onePreloadDataCache.setOnGetDataListener(OnGetDataListener) set how to get image, this cache will get image
and preload images by itSimpleCache.setCacheFullRemoveType(CacheFullRemoveType) set remove type when cache is fullPreloadDataCache and SimpleCache| 限定符和类型 | 类和说明 |
|---|---|
static interface |
ImageSDCardCache.OnImageSDCallbackListener
callback interface when getting image
|
PreloadDataCache.OnGetDataListener<K,V>| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_CACHE_FOLDER
cache folder path which be used when saving images
|
static int |
DEFAULT_MAX_SIZE
recommend default max cache size according to dalvik max memory
|
DEFAULT_BACKWARD_CACHE_NUMBER, DEFAULT_FORWARD_CACHE_NUMBER, DEFAULT_THREAD_POOL_SIZE, NETWORK_MOBILE, NETWORK_WIFI, onGetDataListenercache, hitCount, missCount| 构造器和说明 |
|---|
ImageSDCardCache()
Get data listener is
getDefaultOnGetImageListener()
callback interface when getting image is null, can set by
setOnImageSDCallbackListener(OnImageSDCallbackListener)
Maximum size of the cache is DEFAULT_MAX_SIZE
Elements of the cache will not invalid
Remove type is RemoveTypeUsedCountSmall when cache is full
|
ImageSDCardCache(int maxSize)
Get data listener is
getDefaultOnGetImageListener()
callback interface when getting image is null, can set by
setOnImageSDCallbackListener(OnImageSDCallbackListener)
Elements of the cache will not invalid
Remove type is RemoveTypeUsedCountSmall when cache is full
|
ImageSDCardCache(int maxSize,
int threadPoolSize)
Get data listener is
getDefaultOnGetImageListener()
callback interface when getting image is null, can set by
setOnImageSDCallbackListener(OnImageSDCallbackListener)
Elements of the cache will not invalid
Remove type is RemoveTypeUsedCountSmall when cache is full
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
clear()
delete file when clear cache
|
void |
deleteUnusedFiles()
delete unused file in
getCacheFolder(), you can use it after loadDataFromDb(Context, String) at
first time |
protected CacheObject<String> |
fullRemoveOne()
delete file when full remove one
|
boolean |
get(String imageUrl,
List<String> urlList,
android.view.View view)
get image asynchronous and preload other images asynchronous according to urlList
|
boolean |
get(String imageUrl,
android.view.View view)
get image asynchronous. when get image success, it will pass to
ImageSDCardCache.OnImageSDCallbackListener.onGetSuccess(String, String, View, boolean) |
String |
getCacheFolder()
get cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDER |
PreloadDataCache.OnGetDataListener<String,String> |
getDefaultOnGetImageListener()
default get image listener
|
FileNameRule |
getFileNameRule()
get file name rule which be used when saving images, default is
FileNameRuleImageUrl |
int |
getHttpReadTimeOut()
get http read image time out, if less than 0, not set. default is not set
|
String |
getImagePath(String imageUrl)
get image file path
|
ImageSDCardCache.OnImageSDCallbackListener |
getOnImageSDCallbackListener()
get callback interface when getting image
|
Map<String,String> |
getRequestProperties()
get http request properties
|
void |
initData(android.content.Context context,
String tag)
load all data from db and delete unused file in
getCacheFolder()
It's a combination of loadDataFromDb(Context, String) and deleteUnusedFiles()
You should use saveDataToDb(Context, String) to save data when app exit
|
boolean |
isOpenWaitingQueue()
get whether open waiting queue, default is true.
|
static boolean |
loadDataFromDb(android.content.Context context,
ImageSDCardCache imageSDCardCache,
String tag)
load all data in db whose tag is same to tag to imageSDCardCache. just put, do not affect the original data
Attentions:
If imageSDCardCache is null, throws exception
If tag is null or empty, throws exception
You should use
saveDataToDb(Context, ImageSDCardCache, String) to save data when app exit
|
boolean |
loadDataFromDb(android.content.Context context,
String tag)
load all data in db whose tag is same to tag to imageSDCardCache. just put, do not affect the original data
Attentions:
If tag is null or empty, throws exception
You should use
saveDataToDb(Context, String) to save data when app exit
|
CacheObject<String> |
remove(String key)
delete file when remove
|
static boolean |
saveDataToDb(android.content.Context context,
ImageSDCardCache imageSDCardCache,
String tag)
delete all rows in db whose tag is same to tag at first, and insert all data in imageSDCardCache to db
Attentions:
If imageSDCardCache is null, throws exception
If tag is null or empty, throws exception
Will delete all rows in db whose tag is same to tag at first
You can use
initData(Context, String) or loadDataFromDb(Context, ImageSDCardCache, String)
to init data when app start
|
boolean |
saveDataToDb(android.content.Context context,
String tag)
delete all rows in db whose tag is same to tag at first, and insert all data in imageSDCardCache to db
Attentions:
If tag is null or empty, throws exception
Will delete all rows in db whose tag is same to tag at first
You can use
initData(Context, String) or loadDataFromDb(Context, String) to init data when
app start
|
void |
setCacheFolder(String cacheFolder)
set cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDER |
void |
setFileNameRule(FileNameRule fileNameRule)
set file name rule which be used when saving images, default is
FileNameRuleImageUrl |
void |
setHttpReadTimeOut(int readTimeOutMillis)
set http read image time out, if less than 0, not set. default is not set, in mills
|
void |
setOnImageSDCallbackListener(ImageSDCardCache.OnImageSDCallbackListener onImageSDCallbackListener)
set callback interface when getting image
|
void |
setOpenWaitingQueue(boolean isOpenWaitingQueue)
set whether open waiting queue, default is true.
|
void |
setRequestProperties(Map<String,String> requestProperties)
set http request properties
If image is from the different server, setRequestProperty("Connection", "false") is recommended.
|
void |
setRequestProperty(String field,
String newValue)
Sets the value of the http request header field
|
protected void |
shutdown() |
List<Runnable> |
shutdownNow() |
checkIsNetworkTypeAllowed, get, get, getAllowedNetworkTypes, getBackwardCacheNumber, getContext, getForwardCacheNumber, getOnGetDataListener, isCheckNetwork, isExistGettingDataThread, loadCache, preloadDataBackward, preloadDataForward, setAllowedNetworkTypes, setBackwardCacheNumber, setCheckNetwork, setContext, setForwardCacheNumber, setOnGetDataListenercontainsKey, entrySet, getCacheFullRemoveType, getHitCount, getHitRate, getMaxSize, getMissCount, getSize, getValidTime, isExpired, isExpired, keySet, put, put, putAll, removeExpired, saveCache, setCacheFullRemoveType, setUsedInfo, setValidTime, valuespublic static final int DEFAULT_MAX_SIZE
public static final String DEFAULT_CACHE_FOLDER
public ImageSDCardCache()
getDefaultOnGetImageListener()setOnImageSDCallbackListener(OnImageSDCallbackListener)DEFAULT_MAX_SIZERemoveTypeUsedCountSmall when cache is fullpublic ImageSDCardCache(int maxSize)
getDefaultOnGetImageListener()setOnImageSDCallbackListener(OnImageSDCallbackListener)RemoveTypeUsedCountSmall when cache is fullmaxSize - maximum size of the cachePreloadDataCache.PreloadDataCache(int)public ImageSDCardCache(int maxSize,
int threadPoolSize)
getDefaultOnGetImageListener()setOnImageSDCallbackListener(OnImageSDCallbackListener)RemoveTypeUsedCountSmall when cache is fullmaxSize - maximum size of the cachethreadPoolSize - getting data thread pool sizePreloadDataCache.PreloadDataCache(int, int)public boolean get(String imageUrl, android.view.View view)
ImageSDCardCache.OnImageSDCallbackListener.onGetSuccess(String, String, View, boolean)imageUrl - view - public boolean get(String imageUrl, List<String> urlList, android.view.View view)
imageUrl - urlList - url list, if is null, not preload, else preload forward by
PreloadDataCache.preloadDataForward(Object, List, int), preload backward by
PreloadDataCache.preloadDataBackward(Object, List, int)view - public String getCacheFolder()
DEFAULT_CACHE_FOLDERpublic void setCacheFolder(String cacheFolder)
DEFAULT_CACHE_FOLDERcacheFolder - public FileNameRule getFileNameRule()
FileNameRuleImageUrlpublic void setFileNameRule(FileNameRule fileNameRule)
FileNameRuleImageUrlfileNameRule - public ImageSDCardCache.OnImageSDCallbackListener getOnImageSDCallbackListener()
public void setOnImageSDCallbackListener(ImageSDCardCache.OnImageSDCallbackListener onImageSDCallbackListener)
onImageSDCallbackListener - the onImageSDCallbackListener to setpublic int getHttpReadTimeOut()
public void setHttpReadTimeOut(int readTimeOutMillis)
readTimeOutMillis - public boolean isOpenWaitingQueue()
public void setOpenWaitingQueue(boolean isOpenWaitingQueue)
isOpenWaitingQueue - public void setRequestProperties(Map<String,String> requestProperties)
requestProperties - public Map<String,String> getRequestProperties()
public void setRequestProperty(String field, String newValue)
field - the request header field to be setnewValue - the new value of the specified property#setRequestProperties(Map)}protected void shutdown()
shutdown 在类中 PreloadDataCache<String,String>ExecutorService.shutdown()public List<Runnable> shutdownNow()
shutdownNow 在类中 PreloadDataCache<String,String>ExecutorService.shutdownNow()protected CacheObject<String> fullRemoveOne()
fullRemoveOne 在类中 SimpleCache<String,String>public CacheObject<String> remove(String key)
public void clear()
clear 在接口中 Cache<String,String>clear 在类中 SimpleCache<String,String>Map.clear()public void deleteUnusedFiles()
getCacheFolder(), you can use it after loadDataFromDb(Context, String) at
first timepublic void initData(android.content.Context context,
String tag)
getCacheFolder()
loadDataFromDb(Context, String) and deleteUnusedFiles()saveDataToDb(Context, String) to save data when app exitcontext - tag - loadDataFromDb(Context, String),
deleteUnusedFiles()public boolean loadDataFromDb(android.content.Context context,
String tag)
saveDataToDb(Context, String) to save data when app exitcontext - tag - tag used to mark this cache when save to and load from db, should be unique and cannot be null or
emptyloadDataFromDb(Context, ImageSDCardCache, String)public boolean saveDataToDb(android.content.Context context,
String tag)
initData(Context, String) or loadDataFromDb(Context, String) to init data when
app startcontext - tag - tag used to mark this cache when save to and load from db, should be unique and cannot be null or
emptysaveDataToDb(Context, ImageSDCardCache, String)public static boolean loadDataFromDb(android.content.Context context,
ImageSDCardCache imageSDCardCache,
String tag)
saveDataToDb(Context, ImageSDCardCache, String) to save data when app exitcontext - imageSDCardCache - tag - tag used to mark this cache when save to and load from db, should be unique and cannot be null or
emptypublic static boolean saveDataToDb(android.content.Context context,
ImageSDCardCache imageSDCardCache,
String tag)
initData(Context, String) or loadDataFromDb(Context, ImageSDCardCache, String)
to init data when app startcontext - imageSDCardCache - tag - tag used to mark this cache when save to and load from db, should be unique and cannot be null or
emptypublic String getImagePath(String imageUrl)
imageUrl - public PreloadDataCache.OnGetDataListener<String,String> getDefaultOnGetImageListener()
Copyright © 2012-2014. All Rights Reserved.