// Path: utilslibrary/src/main/java/com/devin/UtilManager.java
// public class UtilManager {
// 
//     private static Context mContext;
// 
//     /**
//      * 初始化工具类集合
//      * @param context  context
//      */
//     public static void init(Context context) {
//         mContext = context.getApplicationContext();
//     }
// 
//     public static Context getContext() {
//         return mContext;
//     }
// }
// 
// Path: utilslibrary/src/main/java/com/devin/glide/GlideCircleTransform.java
// public class GlideCircleTransform extends BitmapTransformation {
// 
//     private Paint mBorderPaint;
//     private float mBorderWidth;
// 
//     public GlideCircleTransform() {
//         super();
//     }
// 
//     public GlideCircleTransform(int borderWidth, int borderColor) {
//         super();
//         mBorderWidth = Resources.getSystem().getDisplayMetrics().density * borderWidth;
// 
//         mBorderPaint = new Paint();
//         mBorderPaint.setDither(true);
//         mBorderPaint.setAntiAlias(true);
//         mBorderPaint.setColor(borderColor);
//         mBorderPaint.setStyle(Paint.Style.STROKE);
//         mBorderPaint.setStrokeWidth(mBorderWidth);
//     }
// 
// 
//     @Override
//     protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
//         return circleCrop(pool, toTransform);
//     }
// 
//     private Bitmap circleCrop(BitmapPool pool, Bitmap source) {
//         if (source == null) {
//             return null;
//         }
// 
//         int size = (int) (Math.min(source.getWidth(), source.getHeight()) - (mBorderWidth / 2));
//         int x = (source.getWidth() - size) / 2;
//         int y = (source.getHeight() - size) / 2;
// 
//         Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
//         Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
//         Canvas canvas = new Canvas(result);
//         Paint paint = new Paint();
//         paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
//         paint.setAntiAlias(true);
//         float r = size / 2f;
//         canvas.drawCircle(r, r, r, paint);
//         if (mBorderPaint != null) {
//             float borderRadius = r - mBorderWidth / 2;
//             canvas.drawCircle(r, r, borderRadius, mBorderPaint);
//         }
//         return result;
//     }
// 
// 
//     @Override
//     public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
// 
//     }
// }
// 
// Path: utilslibrary/src/main/java/com/devin/glide/GlideRoundTransform.java
// public class GlideRoundTransform extends CenterCrop {
//     private float radius;
// 
// 
//     public GlideRoundTransform(int dp) {
//         super();
//         this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
// 
//     }
// 
//     @Override
//     protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
//         Bitmap transform = super.transform(pool, toTransform, outWidth, outHeight);
//         return roundCrop(pool, transform);
//     }
// 
//     private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
//         if (source == null) {
//             return null;
//         }
//         Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
//         Canvas canvas = new Canvas(result);
//         Paint paint = new Paint();
//         paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
//         paint.setAntiAlias(true);
//         RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
//         canvas.drawRoundRect(rectF, radius, radius, paint);
//         return result;
//     }
// 
// 
//     @Override
//     public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
// 
//     }
// }


