前言
刚接触Glide,此处做个笔记,内容仅作参考,可能会有不完善或不正确的地方,若有修改,会即时更新
步骤
1、在gradle中引入Glide
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp-integration:1.3.1'
2、创建一个GlideModule类,用于自定义配置信息
/**
* Description:自定义Glide的配置,这些配置将会在第一个Glide请求发起的时候被调用
* <p>
* Time: 2017/4/10 0005
*/
public class GlidePicModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
String internalCachePath = "glide_cache";
//设置格式
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
//缓存到data目录下最大50M
//缓存目录为程序内部缓存目录/data/data/your_package_name/glide_cache/(不能被其它应用访问)且缓存最大为250MB
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, internalCachePath,DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
//设置内存缓存大小
//MemoryCache和BitmapPool的默认大小由MemorySizeCalculator类决定,MemorySizeCalculator会根据给定屏幕大小可用内存算出合适的缓存大小,这也是推荐的缓存大小
// 目前根据这个推荐大小做出调整,推荐大小乘以1.2倍
MemorySizeCalculator calculator = new MemorySizeCalculator(context);
int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
@Override
public void registerComponents(Context context, Glide glide) {
//采用Glide结合OkHttp的方式
glide.register(GlideUrl.class,InputStream.class, new OkHttpUrlLoader.Factory(new OkHttpClient()));
}
}
3、添加混淆
-keepnames class com.mypackage.MyGlideModule
-keep class com.bumptech.glide.integration.okhttp3.OkHttpGlideModule
# or more generally:
#-keep public class * implements com.bumptech.glide.module.GlideModule
4、manifest中添加
<meta-data
android:name="${applicationId}.util.glide.GlidePicModule"
android:value="GlideModule"/>
5、由于Glide可以转换图片效果,所以在此列出几个转换类
/**
* Description:将图片转换成圆形
* <p>
* Time: 2017/4/10 0006
*/
public class TransformCircle extends BitmapTransformation {
public TransformCircle(Context context) {
super(context);
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return circleCrop(pool, toTransform);
}
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null)
return null;
int size = Math.min(source.getWidth(), source.getHeight());
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);
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();
}
}
/**
* Description:将图片转换成圆角图片
* <p>
* Time: 2017/4/10 0007
*/
public class TransformRound extends BitmapTransformation {
private float radius = 0f;
public TransformRound(Context context) {
this(context, 4);
}
public TransformRound(Context context, int dp) {
super(context);
radius = Resources.getSystem().getDisplayMetrics().density * dp;
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return roundCrop(pool, toTransform);
}
private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(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 String getId() {
return getClass().getName() + Math.round(radius);
}
}
/**
* Description:将图片转换成模糊图片
* <p>
* Time: 2017/4/10 0008
*/
public class TransformBlur implements Transformation<Bitmap> {
public static int MAX_RADIUS = 25;
private Context mContext;
private BitmapPool mBitmapPool;
private int mRadius;
public TransformBlur(Context context, BitmapPool pool) {
this(context, pool, MAX_RADIUS);
}
public TransformBlur(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius);
}
public TransformBlur(Context context, BitmapPool pool, int radius) {
mContext = context;
mBitmapPool = pool;
this.mRadius = radius;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
if (Build.VERSION.SDK_INT > 16) {
Bitmap bitmap = source.copy(source.getConfig(), true);
final RenderScript rs = RenderScript.create(mContext);
final Allocation input = Allocation.createFromBitmap(rs, source,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(mRadius /* e.g. 3.f */);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
Bitmap bitmap = source.copy(source.getConfig(), true);
if (mRadius < 1) {
return (null);
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int[] pix = new int[w * h];
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = mRadius + mRadius + 1;
int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
int vmin[] = new int[Math.max(w, h)];
int divsum = (div + 1) >> 1;
divsum *= divsum;
int dv[] = new int[256 * divsum];
for (i = 0; i < 256 * divsum; i++) {
dv[i] = (i / divsum);
}
yw = yi = 0;
int[][] stack = new int[div][3];
int stackpointer;
int stackstart;
int[] sir;
int rbs;
int r1 = mRadius + 1;
int routsum, goutsum, boutsum;
int rinsum, ginsum, binsum;
for (y = 0; y < h; y++) {
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
for (i = -mRadius; i <= mRadius; i++) {
p = pix[yi + Math.min(wm, Math.max(i, 0))];
sir = stack[i + mRadius];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rbs = r1 - Math.abs(i);
rsum += sir[0] * rbs;
gsum += sir[1] * rbs;
bsum += sir[2] * rbs;
if (i > 0) {
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
}
stackpointer = mRadius;
for (x = 0; x < w; x++) {
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - mRadius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (y == 0) {
vmin[x] = Math.min(x + mRadius + 1, wm);
}
p = pix[yw + vmin[x]];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[(stackpointer) % div];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi++;
}
yw += w;
}
for (x = 0; x < w; x++) {
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
yp = -mRadius * w;
for (i = -mRadius; i <= mRadius; i++) {
yi = Math.max(0, yp) + x;
sir = stack[i + mRadius];
sir[0] = r[yi];
sir[1] = g[yi];
sir[2] = b[yi];
rbs = r1 - Math.abs(i);
rsum += r[yi] * rbs;
gsum += g[yi] * rbs;
bsum += b[yi] * rbs;
if (i > 0) {
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
if (i < hm) {
yp += w;
}
}
yi = x;
stackpointer = mRadius;
for (y = 0; y < h; y++) {
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - mRadius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (x == 0) {
vmin[y] = Math.min(y + r1, hm) * w;
}
p = x + vmin[y];
sir[0] = r[p];
sir[1] = g[p];
sir[2] = b[p];
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[stackpointer];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi += w;
}
}
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "BlurTransformation(radius=" + mRadius + ")";
}
}
6、封装一个使用Glide的工具类
/**
* 使用Glide加载图片要注意以下几点:
* 1、ScaleType不要用fixXY
* 2、setTag不要直接设置在ImageView上,要设置在其父布局上
* 3、列表在滑动的时候,可以调用pauseRequests()取消请求,滑动停止时,调用resumeRequests()恢复请求
*/
/**
* Description:Glide处理图片管理类
* <p>
* Time: 2017/4/10 0010
*/
public class GlideUtils {
public final static int FILLET_10 = 10;//圆角角度 10度
/****************************1、以下 圆形头像******************************/
/**
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
*/
public static void loadCirleAvatar(Context context,String string, ImageView tartgetIv) {
loadCirleAvatar(context,string,0,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadCirleAvatar(Context context,String string, ImageView tartgetIv,int w,int h) {
loadCirleAvatar(context,string,0,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
*/
public static void loadCirleAvatar(Context context,Integer resourceId, ImageView tartgetIv) {
loadCirleAvatar(context,"",resourceId,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadCirleAvatar(Context context,Integer resourceId, ImageView tartgetIv,int w,int h) {
loadCirleAvatar(context,"",resourceId,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
*/
public static void loadCirleAvatar(Context context,File file, ImageView tartgetIv) {
loadCirleAvatar(context,"",0,file,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadCirleAvatar(Context context,File file, ImageView tartgetIv,int w,int h) {
loadCirleAvatar(context,"",0,file,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
*/
public static void loadCirleAvatar(Context context,Uri uri, ImageView tartgetIv) {
loadCirleAvatar(context,"",0,null,uri,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadCirleAvatar(Context context,Uri uri, ImageView tartgetIv,int w,int h) {
loadCirleAvatar(context,"",0,null,uri,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
*/
public static void loadCirleAvatar(Context context,byte[] model, ImageView tartgetIv) {
loadCirleAvatar(context,"",0,null,null,model,tartgetIv,0,0);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadCirleAvatar(Context context,byte[] model, ImageView tartgetIv,int w,int h) {
loadCirleAvatar(context,"",0,null,null,model,tartgetIv,w,h);
}
/**
* 加载圆形图片(以头像为例)
* 以下1-5个来源中,每次只能有一个有值
*
* @param context
* @param string 来源 1
* @param resourceId 来源 2
* @param file 来源 3
* @param uri 来源 4
* @param model 来源 5
* @param targetIv
* @param w
* @param h
*/
private static void loadCirleAvatar(Context context,String string,Integer resourceId,File file,Uri uri,byte[] model,ImageView targetIv,int w,int h){
//来源于String
if (!StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformCircle(context))
.into(targetIv);
}else {
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.transform(new TransformCircle(context))
.into(targetIv);
}
}
//来源于Integer
else if (resourceId!=0&&StringTools.isEmpty(string)&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformCircle(context))
.into(targetIv);
}else {
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.transform(new TransformCircle(context))
.into(targetIv);
}
}
//来源于File
else if (file!=null&&StringTools.isEmpty(string)&&resourceId==0&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformCircle(context))
.into(targetIv);
}else {
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.transform(new TransformCircle(context))
.into(targetIv);
}
}
//来源于Uri
else if (uri!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformCircle(context))
.into(targetIv);
}else {
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.transform(new TransformCircle(context))
.into(targetIv);
}
}
//来源于byte[]
else if (model!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformCircle(context))
.into(targetIv);
}else {
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_default)
.error(R.drawable.bg_avatar_default)
.centerCrop()
.crossFade()
.transform(new TransformCircle(context))
.into(targetIv);
}
}
}
/****************************以上 圆形头像******************************/
/****************************2、以下 圆角头像******************************/
/**
* 圆角为10
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatar10(Context context,String string, ImageView tartgetIv) {
loadRoundAvatar(context,string,0,null,null,null,tartgetIv,0,0,FILLET_10);
}
/**
* 自定义圆角大小
* @param context
* @param string 图片来源为String
* @param fillet 圆角大小
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatarCustom(Context context,String string, int fillet,ImageView tartgetIv) {
loadRoundAvatar(context,string,0,null,null,null,tartgetIv,0,0,fillet);
}
/**
*
* 圆角为10
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatar10(Context context,String string, ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,string,0,null,null,null,tartgetIv,w,h,FILLET_10);
}
/**
*
* 自定义圆角大小
* @param context
* @param string 图片来源为String
* @param fillet 圆角大小
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatarCustom(Context context,String string, int fillet,ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,string,0,null,null,null,tartgetIv,w,h,fillet);
}
/**
*
* 圆角为10
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatar10(Context context,Integer resourceId, ImageView tartgetIv) {
loadRoundAvatar(context,"",resourceId,null,null,null,tartgetIv,0,0,FILLET_10);
}
/**
* 自定义圆角大小
* @param context
* @param resourceId 图片来源为Integer
* @param fillet 圆角大小
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatarCustom(Context context,Integer resourceId,int fillet, ImageView tartgetIv) {
loadRoundAvatar(context,"",resourceId,null,null,null,tartgetIv,0,0,fillet);
}
/**
*
* 圆角为10
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatar10(Context context,Integer resourceId, ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",resourceId,null,null,null,tartgetIv,w,h,FILLET_10);
}
/**
*
* 自定义圆角大小
* @param context
* @param resourceId 图片来源为Integer
* @param fillet 圆角大小
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatarCustom(Context context,Integer resourceId, int fillet,ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",resourceId,null,null,null,tartgetIv,w,h,fillet);
}
/**
*
* 圆角为10
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatar10(Context context,File file, ImageView tartgetIv) {
loadRoundAvatar(context,"",0,file,null,null,tartgetIv,0,0,FILLET_10);
}
/**
* 自定义圆角大小
* @param context
* @param file 图片来源为File
* @param fillet 圆角大小
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatarCustom(Context context,File file, int fillet,ImageView tartgetIv) {
loadRoundAvatar(context,"",0,file,null,null,tartgetIv,0,0,fillet);
}
/**
*
* 圆角为10
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatar10(Context context,File file, ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",0,file,null,null,tartgetIv,w,h,FILLET_10);
}
/**
*
* 自定义圆角大小
* @param context
* @param file 图片来源为File
* @param fillet 圆角大小
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatarCustom(Context context,File file, int fillet,ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",0,file,null,null,tartgetIv,w,h,fillet);
}
/**
*
* 圆角为10
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatar10(Context context,Uri uri, ImageView tartgetIv) {
loadRoundAvatar(context,"",0,null,uri,null,tartgetIv,0,0,FILLET_10);
}
/**
* 自定义圆角大小
* @param context
* @param uri 图片来源为Uri
* @param fillet 圆角大小
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatarCustom(Context context,Uri uri, int fillet,ImageView tartgetIv) {
loadRoundAvatar(context,"",0,null,uri,null,tartgetIv,0,0,fillet);
}
/**
*
* 圆角为10
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatar10(Context context,Uri uri, ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",0,null,uri,null,tartgetIv,w,h,FILLET_10);
}
/**
*
* 自定义圆角大小
* @param context
* @param uri 图片来源为Uri
* @param fillet 圆角大小
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatarCustom(Context context,Uri uri,int fillet, ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",0,null,uri,null,tartgetIv,w,h,fillet);
}
/**
*
* 圆角为10
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatar10(Context context,byte[] model, ImageView tartgetIv) {
loadRoundAvatar(context,"",0,null,null,model,tartgetIv,0,0,FILLET_10);
}
/**
* 自定义圆角大小
* @param context
* @param model 图片来源为byte[]
* @param fillet 圆角大小
* @param tartgetIv 目标控件
*/
public static void loadRoundAvatarCustom(Context context,byte[] model,int fillet, ImageView tartgetIv) {
loadRoundAvatar(context,"",0,null,null,model,tartgetIv,0,0,fillet);
}
/**
*
* 圆角为10
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatar10(Context context,byte[] model, ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",0,null,null,model,tartgetIv,w,h,FILLET_10);
}
/**
*
* 自定义圆角大小
* @param context
* @param model 图片来源为byte[]
* @param fillet 圆角大小
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadRoundAvatarCustom(Context context,byte[] model, int fillet,ImageView tartgetIv,int w,int h) {
loadRoundAvatar(context,"",0,null,null,model,tartgetIv,w,h,fillet);
}
/**
* 加载圆角图片
* 以下1-5个来源中,每次只能有一个有值
*
* @param context
* @param string 来源 1
* @param resourceId 来源 2
* @param file 来源 3
* @param uri 来源 4
* @param model 来源 5
* @param targetIv
* @param w
* @param h
* @param fillet 圆角切角角度
*/
private static void loadRoundAvatar(Context context,String string,Integer resourceId,File file,
Uri uri,byte[] model,ImageView targetIv,int w,int h,int fillet){
//来源于String
if (!StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformRound(context,fillet))
.into(targetIv);
}else {
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.transform(new TransformRound(context,fillet))
.into(targetIv);
}
}
//来源于Integer
else if (resourceId!=0&&StringTools.isEmpty(string)&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformRound(context,fillet))
.into(targetIv);
}else {
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.transform(new TransformRound(context,fillet))
.into(targetIv);
}
}
//来源于File
else if (file!=null&&StringTools.isEmpty(string)&&resourceId==0&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformRound(context,fillet))
.into(targetIv);
}else {
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.transform(new TransformRound(context,fillet))
.into(targetIv);
}
}
//来源于Uri
else if (uri!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformRound(context,fillet))
.into(targetIv);
}else {
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.transform(new TransformRound(context,fillet))
.into(targetIv);
}
}
//来源于byte[]
else if (model!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.override(w,h)
.transform(new TransformRound(context,fillet))
.into(targetIv);
}else {
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_avatar_round_default)
.error(R.drawable.bg_avatar_round_default)
.centerCrop()
.crossFade()
.transform(new TransformRound(context,fillet))
.into(targetIv);
}
}
}
/****************************以上 圆形头像******************************/
/**************************3、以下 方形banner图****************************/
/**
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
*/
public static void loadBannerPic(Context context,String string, ImageView tartgetIv) {
loadBannerPic(context,string,0,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBannerPic(Context context,String string, ImageView tartgetIv,int w,int h) {
loadBannerPic(context,string,0,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
*/
public static void loadBannerPic(Context context,Integer resourceId, ImageView tartgetIv) {
loadBannerPic(context,"",resourceId,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBannerPic(Context context,Integer resourceId, ImageView tartgetIv,int w,int h) {
loadBannerPic(context,"",resourceId,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
*/
public static void loadBannerPic(Context context,File file, ImageView tartgetIv) {
loadBannerPic(context,"",0,file,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBannerPic(Context context,File file, ImageView tartgetIv,int w,int h) {
loadBannerPic(context,"",0,file,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
*/
public static void loadBannerPic(Context context,Uri uri, ImageView tartgetIv) {
loadBannerPic(context,"",0,null,uri,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBannerPic(Context context,Uri uri, ImageView tartgetIv,int w,int h) {
loadBannerPic(context,"",0,null,uri,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
*/
public static void loadBannerPic(Context context,byte[] model, ImageView tartgetIv) {
loadBannerPic(context,"",0,null,null,model,tartgetIv,0,0);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBannerPic(Context context,byte[] model, ImageView tartgetIv,int w,int h) {
loadBannerPic(context,"",0,null,null,model,tartgetIv,w,h);
}
/**
* 加载banner图
* 以下1-5个来源中,每次只能有一个有值
*
* @param context
* @param string 来源 1
* @param resourceId 来源 2
* @param file 来源 3
* @param uri 来源 4
* @param model 来源 5
* @param targetIv
* @param w
* @param h
*/
private static void loadBannerPic(Context context,String string,Integer resourceId,File file,Uri uri,byte[] model,ImageView targetIv,int w,int h){
//来源于String
if (!StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.override(w,h)
.priority(Priority.HIGH)
.into(targetIv);
}else {
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.priority(Priority.HIGH)
.into(targetIv);
}
}
//来源于Integer
else if (resourceId!=0&&StringTools.isEmpty(string)&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.override(w,h)
.priority(Priority.HIGH)
.into(targetIv);
}else {
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.priority(Priority.HIGH)
.into(targetIv);
}
}
//来源于File
else if (file!=null&&StringTools.isEmpty(string)&&resourceId==0&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.override(w,h)
.priority(Priority.HIGH)
.into(targetIv);
}else {
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.priority(Priority.HIGH)
.into(targetIv);
}
}
//来源于Uri
else if (uri!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.override(w,h)
.priority(Priority.HIGH)
.into(targetIv);
}else {
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.priority(Priority.HIGH)
.into(targetIv);
}
}
//来源于byte[]
else if (model!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.override(w,h)
.priority(Priority.HIGH)
.into(targetIv);
}else {
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_banner_default)
.error(R.drawable.bg_banner_default)
.centerCrop()
.crossFade()
.priority(Priority.HIGH)
.into(targetIv);
}
}
}
/**************************以上 方形banner图****************************/
/**************************4、以下 高清大图***************************/
/**
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
*/
public static void loadLargePic(Context context,String string, ImageView tartgetIv) {
loadLargePic(context,string,0,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadLargePic(Context context,String string, ImageView tartgetIv,int w,int h) {
loadLargePic(context,string,0,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
*/
public static void loadLargePic(Context context,Integer resourceId, ImageView tartgetIv) {
loadLargePic(context,"",resourceId,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadLargePic(Context context,Integer resourceId, ImageView tartgetIv,int w,int h) {
loadLargePic(context,"",resourceId,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
*/
public static void loadLargePic(Context context,File file, ImageView tartgetIv) {
loadLargePic(context,"",0,file,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadLargePic(Context context,File file, ImageView tartgetIv,int w,int h) {
loadLargePic(context,"",0,file,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
*/
public static void loadLargePic(Context context,Uri uri, ImageView tartgetIv) {
loadLargePic(context,"",0,null,uri,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadLargePic(Context context,Uri uri, ImageView tartgetIv,int w,int h) {
loadLargePic(context,"",0,null,uri,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
*/
public static void loadLargePic(Context context,byte[] model, ImageView tartgetIv) {
loadLargePic(context,"",0,null,null,model,tartgetIv,0,0);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadLargePic(Context context,byte[] model, ImageView tartgetIv,int w,int h) {
loadLargePic(context,"",0,null,null,model,tartgetIv,w,h);
}
/**
* 加载大图
* 以下1-5个来源中,每次只能有一个有值
*
* @param context
* @param string 来源 1
* @param resourceId 来源 2
* @param file 来源 3
* @param uri 来源 4
* @param model 来源 5
* @param targetIv
* @param w
* @param h
*/
private static void loadLargePic(Context context,String string,Integer resourceId,File file,Uri uri,byte[] model,ImageView targetIv,int w,int h){
//来源于String
if (!StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.override(w,h)
.thumbnail(0.5f)
.into(targetIv);
}else {
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.thumbnail(0.5f)
.into(targetIv);
}
}
//来源于Integer
else if (resourceId!=0&&StringTools.isEmpty(string)&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.override(w,h)
.thumbnail(0.5f)
.into(targetIv);
}else {
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.thumbnail(0.5f)
.into(targetIv);
}
}
//来源于File
else if (file!=null&&StringTools.isEmpty(string)&&resourceId==0&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.override(w,h)
.thumbnail(0.5f)
.into(targetIv);
}else {
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.5f)
.crossFade()
.into(targetIv);
}
}
//来源于Uri
else if (uri!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.thumbnail(0.5f)
.override(w,h)
.into(targetIv);
}else {
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.5f)
.crossFade()
.into(targetIv);
}
}
//来源于byte[]
else if (model!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.5f)
.crossFade()
.override(w,h)
.into(targetIv);
}else {
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bg_big_pic_default)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.5f)
.crossFade()
.into(targetIv);
}
}
}
/**************************以上 高清大图***************************/
/**************************5、以下 普通图***************************/
/**
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
*/
public static void loadNormalPic(Context context,String string, ImageView tartgetIv) {
loadNormalPic(context,string,0,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadNormalPic(Context context,String string, ImageView tartgetIv,int w,int h) {
loadNormalPic(context,string,0,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
*/
public static void loadNormalPic(Context context,Integer resourceId, ImageView tartgetIv) {
loadNormalPic(context,"",resourceId,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadNormalPic(Context context,Integer resourceId, ImageView tartgetIv,int w,int h) {
loadNormalPic(context,"",resourceId,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
*/
public static void loadNormalPic(Context context,File file, ImageView tartgetIv) {
loadNormalPic(context,"",0,file,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadNormalPic(Context context,File file, ImageView tartgetIv,int w,int h) {
loadNormalPic(context,"",0,file,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
*/
public static void loadNormalPic(Context context,Uri uri, ImageView tartgetIv) {
loadNormalPic(context,"",0,null,uri,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadNormalPic(Context context,Uri uri, ImageView tartgetIv,int w,int h) {
loadNormalPic(context,"",0,null,uri,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
*/
public static void loadNormalPic(Context context,byte[] model, ImageView tartgetIv) {
loadNormalPic(context,"",0,null,null,model,tartgetIv,0,0);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadNormalPic(Context context,byte[] model, ImageView tartgetIv,int w,int h) {
loadNormalPic(context,"",0,null,null,model,tartgetIv,w,h);
}
/**
* 加载普通图
* 以下1-5个来源中,每次只能有一个有值
*
* @param context
* @param string 来源 1
* @param resourceId 来源 2
* @param file 来源 3
* @param uri 来源 4
* @param model 来源 5
* @param targetIv
* @param w
* @param h
*/
private static void loadNormalPic(Context context,String string,Integer resourceId,File file,Uri uri,byte[] model,ImageView targetIv,int w,int h){
//来源于String
if (!StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.override(w,h)
.thumbnail(0.8f)
.into(targetIv);
}else {
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.thumbnail(0.8f)
.into(targetIv);
}
}
//来源于Integer
else if (resourceId!=0&&StringTools.isEmpty(string)&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.override(w,h)
.thumbnail(0.8f)
.into(targetIv);
}else {
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.thumbnail(0.8f)
.into(targetIv);
}
}
//来源于File
else if (file!=null&&StringTools.isEmpty(string)&&resourceId==0&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.override(w,h)
.thumbnail(0.8f)
.into(targetIv);
}else {
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.8f)
.crossFade()
.into(targetIv);
}
}
//来源于Uri
else if (uri!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.crossFade()
.thumbnail(0.8f)
.override(w,h)
.into(targetIv);
}else {
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.8f)
.crossFade()
.into(targetIv);
}
}
//来源于byte[]
else if (model!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.8f)
.crossFade()
.override(w,h)
.into(targetIv);
}else {
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.drawable.jiazaishibai)
.centerCrop()
.thumbnail(0.8f)
.crossFade()
.into(targetIv);
}
}
}
/**************************以上 普通图***************************/
/**************************6、以下 模糊图***************************/
/**
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
*/
public static void loadBlurPic(Context context,String string, ImageView tartgetIv) {
loadBlurPic(context,string,0,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param string 图片来源为String
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBlurPic(Context context,String string, ImageView tartgetIv,int w,int h) {
loadBlurPic(context,string,0,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
*/
public static void loadBlurPic(Context context,Integer resourceId, ImageView tartgetIv) {
loadBlurPic(context,"",resourceId,null,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param resourceId 图片来源为Integer
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBlurPic(Context context,Integer resourceId, ImageView tartgetIv,int w,int h) {
loadBlurPic(context,"",resourceId,null,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
*/
public static void loadBlurPic(Context context,File file, ImageView tartgetIv) {
loadBlurPic(context,"",0,file,null,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param file 图片来源为File
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBlurPic(Context context,File file, ImageView tartgetIv,int w,int h) {
loadBlurPic(context,"",0,file,null,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
*/
public static void loadBlurPic(Context context,Uri uri, ImageView tartgetIv) {
loadBlurPic(context,"",0,null,uri,null,tartgetIv,0,0);
}
/**
*
* @param context
* @param uri 图片来源为Uri
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBlurPic(Context context,Uri uri, ImageView tartgetIv,int w,int h) {
loadBlurPic(context,"",0,null,uri,null,tartgetIv,w,h);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
*/
public static void loadBlurPic(Context context,byte[] model, ImageView tartgetIv) {
loadBlurPic(context,"",0,null,null,model,tartgetIv,0,0);
}
/**
*
* @param context
* @param model 图片来源为byte[]
* @param tartgetIv 目标控件
* @param w 宽
* @param h 高
*/
public static void loadBlurPic(Context context,byte[] model, ImageView tartgetIv,int w,int h) {
loadBlurPic(context,"",0,null,null,model,tartgetIv,w,h);
}
/**
* 加载模糊图片
* 以下1-5个来源中,每次只能有一个有值
*
* @param context
* @param string 来源 1
* @param resourceId 来源 2
* @param file 来源 3
* @param uri 来源 4
* @param model 来源 5
* @param targetIv
* @param w
* @param h
*/
private static void loadBlurPic(Context context,String string,Integer resourceId,File file,Uri uri,byte[] model,ImageView targetIv,int w,int h){
//来源于String
if (!StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.override(w,h)
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}else {
Glide.with(context)
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.crossFade()
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}
}
//来源于Integer
else if (resourceId!=0&&StringTools.isEmpty(string)&&file==null&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.override(w,h)
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}else {
Glide.with(context)
.load(resourceId)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}
}
//来源于File
else if (file!=null&&StringTools.isEmpty(string)&&resourceId==0&&uri==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.override(w,h)
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}else {
Glide.with(context)
.load(file)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}
}
//来源于Uri
else if (uri!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&model==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.override(w,h)
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}else {
Glide.with(context)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}
}
//来源于byte[]
else if (model!=null&&StringTools.isEmpty(string)&&resourceId==0&&file==null&&uri==null){
if (w!=0&&h!=0){
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.override(w,h)
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}else {
Glide.with(context)
.load(model)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.default_bg)
.error(R.color.default_bg)
.centerCrop()
.crossFade()
.bitmapTransform(new TransformBlur(context,TransformBlur.MAX_RADIUS))
.into(targetIv);
}
}
}
}
/**************************以上 模糊图***************************/
网友评论