public class ImageSDCardCache extends PreloadDataCache<java.lang.String,java.lang.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
FileNameRuleImageUrl
setCacheFolder(String)
set cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDER
setHttpReadTimeOut(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
Modifier and Type | Class and Description |
---|---|
static interface |
ImageSDCardCache.OnImageSDCallbackListener
callback interface when getting image
|
PreloadDataCache.OnGetDataListener<K,V>
Modifier and Type | Field and Description |
---|---|
static java.lang.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
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
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 |
boolean |
get(java.lang.String imageUrl,
java.util.List<java.lang.String> urlList,
View view)
get image asynchronous and preload other images asynchronous according to urlList
|
boolean |
get(java.lang.String imageUrl,
View view)
get image asynchronous. when get image success, it will pass to
ImageSDCardCache.OnImageSDCallbackListener.onGetSuccess(String, String, View, boolean) |
java.lang.String |
getCacheFolder()
get cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDER |
PreloadDataCache.OnGetDataListener<java.lang.String,java.lang.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
|
java.lang.String |
getImagePath(java.lang.String imageUrl)
get image file path
|
ImageSDCardCache.OnImageSDCallbackListener |
getOnImageSDCallbackListener()
get callback interface when getting image
|
java.util.Map<java.lang.String,java.lang.String> |
getRequestProperties()
get http request properties
|
void |
initData(Context context,
java.lang.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(Context context,
ImageSDCardCache imageSDCardCache,
java.lang.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(Context context,
java.lang.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<java.lang.String> |
remove(java.lang.String key)
delete file when remove
|
static boolean |
saveDataToDb(Context context,
ImageSDCardCache imageSDCardCache,
java.lang.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(Context context,
java.lang.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(java.lang.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(java.util.Map<java.lang.String,java.lang.String> requestProperties)
set http request properties
If image is from the different server, setRequestProperty("Connection", "false") is recommended.
|
void |
setRequestProperty(java.lang.String field,
java.lang.String newValue)
Sets the value of the http request header field
|
java.util.List<java.lang.Runnable> |
shutdownNow() |
checkIsNetworkTypeAllowed, get, getAllowedNetworkTypes, getBackwardCacheNumber, getContext, getForwardCacheNumber, getOnGetDataListener, isCheckNetwork, isExistGettingDataThread, loadCache, setAllowedNetworkTypes, setBackwardCacheNumber, setCheckNetwork, setContext, setForwardCacheNumber, setOnGetDataListener
containsKey, entrySet, getCacheFullRemoveType, getHitCount, getHitRate, getMaxSize, getMissCount, getSize, getValidTime, keySet, put, put, putAll, saveCache, setCacheFullRemoveType, setValidTime, values
public static final int DEFAULT_MAX_SIZE
public static final java.lang.String DEFAULT_CACHE_FOLDER
public ImageSDCardCache()
getDefaultOnGetImageListener()
setOnImageSDCallbackListener(OnImageSDCallbackListener)
DEFAULT_MAX_SIZE
RemoveTypeUsedCountSmall
when cache is fullPreloadDataCache.PreloadDataCache()
public 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(java.lang.String imageUrl, View view)
ImageSDCardCache.OnImageSDCallbackListener.onGetSuccess(String, String, View, boolean)
imageUrl
- view
- public boolean get(java.lang.String imageUrl, java.util.List<java.lang.String> urlList, 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 java.lang.String getCacheFolder()
DEFAULT_CACHE_FOLDER
public void setCacheFolder(java.lang.String cacheFolder)
DEFAULT_CACHE_FOLDER
cacheFolder
- public FileNameRule getFileNameRule()
FileNameRuleImageUrl
public void setFileNameRule(FileNameRule fileNameRule)
FileNameRuleImageUrl
fileNameRule
- 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(java.util.Map<java.lang.String,java.lang.String> requestProperties)
requestProperties
- public java.util.Map<java.lang.String,java.lang.String> getRequestProperties()
public void setRequestProperty(java.lang.String field, java.lang.String newValue)
field
- the request header field to be setnewValue
- the new value of the specified property#setRequestProperties(Map)}
public java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow
in class PreloadDataCache<java.lang.String,java.lang.String>
ExecutorService.shutdownNow()
public CacheObject<java.lang.String> remove(java.lang.String key)
remove
in interface Cache<java.lang.String,java.lang.String>
remove
in class SimpleCache<java.lang.String,java.lang.String>
public void clear()
clear
in interface Cache<java.lang.String,java.lang.String>
clear
in class SimpleCache<java.lang.String,java.lang.String>
Map.clear()
public void deleteUnusedFiles()
getCacheFolder()
, you can use it after loadDataFromDb(Context, String)
at
first timepublic void initData(Context context, java.lang.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(Context context, java.lang.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(Context context, java.lang.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(Context context, ImageSDCardCache imageSDCardCache, java.lang.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(Context context, ImageSDCardCache imageSDCardCache, java.lang.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 java.lang.String getImagePath(java.lang.String imageUrl)
imageUrl
- public PreloadDataCache.OnGetDataListener<java.lang.String,java.lang.String> getDefaultOnGetImageListener()