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

Commit

Permalink
[library] Clean up CacheableBitmapDrawable.checkState()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Banes committed Mar 11, 2013
1 parent 4af5620 commit c7c29d6
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions library/src/uk/co/senab/bitmapcache/CacheableBitmapDrawable.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ private void checkState() {
* happens now, or is delayed depends on whether the Drawable has been displayed or not. <ul> * happens now, or is delayed depends on whether the Drawable has been displayed or not. <ul>
* <li>If it has been displayed, it is recycled straight away.</li> <li>If it has not been * <li>If it has been displayed, it is recycled straight away.</li> <li>If it has not been
* displayed, and <code>ignoreBeenDisplayed</code> is <code>false</code>, a call to * displayed, and <code>ignoreBeenDisplayed</code> is <code>false</code>, a call to
* <code>checkState(true)</code> is queued to be called after a delay.</li> <li>If it has not been * <code>checkState(true)</code> is queued to be called after a delay.</li> <li>If it has not
* displayed, and <code>ignoreBeenDisplayed</code> is <code>true</code>, it is recycled straight * been displayed, and <code>ignoreBeenDisplayed</code> is <code>true</code>, it is recycled
* away.</li> </ul> * straight away.</li> </ul>
* *
* @param ignoreBeenDisplayed - Whether to ignore the 'has been displayed' flag when deciding * @param ignoreBeenDisplayed - Whether to ignore the 'has been displayed' flag when deciding
* whether to recycle() now. * whether to recycle() now.
Expand All @@ -172,43 +172,31 @@ private synchronized void checkState(final boolean ignoreBeenDisplayed) {
return; return;
} }


if (mCacheCount <= 0 && mDisplayingCount <= 0) { // Cancel the callback, if one is queued.
// We're not being referenced or used anywhere cancelCheckStateCallback();


// Cancel the callback, if one is queued. // We're not being referenced or used anywhere
cancelCheckStateCallback(); if (mCacheCount <= 0 && mDisplayingCount <= 0 && hasValidBitmap()) {

if (hasValidBitmap()) {
/**
* If we have been displayed or we don't care whether we have
* been or not, then recycle() now. Otherwise, we retry in 1
* second.
*/
if (mHasBeenDisplayed || ignoreBeenDisplayed) {
if (Constants.DEBUG) {
Log.d(LOG_TAG, "Recycling bitmap with url: " + mUrl);
}
getBitmap().recycle();
} else {
if (Constants.DEBUG) {
Log.d(LOG_TAG,
"Unused Bitmap which hasn't been displayed, delaying recycle(): "
+ mUrl);
}
mCheckStateRunnable = new CheckStateRunnable(this);
sHandler.postDelayed(mCheckStateRunnable,
Constants.UNUSED_DRAWABLE_RECYCLE_DELAY_MS);
}
}
} else {
// We're being referenced (by either a cache or used somewhere)


/** /**
* If mCheckStateRunnable isn't null, then a checkState() call has * If we have been displayed or we don't care whether we have
* been queued previously. As we're being used now, cancel the * been or not, then recycle() now. Otherwise, we retry after a delay.
* callback.
*/ */
cancelCheckStateCallback(); if (mHasBeenDisplayed || ignoreBeenDisplayed) {
if (Constants.DEBUG) {
Log.d(LOG_TAG, "Recycling bitmap with url: " + mUrl);
}
getBitmap().recycle();
} else {
if (Constants.DEBUG) {
Log.d(LOG_TAG,
"Unused Bitmap which hasn't been displayed, delaying recycle(): "
+ mUrl);
}
mCheckStateRunnable = new CheckStateRunnable(this);
sHandler.postDelayed(mCheckStateRunnable,
Constants.UNUSED_DRAWABLE_RECYCLE_DELAY_MS);
}
} }
} }


Expand Down

0 comments on commit c7c29d6

Please sign in to comment.