@@ -0,0 +1,1365 @@
+/*%0A * BitmapCache.java%0A *%0A * Author: Ming Tsang%0A * Copyright (c) 2015 Ming Tsang%0A * Refer to LICENSE for details%0A */%0A%0Apackage com.nkming.utils.graphic;%0A%0Aimport android.annotation.TargetApi;%0Aimport android.graphics.Bitmap;%0Aimport android.os.Build;%0Aimport android.support.v4.util.LruCache;%0A%0Apublic class BitmapCache%0A%7B%0A%09public static void init(int cacheSize)%0A%09%7B%0A%09%09mInstance = new BitmapCache(cacheSize);%0A%09%7D%0A%0A%09public static void putBitmap(String key, Bitmap bmp)%0A%09%7B%0A%09%09get().putBitmap_(key, bmp);%0A%09%7D%0A%0A%09public static Bitmap getBitmap(String key)%0A%09%7B%0A%09%09return get().getBitmap_(key);%0A%09%7D%0A%0A%09private BitmapCache(int cacheSize)%0A%09%7B%0A%09%09mCache = new LruCache(cacheSize)%0A%09%09%7B%0A%09%09%09@TargetApi(Build.VERSION_CODES.KITKAT)%0A%09%09%09@Override%0A%09%09%09protected int sizeOf(Object key, Object value)%0A%09%09%09%7B%0A%09%09%09%09if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.KITKAT)%0A%09%09%09%09%7B%0A%09%09%09%09%09return ((Bitmap)value).getAllocationByteCount();%0A%09%09%09%09%7D%0A%09%09%09%09else%0A%09%09%09%09%7B%0A%09%09%09%09%09return ((Bitmap)value).getByteCount();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%0A%09private static BitmapCache get()%0A%09%7B%0A%09%09if (mInstance == null)%0A%09%09%7B%0A%09%09%09throw new IllegalStateException(%22Must call init() first%22);%0A%09%09%7D%0A%09%09return mInstance;%0A%09%7D%0A%0A%09private void putBitmap_(String key, Bitmap bmp)%0A%09%7B%0A%09%09mCache.put(key, bmp);%0A%09%7D%0A%0A%09private Bitmap getBitmap_(String key)%0A%09%7B%0A%09%09return mCache.get(key);%0A%09%7D%0A%0A%09private LruCache%3CString, Bitmap%3E mCache;%0A%0A%09private static BitmapCache mInstance;%0A%7D%0A

Add class to handle a global bitmap cache