Пример #1
0
 public BitmapCacheContainer get(String key) {
   BitmapCacheContainer b = mCache.object(key);
   if (b != null && b.isRecycled()) {
     mCache.remove(key);
     return null;
   }
   return b;
 }
Пример #2
0
  public boolean isImageLoaded(String uri) {
    Bitmap btm = mBitmapContainer.get(uri);

    if (btm == null || btm.isRecycled()) {
      return false;
    }
    return true;
  }
Пример #3
0
 /** This method will clean the cache and will recycle all the bitmaps */
 public void purge() {
   if (DEBUG) {
     cacheLogD(mIdCache + "  --- Purguing all the images");
   }
   TaskExecutor.getInstance().cleanAllHistory();
   TaskExecutor.getInstance().removeAllQueuedTask();
   mBitmapContainer.purge();
   mLoadingResources.clear();
   System.gc();
 }
Пример #4
0
  /**
   * Get the Bitmap according to the uri. If it is not loaded, it try to load first.
   *
   * @param uri
   * @return
   */
  public Bitmap getBitmap(String uri) {

    // if (DEBUG) {
    // cacheLog(TAG, mIdCache + " * Requesting: " + uri);
    // }
    if (uri == null) {
      return null;
    }

    Bitmap btm = mBitmapContainer.get(uri);

    if (btm == null || btm.isRecycled()) {
      if (btm != null) {
        mBitmapContainer.remove(uri);
      }

      btm = loadBitmap(uri);
    }

    return btm;
  }
Пример #5
0
  /**
   * Store a bitmap with the name of the URI
   *
   * @param btm
   * @param uri
   * @return The bitmap stored
   */
  public Bitmap storeBitmap(String uri, Bitmap btm) {
    if (null != btm && null != uri) {
      if (mBitmapContainer.get(uri) != null) {
        if (DEBUG) {
          Log.w(
              TAG,
              mIdCache + "  = The image with the URI=" + uri + " already exist. Overwritting...");
        }
        // return btm;
      }

      mLoadingResources.put(uri, IMAGE_LOADED);
      mBitmapContainer.put(uri, btm);
      if (DEBUG) {
        cacheLogD(mIdCache + "  + Saving Bitmap: loadBitmap(ExBitmap btm): " + uri);
      }
    } else {
      if (DEBUG) {
        cacheLogE(mIdCache + "  = Trying to store a null bitmap for uri=" + uri);
      }
    }
    return btm;
  }
Пример #6
0
 public void add(String key, BitmapCacheContainer container) {
   if (container == null || container.isRecycled() || container.get() == null) return;
   BitmapCacheContainer old = mCache.object(key);
   if (old != null) {
     if (old.getLastUpdateTime() < container.getLastUpdateTime()) {
       mCache.remove(key);
     } else {
       Bitmap oldBmp = old.get();
       Bitmap newBmp = container.get();
       if (oldBmp != null
           && Math.max(oldBmp.getWidth(), oldBmp.getHeight())
               > Math.max(newBmp.getWidth(), newBmp.getHeight())) {
         return;
       }
     }
   }
   mCache.insert(key, container, container.getCost());
 }
Пример #7
0
  private Bitmap loadBitmap(int id) {
    String key = normalizeURI(id);
    Bitmap btm = mBitmapContainer.get(key);
    if (null != btm) {
      return (btm);
    }

    Options options = getOptimizedBitmapOption();
    if (options.inJustDecodeBounds) {
      BitmapFactory.decodeResource(mRes, id, options);
      options.inSampleSize = calculateInSampleSize(options, mMaxWidth, mMaxHeight);
      options.inJustDecodeBounds = false;
    }

    btm = DebugBitmap.decodeResource(mRes, id, options);

    return storeBitmap(key, btm);
  }
Пример #8
0
 public synchronized void removeBitmap(String uri) {
   mBitmapContainer.remove(uri);
   mLoadingResources.remove(uri);
 }
Пример #9
0
 /**
  * Clean the recycled Bitmaps stored in the cache.
  *
  * @return Return the number of recycled imaged founded in the cache.
  */
 public int cleanRecylcedBitmaps() {
   return mBitmapContainer.cleanRecycledBitmaps();
 }
Пример #10
0
 @Override
 protected void releaseObject(BitmapCacheContainer container) {
   container.recycle();
 }