I have image file://...qgKEIJC5EHey5qLUEDPWazJ9QimqkeQK.jpg, it is loaded with options
new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_empty)
.resetViewBeforeLoading(true)
.cacheInMemory(true)
.cacheOnDisk(false)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.build()
but when i delete this file, and remove it from cache
if (file.exists()) {
file.setWritable(true);
MemoryCacheUtils.removeFromCache(file.getAbsolutePath(), ImageLoader.getInstance().getMemoryCache());
DiskCacheUtils.removeFromCache(file.getAbsolutePath(), ImageLoader.getInstance().getDiskCache());
boolean deleted = file.delete();
if (!deleted)
Log.d("ERROR", "");
}
image loader still loading it from memory cache
D/ImageLoader: Display image in ImageAware (loaded from MEMORY_CACHE) [file://.../qgKEIJC5EHey5qLUEDPWazJ9QimqkeQK.jpg_430x430]
then i've tried to delete such file using image view size
int size = getImageView().getWidth();
String cachedFile = file.getAbsolutePath() + "_" + size + "x" + size; // = file://.../qgKEIJC5EHey5qLUEDPWazJ9QimqkeQK.jpg_430x430
MemoryCacheUtils.removeFromCache(cachedFile, ImageLoader.getInstance().getMemoryCache());
but it not worked
how can i delete all such files from cache?
finally i found a solution:
i was using wrong url for local file, i forgot to add file://
in code, cause my image url was saved as file.getAbsolutePath()
and was not including file://
. Also i found how i can smoothly replace original picture with cropped (in situation when cropping layer cover original picture and then it need to disappear and show already cropped image)
in adapter
public void setImageLoader(final ImageView imageView, final MyImage myImage) {
final String path = "file://" + myImage.getAbsPathImage();
final DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_empty)
.resetViewBeforeLoading(false) //important!
.cacheInMemory(true) //important!
.cacheOnDisk(true) //important!
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
if (!myImage.isImageCropCacheUpdated()) {
List<String> memCache = MemoryCacheUtils.findCacheKeysForImageUri(path, ImageLoader.getInstance().getMemoryCache());
boolean cacheFound = !memCache.isEmpty();
if (!cacheFound) {
File discCache = DiskCacheUtils.findInCache(path, ImageLoader.getInstance().getDiskCache());
if (discCache != null) {
cacheFound = discCache.exists();
}
}
if (cacheFound) {
myImage.setIsImageCropCacheUpdated(true);
MemoryCacheUtils.removeFromCache(path, ImageLoader.getInstance().getMemoryCache());
DiskCacheUtils.removeFromCache(path, ImageLoader.getInstance().getDiskCache());
}
}
ImageLoader.getInstance().displayImage(path, imageView, options);
}
in activity
final ImageView imageView = (ImageView) pager.findViewWithTag(Constants.TAGS.IMAGEVIEW_TAG
+ pager.getCurrentItem()); //get image view from view pager
imageView.setImageBitmap(getCropImageView().getCroppedImage());
imagePagerAdapter.setImageLoader(imageView, getCurrentImage()); //get cropped image from special crop image view and call setImageLoader from adapter
i'm not using notifyDataSetChanged()
because image blinks in that case (dont know why), after that i call fade out animation for special crop image view and it looks great, also i'm setting cropped image to imageView
before image loader because it can load picture for a while, and fade out animation has a fixed time period, if i will not do that - there maybe a little time when cropping layer already disappeared and cropped image still was not loaded, this not good