Skip to content

Commit

Permalink
very important fix: When reusing a bitmap. Must clear it first, other…
Browse files Browse the repository at this point in the history
…wise we might end up drawing the wrong tile
  • Loading branch information
farfromrefug committed Jun 29, 2014
1 parent 96ef3da commit 6362dbd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package uk.co.senab.bitmapcache;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.v4.util.LruCache;

import java.lang.ref.SoftReference;
Expand Down Expand Up @@ -86,6 +87,8 @@ public Bitmap getBitmapFromRemoved(final int width, final int height) {
if (canUseForInBitmap(value)) {
if (canUseForInBitmapForSize(value, width, height) && !value.isBeingDisplayed() && !value.isReferencedByCache()) {
result = value.getBitmap();
SDK12.setHasAlpha(result, true);
result.eraseColor(Color.TRANSPARENT);
value.setReused();
it.remove();
break;
Expand Down Expand Up @@ -122,8 +125,7 @@ void trimMemory() {
remove(entry.getKey());
}
}

if (mRemovedEntries!=null) {
if (mRemovedEntries != null) {
synchronized (mRemovedEntries) {
mRemovedEntries.clear();
}
Expand Down
13 changes: 13 additions & 0 deletions MapboxAndroidSDK/src/main/java/uk/co/senab/bitmapcache/SDK12.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uk.co.senab.bitmapcache;


import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.os.Build;

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public class SDK12 {
static void setHasAlpha(Bitmap bitmap, final boolean hasAlpha) {
bitmap.setHasAlpha(hasAlpha);
}
}

0 comments on commit 6362dbd

Please sign in to comment.