コード例 #1
0
ファイル: BitmapCache.java プロジェクト: hellosmile/xUtils
 /**
  * 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;
 }
コード例 #2
0
ファイル: BitmapCache.java プロジェクト: hellosmile/xUtils
 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);
   }
 }
コード例 #3
0
ファイル: BitmapCache.java プロジェクト: hellosmile/xUtils
  /** 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();
          }
        };
  }