package com.cocoahero.android.essentials.graphics;

import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

/**
 * This class is a specialized implementation of {@link android.util.LruCache}
 * designed for caching {@link Bitmap}s.
 * 
 * Instead of limiting the number of cached objects, it limits based on the
 * amount of memory used by the cached bitmaps.
 */
public class BitmapCache extends LruCache<String, Bitmap> {

	/**
	 * Constructs a new {@link BitmapCache} allowing you to specify the maximum
	 * amount of memory used by the cache.
	 * 
	 * @param bytes The maximum amount of memory in bytes this cache should use.
	 */
	public BitmapCache(int bytes) {
		super(bytes);
	}

	/**
	 * {@inheritDoc android.util.LruCache}
	 */
	@Override
	protected int sizeOf(String key, Bitmap bitmap) {
		return (bitmap.getRowBytes() * bitmap.getHeight());
	}

	/**
	 * A factory for creating a {@link BitmapCache} based on the application's
	 * memory class.
	 */
	public static class BitmapCacheFactory {

		/**
		 * Returns a new {@link BitmapCache} instance configured to use 1/8th of
		 * the application's memory class.
		 * 
		 * @param context
		 * @return a new {@link BitmapCache} instance configured to use 1/8th of
		 *         the application's memory class.
		 */
		public static BitmapCache getCache(Context context) {
			return getCache(context, 0.125f);
		}

		/**
		 * Returns a new {@link BitmapCache} instance configured to use the
		 * specified percentage of the application's memory class.
		 * 
		 * @param context
		 * @param percentage A floating value between 1.0f and 0.0f.
		 * @return a new {@link BitmapCache} instance configured to use the
		 *         given percentage of the application's memory class.
		 */
		public static BitmapCache getCache(Context context, float percentage) {
			ActivityManager mgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

			final int memoryClass = mgr.getMemoryClass();
			final int cacheSize = (int) (1048576 * memoryClass * percentage);

			return new BitmapCache(cacheSize);
		}

	}

}

@@ -504,22 +504,28 @@
 map%3E %7B%0A%0A
-%09/**%0A%09
+    /**%0A    
  * Const
@@ -592,17 +592,20 @@
 maximum%0A
-%09
+    
  * amoun
@@ -635,22 +635,28 @@
  cache.%0A
-%09 * %0A%09
+     * %0A    
  * @para
@@ -724,22 +724,28 @@
 ld use.%0A
-%09 */%0A%09
+     */%0A    
 public B
@@ -768,18 +768,24 @@
 ytes) %7B%0A
-%09%09
+        
 super(by
@@ -790,26 +790,35 @@
 bytes);%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * %7B@inh
@@ -848,22 +848,28 @@
 uCache%7D%0A
-%09 */%0A%09
+     */%0A    
 @Overrid
@@ -870,17 +870,20 @@
 verride%0A
-%09
+    
 protecte
@@ -924,18 +924,24 @@
 tmap) %7B%0A
-%09%09
+        
 return (
@@ -988,18 +988,27 @@
 ));%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * A
@@ -1078,17 +1078,20 @@
 ation's%0A
-%09
+    
  * memor
@@ -1099,22 +1099,28 @@
  class.%0A
-%09 */%0A%09
+     */%0A    
 public s
@@ -1153,24 +1153,36 @@
 tory %7B%0A%0A
-%09%09/**%0A%09%09
+        /**%0A        
  * Retur
@@ -1246,18 +1246,24 @@
 /8th of%0A
-%09%09
+        
  * the a
@@ -1285,32 +1285,44 @@
 mory class.%0A
-%09%09 * %0A%09%09
+         * %0A        
  * @param co
@@ -1323,26 +1323,32 @@
 ram context%0A
-%09%09
+        
  * @return a
@@ -1408,18 +1408,24 @@
 /8th of%0A
-%09%09
+        
  *      
@@ -1455,32 +1455,44 @@
 mory class.%0A
-%09%09 */%0A%09%09
+         */%0A        
 public stati
@@ -1533,19 +1533,28 @@
 text) %7B%0A
-%09%09%09
+            
 return g
@@ -1583,21 +1583,39 @@
 f);%0A
-%09%09%7D%0A%0A%09%09/**%0A%09%09
+        %7D%0A%0A        /**%0A        
  * R
@@ -1678,18 +1678,24 @@
 use the%0A
-%09%09
+        
  * speci
@@ -1749,16 +1749,28 @@
 ss.%0A
-%09%09 * %0A%09%09
+         * %0A        
  * @
@@ -1783,18 +1783,24 @@
 context%0A
-%09%09
+        
  * @para
@@ -1852,18 +1852,24 @@
 d 0.0f.%0A
-%09%09
+        
  * @retu
@@ -1928,18 +1928,24 @@
 use the%0A
-%09%09
+        
  *      
@@ -2003,16 +2003,28 @@
 ss.%0A
-%09%09 */%0A%09%09
+         */%0A        
 publ
@@ -2091,19 +2091,28 @@
 tage) %7B%0A
-%09%09%09
+            
 Activity
@@ -2196,19 +2196,28 @@
 VICE);%0A%0A
-%09%09%09
+            
 final in
@@ -2254,19 +2254,28 @@
 lass();%0A
-%09%09%09
+            
 final in
@@ -2337,11 +2337,20 @@
 );%0A%0A
-%09%09%09
+            
 retu
@@ -2384,14 +2384,23 @@
 e);%0A
-%09%09%7D%0A%0A%09
+        %7D%0A%0A    
 %7D%0A%0A%7D

Replace tabs with spaces