// Path: library/src/main/java/com/onegravity/contactpicker/Helper.java
// public class Helper {
// 
//     public static boolean isNullOrEmpty(CharSequence string){
//         return string == null || string.length() == 0;
//     }
// 
//     public static DisplayMetrics getDisplayMetrics(Context context) {
//         Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
//         DisplayMetrics metrics = new DisplayMetrics();
//         display.getMetrics( metrics );
//         return metrics;
//     }
// 
//     public static void closeQuietly(Cursor cursor) {
//         try {
//             cursor.close();
//         }
//         catch (Exception ignore) {}
//     }
// 
//     public static void closeQuietly(Closeable closeable) {
//         try {
//             if (closeable != null) {
//                 closeable.close();
//             }
//         } catch (IOException ignore) {}
//     }
// 
// }
// 
// Path: library/src/main/java/com/onegravity/contactpicker/picture/cache/ContactPictureCache.java
// public class ContactPictureCache extends InMemoryCache<Uri, Bitmap> {
// 
//     private static ContactPictureCache sInstance;
//     private static int sMemClass;
// 
//     // we need to synchronize this to make sure there's no race condition instantiating the cache
//     public synchronized static ContactPictureCache getInstance(Context context) {
//         if (sInstance == null) {
//             ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//             sMemClass = activityManager.getMemoryClass();
//             sInstance = new ContactPictureCache();
//         }
//         return sInstance;
//     }
// 
//     private ContactPictureCache() {
//         // purge after 5 minutes of being idle, the cacheCapacity parameter is ignored
//         super(1000 * 60 * 5, 50);
//     }
// 
//     @Override
//     protected HardLruCache createHardLruCache(int cacheCapacity) {
//         // Use 1/16th of the available memory for this memory cache.
//         final int cacheSize = 1024 * 1024 * sMemClass / 16;
//         return new PhotoHardLruCache(cacheSize);
//     }
// 
//     private class PhotoHardLruCache extends HardLruCache {
//         public PhotoHardLruCache(int initialCapacity) {
//             super(initialCapacity);
//         }
// 
//         @Override
//         protected int sizeOf(Uri key, Bitmap bitmap) {
//             // The cache size will be measured in bytes rather than number of items.
//             return bitmap.getByteCount();
//         }
//     }
// }


import java.io.InputStream;
import java.lang.ref.SoftReference;
import static android.graphics.Bitmap.createBitmap;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.net.Uri;
import com.onegravity.contactpicker.Helper;
import com.onegravity.contactpicker.picture.cache.ContactPictureCache;
import java.io.FileNotFoundException;

        // read contact picture
        try {
            stream = context.getContentResolver().openInputStream(photoUri);
            bitmap = BitmapFactory.decodeStream(stream);

            if (bitmap != null) {
                // some contact pictures aren't square...
                if (bitmap.getWidth() != bitmap.getHeight()) {
                    int w = bitmap.getWidth();
                    int h = bitmap.getHeight();
                    int indent = Math.abs(w - h) / 2;
                    int x = w > h ? indent : 0;
                    int y = w < h ? indent : 0;
                    int size = Math.min(w, h);
                    bitmap = createBitmap(bitmap, x, y, size, size);
                }

                if (roundContactPictures) {
                    bitmap = getRoundedBitmap(bitmap);
                }
            }
        }
        catch (OutOfMemoryError | FileNotFoundException ignore) {}
        finally {
            Helper.closeQuietly(stream);
        }

        // cache contact picture
        if (bitmap != null) {
// Path: library/src/main/java/com/onegravity/contactpicker/Helper.java
// public class Helper {
// 
//     public static boolean isNullOrEmpty(CharSequence string){
//         return string == null || string.length() == 0;
//     }
// 
//     public static DisplayMetrics getDisplayMetrics(Context context) {
//         Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
//         DisplayMetrics metrics = new DisplayMetrics();
//         display.getMetrics( metrics );
//         return metrics;
//     }
// 
//     public static void closeQuietly(Cursor cursor) {
//         try {
//             cursor.close();
//         }
//         catch (Exception ignore) {}
//     }
// 
//     public static void closeQuietly(Closeable closeable) {
//         try {
//             if (closeable != null) {
//                 closeable.close();
//             }
//         } catch (IOException ignore) {}
//     }
// 
// }
// 
// Path: library/src/main/java/com/onegravity/contactpicker/picture/cache/ContactPictureCache.java
// public class ContactPictureCache extends InMemoryCache<Uri, Bitmap> {
// 
//     private static ContactPictureCache sInstance;
//     private static int sMemClass;
// 
//     // we need to synchronize this to make sure there's no race condition instantiating the cache
//     public synchronized static ContactPictureCache getInstance(Context context) {
//         if (sInstance == null) {
//             ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//             sMemClass = activityManager.getMemoryClass();
//             sInstance = new ContactPictureCache();
//         }
//         return sInstance;
//     }
// 
//     private ContactPictureCache() {
//         // purge after 5 minutes of being idle, the cacheCapacity parameter is ignored
//         super(1000 * 60 * 5, 50);
//     }
// 
//     @Override
//     protected HardLruCache createHardLruCache(int cacheCapacity) {
//         // Use 1/16th of the available memory for this memory cache.
//         final int cacheSize = 1024 * 1024 * sMemClass / 16;
//         return new PhotoHardLruCache(cacheSize);
//     }
// 
//     private class PhotoHardLruCache extends HardLruCache {
//         public PhotoHardLruCache(int initialCapacity) {
//             super(initialCapacity);
//         }
// 
//         @Override
//         protected int sizeOf(Uri key, Bitmap bitmap) {
//             // The cache size will be measured in bytes rather than number of items.
//             return bitmap.getByteCount();
//         }
//     }
// }


// Path: library/src/main/java/com/onegravity/contactpicker/picture/ContactPictureLoader.java
import java.io.InputStream;
import java.lang.ref.SoftReference;
import static android.graphics.Bitmap.createBitmap;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.net.Uri;
import com.onegravity.contactpicker.Helper;
import com.onegravity.contactpicker.picture.cache.ContactPictureCache;
import java.io.FileNotFoundException;


        // read contact picture
        try {
            stream = context.getContentResolver().openInputStream(photoUri);
            bitmap = BitmapFactory.decodeStream(stream);

            if (bitmap != null) {
                // some contact pictures aren't square...
                if (bitmap.getWidth() != bitmap.getHeight()) {
                    int w = bitmap.getWidth();
                    int h = bitmap.getHeight();
                    int indent = Math.abs(w - h) / 2;
                    int x = w > h ? indent : 0;
                    int y = w < h ? indent : 0;
                    int size = Math.min(w, h);
                    bitmap = createBitmap(bitmap, x, y, size, size);
                }

                if (roundContactPictures) {
                    bitmap = getRoundedBitmap(bitmap);
                }
            }
        }
        catch (OutOfMemoryError | FileNotFoundException ignore) {}
        finally {
            Helper.closeQuietly(stream);
        }

        // cache contact picture
        if (bitmap != null) {
            ContactPictureCache.getInstance(context).put(photoUri, bitmap);