// Path: library-lis/src/main/java/com/cocolover2/lis/utils/ImageCache.java
// public class ImageCache {
//     private static LruCache<String, Bitmap> mCache;
// 
//     private ImageCache() {
//     }
// 
//     public static LruCache<String, Bitmap> getInstance() {
//         if (mCache == null)
//             synchronized (ImageCache.class) {
//                 if (mCache == null)
//                     mCache = new LruCache<String, Bitmap>((int) Runtime.getRuntime().maxMemory() / 8) {
//                         @Override
//                         protected int sizeOf(String key, Bitmap value) {
//                             if (Build.VERSION.SDK_INT > 12)
//                                 return value.getByteCount();
//                             else
//                                 return value.getRowBytes() * value.getHeight();
//                         }
//                     };
//             }
//         return mCache;
//     }
// }
// 
// Path: library-lis/src/main/java/com/cocolover2/lis/utils/ImageUtils.java
// public class ImageUtils {
//     private ImageUtils() {
//         throw new UnsupportedOperationException("cannot be instantiated");
//     }
// 
//     /**
//      * 压缩图片的像素
//      *
//      * @param path
//      * @param requestWidth
//      * @param requestHeight
//      * @return
//      */
//     public static Bitmap compressImgBySize(String path, int requestWidth, int requestHeight) {
//         if (null == path || TextUtils.isEmpty(path) || !new File(path).exists())
//             return null;
//         //第一次解析图片的时候将inJustDecodeBounds设置为true,来获取图片的大小
//         BitmapFactory.Options options = new BitmapFactory.Options();
//         options.inJustDecodeBounds = true;
//         BitmapFactory.decodeFile(path, options);
//         options.inSampleSize = calculateInSampleSize(options, requestWidth, requestHeight);
//         options.inJustDecodeBounds = false;
//         return BitmapFactory.decodeFile(path, options);
//     }
// 
//     private static int calculateInSampleSize(BitmapFactory.Options options, int requestWidth, int requestHeight) {
//         int width = options.outWidth;
//         int height = options.outHeight;
//         int inSampleSize = 1;
//         if (width > requestWidth || height > requestHeight) {
//             final int heightRatio = Math.round((float) height / (float) requestHeight);
//             final int widthRatio = Math.round((float) width / (float) requestWidth);
//             inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
//         }
//         return inSampleSize;
//     }
// }


import android.graphics.Bitmap;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.widget.AbsListView;
import android.widget.ImageView;
import com.cocolover2.lis.utils.ImageCache;
import com.cocolover2.lis.utils.ImageUtils;
import java.util.LinkedList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
        if (mType == Type.FIFO) {
            return mTasks.removeFirst();
        } else if (mType == Type.LIFO) {
            return mTasks.removeLast();
        }
        return null;
    }

    /**
     * 单例获得该实例对象
     *
     * @return
     */
    public static LocalImageLoader getInstance(int threadCount, Type type) {

        if (mInstance == null) {
            synchronized (LocalImageLoader.class) {
                if (mInstance == null) {
                    mInstance = new LocalImageLoader(threadCount, type);
                }
            }
        }
        return mInstance;
    }


    /**
     * 从LruCache中获取一张图片，如果不存在就返回null。
     */
    private Bitmap getBitmapFromLruCache(String key) {
// Path: library-lis/src/main/java/com/cocolover2/lis/utils/ImageCache.java
// public class ImageCache {
//     private static LruCache<String, Bitmap> mCache;
// 
//     private ImageCache() {
//     }
// 
//     public static LruCache<String, Bitmap> getInstance() {
//         if (mCache == null)
//             synchronized (ImageCache.class) {
//                 if (mCache == null)
//                     mCache = new LruCache<String, Bitmap>((int) Runtime.getRuntime().maxMemory() / 8) {
//                         @Override
//                         protected int sizeOf(String key, Bitmap value) {
//                             if (Build.VERSION.SDK_INT > 12)
//                                 return value.getByteCount();
//                             else
//                                 return value.getRowBytes() * value.getHeight();
//                         }
//                     };
//             }
//         return mCache;
//     }
// }
// 
// Path: library-lis/src/main/java/com/cocolover2/lis/utils/ImageUtils.java
// public class ImageUtils {
//     private ImageUtils() {
//         throw new UnsupportedOperationException("cannot be instantiated");
//     }
// 
//     /**
//      * 压缩图片的像素
//      *
//      * @param path
//      * @param requestWidth
//      * @param requestHeight
//      * @return
//      */
//     public static Bitmap compressImgBySize(String path, int requestWidth, int requestHeight) {
//         if (null == path || TextUtils.isEmpty(path) || !new File(path).exists())
//             return null;
//         //第一次解析图片的时候将inJustDecodeBounds设置为true,来获取图片的大小
//         BitmapFactory.Options options = new BitmapFactory.Options();
//         options.inJustDecodeBounds = true;
//         BitmapFactory.decodeFile(path, options);
//         options.inSampleSize = calculateInSampleSize(options, requestWidth, requestHeight);
//         options.inJustDecodeBounds = false;
//         return BitmapFactory.decodeFile(path, options);
//     }
// 
//     private static int calculateInSampleSize(BitmapFactory.Options options, int requestWidth, int requestHeight) {
//         int width = options.outWidth;
//         int height = options.outHeight;
//         int inSampleSize = 1;
//         if (width > requestWidth || height > requestHeight) {
//             final int heightRatio = Math.round((float) height / (float) requestHeight);
//             final int widthRatio = Math.round((float) width / (float) requestWidth);
//             inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
//         }
//         return inSampleSize;
//     }
// }


// Path: library-lis/src/main/java/com/cocolover2/lis/LocalImageLoader.java
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.widget.AbsListView;
import android.widget.ImageView;
import com.cocolover2.lis.utils.ImageCache;
import com.cocolover2.lis.utils.ImageUtils;
import java.util.LinkedList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

        if (mType == Type.FIFO) {
            return mTasks.removeFirst();
        } else if (mType == Type.LIFO) {
            return mTasks.removeLast();
        }
        return null;
    }

    /**
     * 单例获得该实例对象
     *
     * @return
     */
    public static LocalImageLoader getInstance(int threadCount, Type type) {

        if (mInstance == null) {
            synchronized (LocalImageLoader.class) {
                if (mInstance == null) {
                    mInstance = new LocalImageLoader(threadCount, type);
                }
            }
        }
        return mInstance;
    }


    /**
     * 从LruCache中获取一张图片，如果不存在就返回null。
     */
    private Bitmap getBitmapFromLruCache(String key) {
        return ImageCache.getInstance().get(key_prefix + key);