Skip to content

Commit

Permalink
Use 'evictAll' to clear the cache, instead of resizing it.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloercoli committed Dec 11, 2013
1 parent 7f40fe4 commit 4f06a04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,9 @@ public void onTrimMemory(final int level) {
background = false;
}

//Levels that we need to consider are TRIM_MEMORY_UI_HIDDEN = 20; - TRIM_MEMORY_RUNNING_CRITICAL = 15; - TRIM_MEMORY_RUNNING_LOW = 10;
//Levels that we need to consider are TRIM_MEMORY_RUNNING_CRITICAL = 15; - TRIM_MEMORY_RUNNING_LOW = 10; - TRIM_MEMORY_RUNNING_MODERATE = 5;
if (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
int maxMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
int cacheSize = maxMemory / 16;
mBitmapCache.trimToSize(cacheSize);
mBitmapCache.evictAll();
}

}
Expand Down
17 changes: 3 additions & 14 deletions src/org/wordpress/android/util/BitmapLruCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package org.wordpress.android.util;

import android.graphics.Bitmap;
import android.os.Build;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;
Expand All @@ -17,18 +16,8 @@ public BitmapLruCache(int maxSize) {
protected int sizeOf(String key, Bitmap value) {
// The cache size will be measured in kilobytes rather than
// number of items.

int bytes = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
bytes = (value.getRowBytes() * value.getHeight());
} else {
bytes = value.getByteCount();
}

if (bytes!=0)
bytes = bytes / 1024;

return bytes;
int bytes = (value.getRowBytes() * value.getHeight());
return (bytes / 1024); //value.getByteCount() introduced in HONEYCOMB_MR1 or higher.
}

@Override
Expand All @@ -40,4 +29,4 @@ public Bitmap getBitmap(String key) {
public void putBitmap(String key, Bitmap bitmap) {
this.put(key, bitmap);
}
}
}

0 comments on commit 4f06a04

Please sign in to comment.