@@ -269,11 +269,9 @@ public CacheableBitmapDrawable getFromDiskCache(final String url,
269
269
try {
270
270
final String key = transformUrlForDiskCacheKey (url );
271
271
// Try and decode bitmap
272
- Bitmap bitmap = decodeBitmap (new SnapshotInputStreamProvider (key ), decodeOpts );
272
+ result = decodeBitmap (new SnapshotInputStreamProvider (key ), url , decodeOpts );
273
273
274
- if (null != bitmap ) {
275
- result = new CacheableBitmapDrawable (url , mResources , bitmap ,
276
- mRecyclePolicy );
274
+ if (null != result ) {
277
275
if (null != mMemoryCache ) {
278
276
mMemoryCache .put (result );
279
277
}
@@ -362,7 +360,7 @@ public CacheableBitmapDrawable put(final String url, final Bitmap bitmap,
362
360
Bitmap .CompressFormat compressFormat , int compressQuality ) {
363
361
364
362
CacheableBitmapDrawable d = new CacheableBitmapDrawable (url , mResources , bitmap ,
365
- mRecyclePolicy );
363
+ mRecyclePolicy , CacheableBitmapDrawable . SOURCE_UNKNOWN );
366
364
367
365
if (null != mMemoryCache ) {
368
366
mMemoryCache .put (d );
@@ -448,11 +446,9 @@ public CacheableBitmapDrawable put(final String url, final InputStream inputStre
448
446
449
447
if (null != tmpFile ) {
450
448
// Try and decode File
451
- Bitmap bitmap = decodeBitmap (new FileInputStreamProvider (tmpFile ), decodeOpts );
452
-
453
- if (null != bitmap ) {
454
- d = new CacheableBitmapDrawable (url , mResources , bitmap , mRecyclePolicy );
449
+ d = decodeBitmap (new FileInputStreamProvider (tmpFile ), url , decodeOpts );
455
450
451
+ if (d != null ) {
456
452
if (null != mMemoryCache ) {
457
453
d .setCached (true );
458
454
mMemoryCache .put (d .getUrl (), d );
@@ -553,9 +549,12 @@ private void scheduleDiskCacheFlush() {
553
549
TimeUnit .SECONDS );
554
550
}
555
551
556
- private Bitmap decodeBitmap (InputStreamProvider ip , BitmapFactory .Options opts ) {
552
+ private CacheableBitmapDrawable decodeBitmap (InputStreamProvider ip , String url ,
553
+ BitmapFactory .Options opts ) {
554
+
557
555
Bitmap bm = null ;
558
556
InputStream is = null ;
557
+ int source = CacheableBitmapDrawable .SOURCE_NEW ;
559
558
560
559
try {
561
560
if (mRecyclePolicy .canInBitmap ()) {
@@ -566,7 +565,10 @@ private Bitmap decodeBitmap(InputStreamProvider ip, BitmapFactory.Options opts)
566
565
567
566
if (opts .inSampleSize <= 1 ) {
568
567
opts .inSampleSize = 1 ;
569
- addInBitmapOptions (ip , opts );
568
+
569
+ if (addInBitmapOptions (ip , opts )) {
570
+ source = CacheableBitmapDrawable .SOURCE_INBITMAP ;
571
+ }
570
572
}
571
573
}
572
574
@@ -579,10 +581,14 @@ private Bitmap decodeBitmap(InputStreamProvider ip, BitmapFactory.Options opts)
579
581
} finally {
580
582
IoUtils .closeStream (is );
581
583
}
582
- return bm ;
584
+
585
+ if (bm != null ) {
586
+ return new CacheableBitmapDrawable (url , mResources , bm , mRecyclePolicy , source );
587
+ }
588
+ return null ;
583
589
}
584
590
585
- private void addInBitmapOptions (InputStreamProvider ip , BitmapFactory .Options opts ) {
591
+ private boolean addInBitmapOptions (InputStreamProvider ip , BitmapFactory .Options opts ) {
586
592
// Create InputStream for decoding the bounds
587
593
final InputStream is = ip .getInputStream ();
588
594
// Decode the bounds so we know what size Bitmap to look for
@@ -602,7 +608,10 @@ private void addInBitmapOptions(InputStreamProvider ip, BitmapFactory.Options op
602
608
Log .i (Constants .LOG_TAG , "Using inBitmap" );
603
609
}
604
610
SDK11 .addInBitmapOption (opts , reusableBm );
611
+ return true ;
605
612
}
613
+
614
+ return false ;
606
615
}
607
616
608
617
/**
0 commit comments