Permalink
Browse files

[library] Fix #11: Adding a constructor to CacheableBitmapDrawable.ja…

…va to let it implement the default (non deprecated) constructor with Bitmap parameter.
  • Loading branch information...
1 parent c7c29d6 commit bda38eff8574fba2e659e87ff2987974e0b3dd02 @chrisbanes committed Mar 11, 2013
@@ -19,6 +19,7 @@
import com.jakewharton.DiskLruCache;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
@@ -124,6 +125,8 @@ private static String transformUrlForDiskCacheKey(String url) {
private File mTempDir;
+ private Resources mResources;
+
/**
* Memory Cache Variables
*/
@@ -148,7 +151,11 @@ private static String transformUrlForDiskCacheKey(String url) {
BitmapLruCache(Context context) {
if (null != context) {
+ // Make sure we have the application context
+ context = context.getApplicationContext();
+
mTempDir = context.getCacheDir();
+ mResources = context.getResources();
}
}
@@ -256,7 +263,8 @@ public CacheableBitmapDrawable getFromDiskCache(final String url,
.decodeStream(snapshot.getInputStream(0), null, decodeOpts);
if (null != bitmap) {
- result = new CacheableBitmapDrawable(url, bitmap, mRecyclePolicy);
+ result = new CacheableBitmapDrawable(url, mResources, bitmap,
+ mRecyclePolicy);
if (null != mMemoryCache) {
mMemoryCache.put(result);
}
@@ -312,7 +320,8 @@ public CacheableBitmapDrawable getFromMemoryCache(final String url) {
* @return CacheableBitmapDrawable which can be used to display the bitmap.
*/
public CacheableBitmapDrawable put(final String url, final Bitmap bitmap) {
- CacheableBitmapDrawable d = new CacheableBitmapDrawable(url, bitmap, mRecyclePolicy);
+ CacheableBitmapDrawable d = new CacheableBitmapDrawable(url, mResources, bitmap,
+ mRecyclePolicy);
if (null != mMemoryCache) {
mMemoryCache.put(d);
@@ -402,7 +411,7 @@ public CacheableBitmapDrawable put(final String url, final InputStream inputStre
Bitmap bitmap = BitmapFactory.decodeFile(tmpFile.getAbsolutePath(), decodeOpts);
if (null != bitmap) {
- d = new CacheableBitmapDrawable(url, bitmap, mRecyclePolicy);
+ d = new CacheableBitmapDrawable(url, mResources, bitmap, mRecyclePolicy);
if (null != mMemoryCache) {
d.setCached(true);
@@ -556,7 +565,7 @@ private static long getHeapSize() {
/**
* @deprecated You should now use {@link Builder(Context)}. This is so that we can reliably
- * find a write-able location for temporary files.
+ * set up correctly.
*/
public Builder() {
this(null);
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package uk.co.senab.bitmapcache;
+import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
@@ -45,9 +47,9 @@
// Handler which may be used later
private static final Handler sHandler = new Handler(Looper.getMainLooper());
- @SuppressWarnings("deprecation")
- CacheableBitmapDrawable(String url, Bitmap bitmap, BitmapLruCache.RecyclePolicy recyclePolicy) {
- super(bitmap);
+ CacheableBitmapDrawable(String url, Resources resources, Bitmap bitmap,
+ BitmapLruCache.RecyclePolicy recyclePolicy) {
+ super(resources, bitmap);
mUrl = url;
mRecyclePolicy = recyclePolicy;

0 comments on commit bda38ef

Please sign in to comment.