GlideImageConfig.java
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.xdy.commonlibrary.imageloader.glide;
import android.widget.ImageView;
import com.bumptech.glide.load.Transformation;
import com.xdy.commonlibrary.imageloader.ImageConfig;
/**
* Created by jess on 8/5/16 15:19
* contact with jess.yan.effort@gmail.com
* 这里放Glide专属的配置信息,可以一直扩展字段,如果外部调用时想让图片加载框架
* 做一些操作,比如清除或则切换缓存策略,则可以定义一个int类型的变量,内部根据int做不同过的操作
* 其他操作同理
*/
public class GlideImageConfig extends ImageConfig {
private int cacheStrategy;//0对应DiskCacheStrategy.all,1对应DiskCacheStrategy.NONE,2对应DiskCacheStrategy.SOURCE,3对应DiskCacheStrategy.RESULT
private Transformation transformation;//glide用它来改变图形的形状
private GlideImageConfig(Buidler builder) {
this.url = builder.url;
this.imageView = builder.imageView;
this.placeholder = builder.placeholder;
this.errorPic = builder.errorPic;
this.cacheStrategy = builder.cacheStrategy;
this.transformation = builder.transformation;
}
public int getCacheStrategy() {
return cacheStrategy;
}
public Transformation getTransformation() {
return transformation;
}
public static Buidler builder() {
return new Buidler();
}
public static final class Buidler {
private String url;
private ImageView imageView;
private int placeholder;
private int errorPic;
private int cacheStrategy;//0对应DiskCacheStrategy.all,1对应DiskCacheStrategy.NONE,2对应DiskCacheStrategy.SOURCE,3对应DiskCacheStrategy.RESULT
private Transformation transformation;//glide用它来改变图形的形状
private Buidler() {
}
public Buidler url(String url) {
this.url = url;
return this;
}
public Buidler placeholder(int placeholder) {
this.placeholder = placeholder;
return this;
}
public Buidler errorPic(int errorPic){
this.errorPic = errorPic;
return this;
}
public Buidler imagerView(ImageView imageView) {
this.imageView = imageView;
return this;
}
public Buidler cacheStrategy(int cacheStrategy) {
this.cacheStrategy = cacheStrategy;
return this;
}
public Buidler transformation(Transformation transformation) {
this.transformation = transformation;
return this;
}
public GlideImageConfig build() {
if (url == null) throw new IllegalStateException("url is required");
if (imageView == null) throw new IllegalStateException("imageview is required");
return new GlideImageConfig(this);
}
}
}