public class ImageCache extends ImageMemoryCache
ImageMemoryCache and
ImageSDCardCache. It applies to apps those used much images, like sina weibo, twitter, taobao, huaban, weixin
and so on.ImageMemoryCache.setOnImageCallbackListener(OnImageCallbackListener) set callback interface after image
get successImageMemoryCache.get(String, List, View) get image asynchronous and preload other images asynchronous
according to urlListImageMemoryCache.get(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 exitsetHttpReadTimeOut(int) set http read image time out, if less than 0, not set. default is not setPreloadDataCache.setContext(Context) and setAllowedNetworkTypes(int) restrict the types of
networks over which this data can get.ImageMemoryCache.setOpenWaitingQueue(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 primary cache is fullsetCacheFullRemoveTypeOfSecondaryCache(CacheFullRemoveType) set remove type when secondary cache is full
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
ImageCache.CompressListener
set image compress scale
|
ImageMemoryCache.OnImageCallbackListenerPreloadDataCache.OnGetDataListener<K,V>| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_CACHE_FOLDER
cache folder path which be used when saving images
|
DEFAULT_MAX_SIZEDEFAULT_BACKWARD_CACHE_NUMBER, DEFAULT_FORWARD_CACHE_NUMBER, DEFAULT_THREAD_POOL_SIZE, NETWORK_MOBILE, NETWORK_WIFI, onGetDataListenercache, hitCount, missCount| 构造器和说明 |
|---|
ImageCache()
max size of primary cache is
ImageMemoryCache.DEFAULT_MAX_SIZE, max size of secondary cache is
ImageSDCardCache.DEFAULT_MAX_SIZE
thread pool size of primary cache and secondary cache both are
PreloadDataCache.DEFAULT_THREAD_POOL_SIZE
|
ImageCache(int primaryCacheMaxSize)
max size of secondary cache is
ImageSDCardCache.DEFAULT_MAX_SIZE
thread pool size of primary cache and secondary cache both are
PreloadDataCache.DEFAULT_THREAD_POOL_SIZE
|
ImageCache(int primaryCacheMaxSize,
int secondaryCacheMaxSize)
thread pool size of primary cache and secondary cache both are
PreloadDataCache.DEFAULT_THREAD_POOL_SIZE |
ImageCache(int primaryCacheMaxSize,
int primaryCacheThreadPoolSize,
int secondaryCacheMaxSize,
int secondaryCacheThreadPoolSize)
Callback interface after image get success is null, can set by
PreloadDataCache#setOnImageCallbackListener(OnImageCallbackListener)
Get data listener of primary cache is getOnGetImageListenerOfPrimaryCache(), you can set by
#setOnGetImageListenerOfPrimaryCache(OnGetDataListener), but not recommended, you may destory secondary
cache. |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
checkIsNetworkTypeAllowed()
Check if get data can proceed over the given network type.
|
void |
clear()
clear both primary cache and secondary cache
|
void |
deleteUnusedFiles()
delete unused file in
getCacheFolder(), you can use it after loadDataFromDb(Context, String) at
first time |
int |
getAllowedNetworkTypes()
get the types of networks over which this data can get
|
String |
getCacheFolder()
get cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDER |
CacheFullRemoveType<String> |
getCacheFullRemoveTypeOfSecondaryCache()
get remove type when secondary cache is full
|
ImageCache.CompressListener |
getCompressListener()
get compressListener
|
int |
getCompressSize()
get compressSize
|
android.content.Context |
getContext() |
FileNameRule |
getFileNameRule()
get file name rule which be used when saving images, default is
FileNameRuleImageUrl |
int |
getHttpReadTimeOut()
get http read image time out of secondary cache, if less than 0, not set. default is not set
|
String |
getImagePath(String imageUrl)
get image file path
|
PreloadDataCache.OnGetDataListener<String,android.graphics.Bitmap> |
getOnGetImageListenerOfPrimaryCache()
get get image listener of primary cache
|
PreloadDataCache.OnGetDataListener<String,String> |
getOnGetImageListenerOfSecondaryCache()
get get image listener of secondary cache
|
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 |
isCheckNetwork()
get whether to check the network at first when get data, used when
PreloadDataCache.checkIsNetworkTypeAllowed() |
boolean |
loadDataFromDb(android.content.Context context,
String tag)
load all data in db whose tag is same to tag to this cache. 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
|
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 this cache 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 |
setAllowedNetworkTypes(int allowedNetworkTypes)
Restrict the types of networks over which this data can get.
|
void |
setBackwardCacheNumber(int backwardCacheNumber)
set count for preload backward, default is
PreloadDataCache.DEFAULT_BACKWARD_CACHE_NUMBER |
void |
setCacheFolder(String cacheFolder)
set cache folder path which be used when saving images, default is
DEFAULT_CACHE_FOLDER |
void |
setCacheFullRemoveTypeOfSecondaryCache(CacheFullRemoveType<String> cacheFullRemoveType)
set remove type when secondary cache is full
|
void |
setCheckNetwork(boolean isCheckNetwork)
set whether to check the network at first when get data, used when
PreloadDataCache.checkIsNetworkTypeAllowed() |
void |
setCompressListener(ImageCache.CompressListener compressListener)
set compressListener
Attentions:
if this function is set, the function
#setCompressSize(String) is not work
|
void |
setCompressSize(int compressSize)
set image compress scale
Attentions:
if
setCompressListener(CompressListener) is set, this function is not work
|
void |
setContext(android.content.Context context)
|
void |
setFileNameRule(FileNameRule fileNameRule)
set file name rule which be used when saving images, default is
FileNameRuleImageUrl |
void |
setForwardCacheNumber(int forwardCacheNumber)
set count for preload forward, default is
PreloadDataCache.DEFAULT_FORWARD_CACHE_NUMBER |
void |
setHttpReadTimeOut(int readTimeOutMillis)
set http read image time out of secondary cache, if less than 0, not set. default is not set, in mills
|
void |
setOnGetImageListenerOfPrimaryCache(PreloadDataCache.OnGetDataListener<String,android.graphics.Bitmap> onGetImageListener)
set get data listener of primary cache, primary cache will get data and preload data by it
|
void |
setOnGetImageListenerOfSecondaryCache(PreloadDataCache.OnGetDataListener<String,String> onGetImageListener)
set get data listener of secondary cache, secondary cache will get data and preload data by it
|
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() |
get, get, getDefaultOnGetImageListener, getOnImageCallbackListener, isOpenWaitingQueue, setOnImageCallbackListener, setOpenWaitingQueueget, get, getBackwardCacheNumber, getForwardCacheNumber, getOnGetDataListener, isExistGettingDataThread, loadCache, preloadDataBackward, preloadDataForward, setOnGetDataListenercontainsKey, entrySet, fullRemoveOne, getCacheFullRemoveType, getHitCount, getHitRate, getMaxSize, getMissCount, getSize, getValidTime, isExpired, isExpired, keySet, put, put, putAll, remove, removeExpired, saveCache, setCacheFullRemoveType, setUsedInfo, setValidTime, valuespublic static final String DEFAULT_CACHE_FOLDER
public ImageCache()
ImageMemoryCache.DEFAULT_MAX_SIZE, max size of secondary cache is
ImageSDCardCache.DEFAULT_MAX_SIZEPreloadDataCache.DEFAULT_THREAD_POOL_SIZE#ImageCache(int, int, int, int)}public ImageCache(int primaryCacheMaxSize)
ImageSDCardCache.DEFAULT_MAX_SIZEPreloadDataCache.DEFAULT_THREAD_POOL_SIZEprimaryCacheMaxSize - secondaryCacheMaxSize - #ImageCache(int, int, int, int)}public ImageCache(int primaryCacheMaxSize,
int secondaryCacheMaxSize)
PreloadDataCache.DEFAULT_THREAD_POOL_SIZEprimaryCacheMaxSize - secondaryCacheMaxSize - #ImageCache(int, int, int, int)}public ImageCache(int primaryCacheMaxSize,
int primaryCacheThreadPoolSize,
int secondaryCacheMaxSize,
int secondaryCacheThreadPoolSize)
PreloadDataCache#setOnImageCallbackListener(OnImageCallbackListener)getOnGetImageListenerOfPrimaryCache(), you can set by
#setOnGetImageListenerOfPrimaryCache(OnGetDataListener), but not recommended, you may destory secondary
cache.getOnGetImageListenerOfSecondaryCache(), you can set by
#setOnGetImageListenerOfSecondaryCache(OnGetDataListener).RemoveTypeUsedCountSmall when cache is fullprimaryCacheMaxSize - maximum size of the primary cacheprimaryCacheThreadPoolSize - getting data thread pool size of the primary cachesecondaryCacheMaxSize - maximum size of the secondary cachesecondaryCacheThreadPoolSize - getting data thread pool size of the secondary cachepublic int getCompressSize()
public void setCompressSize(int compressSize)
setCompressListener(CompressListener) is set, this function is not workcompressSize - the compressSize to set#setCompressSize(String)}public void setCompressListener(ImageCache.CompressListener compressListener)
#setCompressSize(String) is not workcompressListener - public ImageCache.CompressListener getCompressListener()
public int getHttpReadTimeOut()
getHttpReadTimeOut 在类中 ImageMemoryCachepublic void setHttpReadTimeOut(int readTimeOutMillis)
setHttpReadTimeOut 在类中 ImageMemoryCachereadTimeOutMillis - public void clear()
clear 在接口中 Cache<String,android.graphics.Bitmap>clear 在类中 SimpleCache<String,android.graphics.Bitmap>Map.clear()public void setForwardCacheNumber(int forwardCacheNumber)
PreloadDataCachePreloadDataCache.DEFAULT_FORWARD_CACHE_NUMBERsetForwardCacheNumber 在类中 PreloadDataCache<String,android.graphics.Bitmap>public void setBackwardCacheNumber(int backwardCacheNumber)
PreloadDataCachePreloadDataCache.DEFAULT_BACKWARD_CACHE_NUMBERsetBackwardCacheNumber 在类中 PreloadDataCache<String,android.graphics.Bitmap>public int getAllowedNetworkTypes()
PreloadDataCachegetAllowedNetworkTypes 在类中 PreloadDataCache<String,android.graphics.Bitmap>public void setAllowedNetworkTypes(int allowedNetworkTypes)
PreloadDataCachePreloadDataCache.getContext() is not nullsetAllowedNetworkTypes 在类中 PreloadDataCache<String,android.graphics.Bitmap>allowedNetworkTypes - any combination of the NETWORK_* bit flags.public boolean isCheckNetwork()
PreloadDataCachePreloadDataCache.checkIsNetworkTypeAllowed()isCheckNetwork 在类中 PreloadDataCache<String,android.graphics.Bitmap>public void setCheckNetwork(boolean isCheckNetwork)
PreloadDataCachePreloadDataCache.checkIsNetworkTypeAllowed()setCheckNetwork 在类中 PreloadDataCache<String,android.graphics.Bitmap>public boolean checkIsNetworkTypeAllowed()
PreloadDataCachecheckIsNetworkTypeAllowed 在类中 PreloadDataCache<String,android.graphics.Bitmap>PreloadDataCache.getContext() is null, return truePreloadDataCache.getAllowedNetworkTypes() is not match network, return falsepublic android.content.Context getContext()
getContext 在类中 PreloadDataCache<String,android.graphics.Bitmap>public void setContext(android.content.Context context)
PreloadDataCachesetContext 在类中 PreloadDataCache<String,android.graphics.Bitmap>public void setRequestProperties(Map<String,String> requestProperties)
setRequestProperties 在类中 ImageMemoryCacherequestProperties - public Map<String,String> getRequestProperties()
getRequestProperties 在类中 ImageMemoryCachepublic void setRequestProperty(String field, String newValue)
setRequestProperty 在类中 ImageMemoryCachefield - the request header field to be setnewValue - the new value of the specified property#setRequestProperties(Map)}public String getCacheFolder()
DEFAULT_CACHE_FOLDERImageSDCardCache.getCacheFolder()public void setCacheFolder(String cacheFolder)
DEFAULT_CACHE_FOLDERcacheFolder - ImageSDCardCache.setCacheFolder(String)public FileNameRule getFileNameRule()
FileNameRuleImageUrlImageSDCardCache.getFileNameRule()public void setFileNameRule(FileNameRule fileNameRule)
FileNameRuleImageUrlfileNameRule - ImageSDCardCache.setFileNameRule(FileNameRule)public 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 void deleteUnusedFiles()
getCacheFolder(), you can use it after loadDataFromDb(Context, String) at
first timeImageSDCardCache#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
emptyImageSDCardCache.loadDataFromDb(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
emptyImageSDCardCache.saveDataToDb(Context, ImageSDCardCache, String)public String getImagePath(String imageUrl)
imageUrl - protected void shutdown()
shutdown 在类中 ImageMemoryCacheExecutorService.shutdown()public List<Runnable> shutdownNow()
shutdownNow 在类中 ImageMemoryCacheExecutorService.shutdownNow()public PreloadDataCache.OnGetDataListener<String,android.graphics.Bitmap> getOnGetImageListenerOfPrimaryCache()
PreloadDataCache#getOnGetDataListener()}public void setOnGetImageListenerOfPrimaryCache(PreloadDataCache.OnGetDataListener<String,android.graphics.Bitmap> onGetImageListener)
onGetImageListener - PreloadDataCache#setOnGetDataListener(OnGetDataListener)}public PreloadDataCache.OnGetDataListener<String,String> getOnGetImageListenerOfSecondaryCache()
public void setOnGetImageListenerOfSecondaryCache(PreloadDataCache.OnGetDataListener<String,String> onGetImageListener)
onGetImageListener - public CacheFullRemoveType<String> getCacheFullRemoveTypeOfSecondaryCache()
public void setCacheFullRemoveTypeOfSecondaryCache(CacheFullRemoveType<String> cacheFullRemoveType)
cacheFullRemoveType - the cacheFullRemoveType to setCopyright © 2012-2014. All Rights Reserved.