public boolean isImageLoaded(String uri) { Bitmap btm = mBitmapContainer.get(uri); if (btm == null || btm.isRecycled()) { return false; } return true; }
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()); }
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); }
/** * 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; }
/** * 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; }