// Path: app/src/main/java/com/camnter/easygank/widget/GlideCircleTransform.java
// public class GlideCircleTransform extends BitmapTransformation {
// 
//     public GlideCircleTransform(Context context) {
//         super(context);
//     }
// 
// 
//     @Override
//     protected Bitmap transform(BitmapPool pool, Bitmap inBitmap, int destWidth, int destHeight) {
//         if (inBitmap == null) return null;
// 
//         int size = Math.min(inBitmap.getWidth(), inBitmap.getHeight());
//         int x = (inBitmap.getWidth() - size) / 2;
//         int y = (inBitmap.getHeight() - size) / 2;
// 
//         Bitmap squared = Bitmap.createBitmap(inBitmap, x, y, size, size);
//         Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
//         if (result == null) {
//             result = Bitmap.createBitmap(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);
//         return result;
//     }
// 
// 
//     @Override public String getId() {
//         return getClass().getName();
//     }
// }


import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.camnter.easygank.R;
import com.camnter.easygank.widget.GlideCircleTransform;
import com.orhanobut.logger.Logger;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
                 .getSize((width, height) -> {
                     if (!view.isShown()) {
                         view.setVisibility(View.VISIBLE);
                     }
                 });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void displayCircleHeader(ImageView view, @DrawableRes int res) {
        // 不能崩
        if (view == null) {
            Logger.e("GlideUtils -> display -> imageView is null");
            return;
        }
        Context context = view.getContext();
        // View你还活着吗？
        if (context instanceof Activity) {
            if (((Activity) context).isFinishing()) {
                return;
            }
        }

        try {
            Glide.with(context)
                 .load(res)
                 .centerCrop()
                 .placeholder(R.mipmap.img_default_gray)
// Path: app/src/main/java/com/camnter/easygank/widget/GlideCircleTransform.java
// public class GlideCircleTransform extends BitmapTransformation {
// 
//     public GlideCircleTransform(Context context) {
//         super(context);
//     }
// 
// 
//     @Override
//     protected Bitmap transform(BitmapPool pool, Bitmap inBitmap, int destWidth, int destHeight) {
//         if (inBitmap == null) return null;
// 
//         int size = Math.min(inBitmap.getWidth(), inBitmap.getHeight());
//         int x = (inBitmap.getWidth() - size) / 2;
//         int y = (inBitmap.getHeight() - size) / 2;
// 
//         Bitmap squared = Bitmap.createBitmap(inBitmap, x, y, size, size);
//         Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
//         if (result == null) {
//             result = Bitmap.createBitmap(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);
//         return result;
//     }
// 
// 
//     @Override public String getId() {
//         return getClass().getName();
//     }
// }


// Path: app/src/main/java/com/camnter/easygank/utils/GlideUtils.java
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.camnter.easygank.R;
import com.camnter.easygank.widget.GlideCircleTransform;
import com.orhanobut.logger.Logger;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;

                 .getSize((width, height) -> {
                     if (!view.isShown()) {
                         view.setVisibility(View.VISIBLE);
                     }
                 });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void displayCircleHeader(ImageView view, @DrawableRes int res) {
        // 不能崩
        if (view == null) {
            Logger.e("GlideUtils -> display -> imageView is null");
            return;
        }
        Context context = view.getContext();
        // View你还活着吗？
        if (context instanceof Activity) {
            if (((Activity) context).isFinishing()) {
                return;
            }
        }

        try {
            Glide.with(context)
                 .load(res)
                 .centerCrop()
                 .placeholder(R.mipmap.img_default_gray)
                 .bitmapTransform(new GlideCircleTransform(context))