Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Commit

Permalink
Can now externally control whether a bitmap is being used, just like …
Browse files Browse the repository at this point in the history
…CacheableImageView
  • Loading branch information
Chris Banes committed Jul 3, 2012
1 parent 3d19406 commit 075641c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/uk/co/senab/bitmapcache/CacheableBitmapWrapper.java
Expand Up @@ -4,7 +4,7 @@
import android.util.Log;

public class CacheableBitmapWrapper {

static final String LOG_TAG = "CacheableBitmapWrapper";

private final String mUrl;
Expand All @@ -15,7 +15,7 @@ public class CacheableBitmapWrapper {

// Number of caches currently referencing the wrapper
private int mCacheCount;

public CacheableBitmapWrapper(Bitmap bitmap) {
this(null, bitmap);
}
Expand All @@ -24,7 +24,7 @@ public CacheableBitmapWrapper(String url, Bitmap bitmap) {
if (null == bitmap) {
throw new IllegalArgumentException("Bitmap can not be null");
}

mBitmap = bitmap;
mUrl = url;
mImageViewsCount = 0;
Expand Down Expand Up @@ -70,8 +70,12 @@ public boolean hasValidBitmap() {
}

/**
* Used to signal to the wrapper whether it is being referenced by a cache or not.
* @param added - true if the wrapper has been added to a cache, false if removed.
* Used to signal to the wrapper whether it is being referenced by a cache
* or not.
*
* @param added
* - true if the wrapper has been added to a cache, false if
* removed.
*/
void setCached(boolean added) {
if (added) {
Expand All @@ -83,11 +87,14 @@ void setCached(boolean added) {
}

/**
* Used to signal to the wrapper whether it is being displayed by an ImageView or not.
* @param added - true if displayed, false if not.
* Used to signal to the wrapper whether it is being used or not. Being used
* could be that it is being displayed by an ImageView.
*
* @param beingUsed
* - true if being used, false if not.
*/
void setDisplayed(boolean displayed) {
if (displayed) {
public void setBeingUsed(boolean beingUsed) {
if (beingUsed) {
mImageViewsCount++;
} else {
mImageViewsCount--;
Expand Down
4 changes: 2 additions & 2 deletions src/uk/co/senab/bitmapcache/CacheableImageView.java
Expand Up @@ -25,7 +25,7 @@ public CacheableImageView(Context context, AttributeSet attrs) {
*/
public void setImageCachedBitmap(final CacheableBitmapWrapper wrapper) {
if (null != wrapper) {
wrapper.setDisplayed(true);
wrapper.setBeingUsed(true);
setImageDrawable(new BitmapDrawable(getResources(), wrapper.getBitmap()));
} else {
setImageDrawable(null);
Expand Down Expand Up @@ -66,7 +66,7 @@ protected void onDetachedFromWindow() {
*/
private void resetCachedDrawable() {
if (null != mDisplayedBitmapWrapper) {
mDisplayedBitmapWrapper.setDisplayed(false);
mDisplayedBitmapWrapper.setBeingUsed(false);
mDisplayedBitmapWrapper = null;
}
}
Expand Down

0 comments on commit 075641c

Please sign in to comment.