BitmapCache

package com.zcs.fast.forward.utils;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;

public class BitmapCache implements ImageCache {
	private static LruCache<String, Bitmap> mCache;

	public BitmapCache() {
		if (mCache == null) {
			LogUtil.i(VolleyUtil.TAG, "***Init The BitmapCache");
			int maxSize = 10 * 1024 * 1024;
			mCache = new LruCache<String, Bitmap>(maxSize) {
				@Override
				protected int sizeOf(String key, Bitmap value) {
					return value.getRowBytes() * value.getHeight();
				}
			};
		}
	}

	@Override
	public Bitmap getBitmap(String url) {
		return mCache.get(url);
	}

	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		mCache.put(url, bitmap);
		LogUtil.i(VolleyUtil.TAG, "put:BitmapCache size:" + mCache.size());
	}

}

  

posted @ 2014-11-24 18:11  丿顺丨逐风者  阅读(320)  评论(0)    收藏  举报