/**
  * Notifies the drawable that it's displayed state has changed.
  *
  * @param drawable
  * @param isDisplayed
  */
 private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
   if (drawable instanceof RecyclingBitmapDrawable) {
     // The drawable is a CountingBitmapDrawable, so notify it
     ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
   } else if (drawable instanceof LayerDrawable) {
     // The drawable is a LayerDrawable, so recurse on each layer
     LayerDrawable layerDrawable = (LayerDrawable) drawable;
     for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
       notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
     }
   }
 }
  /**
   * Adds a bitmap to both memory and disk cache.
   *
   * @param data Unique identifier for the bitmap to store
   * @param value The bitmap drawable to store
   */
  public void addBitmapToCache(String data, BitmapDrawable value) {
    // BEGIN_INCLUDE(add_bitmap_to_cache)
    if (data == null || value == null) {
      return;
    }

    // Add to memory cache
    if (mMemoryCache != null) {
      if (RecyclingBitmapDrawable.class.isInstance(value)) {
        // The removed entry is a recycling drawable, so notify it
        // that it has been added into the memory cache
        ((RecyclingBitmapDrawable) value).setIsCached(true);
      }
      mMemoryCache.put(data, value);
    }

    synchronized (mDiskCacheLock) {
      // Add to disk cache
      if (mDiskLruCache != null) {
        final String key = hashKeyForDisk(data);
        OutputStream out = null;
        try {
          DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key);
          if (snapshot == null) {
            final DiskLruCache.Editor editor = mDiskLruCache.edit(key);
            if (editor != null) {
              out = editor.newOutputStream(DISK_CACHE_INDEX);
              value
                  .getBitmap()
                  .compress(mCacheParams.compressFormat, mCacheParams.compressQuality, out);
              editor.commit();
              out.close();
            }
          } else {
            snapshot.getInputStream(DISK_CACHE_INDEX).close();
          }
        } catch (final IOException e) {
          Log.e(TAG, "addBitmapToCache - " + e);
        } catch (Exception e) {
          Log.e(TAG, "addBitmapToCache - " + e);
        } finally {
          try {
            if (out != null) {
              out.close();
            }
          } catch (IOException e) {
          }
        }
      }
    }
    // END_INCLUDE(add_bitmap_to_cache)
  }
  /**
   * Adds a bitmap to both memory and disk cache.
   *
   * @param data Unique identifier for the bitmap to store
   * @param value The bitmap drawable to store
   */
  public void addBitmapToCache(String data, BitmapDrawable value) {
    // BEGIN_INCLUDE(add_bitmap_to_cache)
    if (data == null || value == null) {
      return;
    }

    // Add to memory cache
    if (mMemoryCache != null) {
      if (RecyclingBitmapDrawable.class.isInstance(value)) {
        // The removed entry is a recycling drawable, so notify it
        // that it has been added into the memory cache
        ((RecyclingBitmapDrawable) value).setIsCached(true);
      }
      mMemoryCache.put(data, value);
    }
  }
  private void addBitmapToCache(String key, BitmapDrawable drawable) {
    if (drawable != null && getBitmapFromCache(key) == null) {
      if (RecyclingBitmapDrawable.class.isInstance(drawable)) {
        ((RecyclingBitmapDrawable) drawable).setIsCached(true);
      }
      mMemoryCache.put(key, drawable);
      Log.d(TAG, "cache size: " + mMemoryCache.size());
    }

    Log.d(
        TAG,
        "cache: number of puts: "
            + mMemoryCache.putCount()
            + ", number of evicts: "
            + mMemoryCache.evictionCount());
  }