Ejemplo n.º 1
0
 /**
  * Get the bitmap from memory cache.
  *
  * @param uri Unique identifier for which item to get
  * @param config
  * @return The bitmap if found in cache, null otherwise
  */
 public Bitmap getBitmapFromMemCache(String uri, BitmapDisplayConfig config) {
   if (mMemoryCache != null && globalConfig.isMemoryCacheEnabled()) {
     MemoryCacheKey key = new MemoryCacheKey(uri, config);
     return mMemoryCache.get(key);
   }
   return null;
 }
Ejemplo n.º 2
0
 private void addBitmapToMemoryCache(
     String uri, BitmapDisplayConfig config, Bitmap bitmap, long expiryTimestamp)
     throws IOException {
   if (uri != null
       && bitmap != null
       && globalConfig.isMemoryCacheEnabled()
       && mMemoryCache != null) {
     MemoryCacheKey key = new MemoryCacheKey(uri, config);
     mMemoryCache.put(key, bitmap, expiryTimestamp);
   }
 }
Ejemplo n.º 3
0
  /** Initialize the memory cache */
  public void initMemoryCache() {
    if (!globalConfig.isMemoryCacheEnabled()) return;

    // Set up memory cache
    if (mMemoryCache != null) {
      try {
        clearMemoryCache();
      } catch (Throwable e) {
      }
    }
    mMemoryCache =
        new LruMemoryCache<MemoryCacheKey, Bitmap>(globalConfig.getMemoryCacheSize()) {
          /**
           * Measure item size in bytes rather than units which is more practical for a bitmap cache
           */
          @Override
          protected int sizeOf(MemoryCacheKey key, Bitmap bitmap) {
            if (bitmap == null) return 0;
            return bitmap.getRowBytes() * bitmap.getHeight();
          }
        };
  }