import android.content.Context;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.devin.UtilManager;
import com.devin.glide.GlideCircleTransform;
import com.devin.glide.GlideRoundTransform;
    /**
     * 加载URI
     *
     * @param context
     * @param uri
     * @param imageView
     */
    public static void loadUri(Context context, Uri uri, @DrawableRes int placeholder, ImageView imageView) {

        RequestOptions requestOptions =
                new RequestOptions()
                        .placeholder(placeholder)
                        .error(placeholder);

        Glide.with(context)
                .load(uri)
                .apply(requestOptions)
                .into(imageView);
    }


    //======================================================================

    /**
     * 加载图片
     *
     * @param imgUrl
     * @param imageView
     */
    public static void load(String imgUrl, ImageView imageView) {
// Path: utilslibrary/src/main/java/com/devin/UtilManager.java
// public class UtilManager {
// 
//     private static Context mContext;
// 
//     /**
//      * 初始化工具类集合
//      * @param context  context
//      */
//     public static void init(Context context) {
//         mContext = context.getApplicationContext();
//     }
// 
//     public static Context getContext() {
//         return mContext;
//     }
// }
// 
// Path: utilslibrary/src/main/java/com/devin/glide/GlideCircleTransform.java
// public class GlideCircleTransform extends BitmapTransformation {
// 
//     private Paint mBorderPaint;
//     private float mBorderWidth;
// 
//     public GlideCircleTransform() {
//         super();
//     }
// 
//     public GlideCircleTransform(int borderWidth, int borderColor) {
//         super();
//         mBorderWidth = Resources.getSystem().getDisplayMetrics().density * borderWidth;
// 
//         mBorderPaint = new Paint();
//         mBorderPaint.setDither(true);
//         mBorderPaint.setAntiAlias(true);
//         mBorderPaint.setColor(borderColor);
//         mBorderPaint.setStyle(Paint.Style.STROKE);
//         mBorderPaint.setStrokeWidth(mBorderWidth);
//     }
// 
// 
//     @Override
//     protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
//         return circleCrop(pool, toTransform);
//     }
// 
//     private Bitmap circleCrop(BitmapPool pool, Bitmap source) {
//         if (source == null) {
//             return null;
//         }
// 
//         int size = (int) (Math.min(source.getWidth(), source.getHeight()) - (mBorderWidth / 2));
//         int x = (source.getWidth() - size) / 2;
//         int y = (source.getHeight() - size) / 2;
// 
//         Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
//         Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
//         Canvas canvas = new Canvas(result);
//         Paint paint = new Paint();
//         paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
//         paint.setAntiAlias(true);
//         float r = size / 2f;
//         canvas.drawCircle(r, r, r, paint);
//         if (mBorderPaint != null) {
//             float borderRadius = r - mBorderWidth / 2;
//             canvas.drawCircle(r, r, borderRadius, mBorderPaint);
//         }
//         return result;
//     }
// 
// 
//     @Override
//     public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
// 
//     }
// }
// 
// Path: utilslibrary/src/main/java/com/devin/glide/GlideRoundTransform.java
// public class GlideRoundTransform extends CenterCrop {
//     private float radius;
// 
// 
//     public GlideRoundTransform(int dp) {
//         super();
//         this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
// 
//     }
// 
//     @Override
//     protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
//         Bitmap transform = super.transform(pool, toTransform, outWidth, outHeight);
//         return roundCrop(pool, transform);
//     }
// 
//     private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
//         if (source == null) {
//             return null;
//         }
//         Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
//         Canvas canvas = new Canvas(result);
//         Paint paint = new Paint();
//         paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
//         paint.setAntiAlias(true);
//         RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
//         canvas.drawRoundRect(rectF, radius, radius, paint);
//         return result;
//     }
// 
// 
//     @Override
//     public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
// 
//     }
// }


// Path: utilslibrary/src/main/java/com/devin/util/ImageLoader.java
import android.content.Context;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.devin.UtilManager;
import com.devin.glide.GlideCircleTransform;
import com.devin.glide.GlideRoundTransform;

    /**
     * 加载URI
     *
     * @param context
     * @param uri
     * @param imageView
     */
    public static void loadUri(Context context, Uri uri, @DrawableRes int placeholder, ImageView imageView) {

        RequestOptions requestOptions =
                new RequestOptions()
                        .placeholder(placeholder)
                        .error(placeholder);

        Glide.with(context)
                .load(uri)
                .apply(requestOptions)
                .into(imageView);
    }


    //======================================================================

    /**
     * 加载图片
     *
     * @param imgUrl
     * @param imageView
     */
    public static void load(String imgUrl, ImageView imageView) {
        load(UtilManager.getContext(), imgUrl, imageView);