本文整理汇总了Java中com.bumptech.glide.DrawableRequestBuilder.diskCacheStrategy方法的典型用法代码示例。如果您正苦于以下问题:Java DrawableRequestBuilder.diskCacheStrategy方法的具体用法?Java DrawableRequestBuilder.diskCacheStrategy怎么用?Java DrawableRequestBuilder.diskCacheStrategy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bumptech.glide.DrawableRequestBuilder
的用法示例。
在下文中一共展示了DrawableRequestBuilder.diskCacheStrategy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadImage
import com.bumptech.glide.DrawableRequestBuilder; //导入方法依赖的package包/类
@Override
public void loadImage(Context ctx, GlideImageConfig config) {
if (ctx == null) throw new IllegalStateException("Context is required");
if (config == null) throw new IllegalStateException("GlideImageConfig is required");
if (TextUtils.isEmpty(config.getUrl())) throw new IllegalStateException("url is required");
if (config.getImageView() == null) throw new IllegalStateException("imageview is required");
RequestManager manager;
manager = Glide.with(ctx);//如果context是activity则自动使用Activity的生命周期
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl())
.crossFade()
.centerCrop();
switch (config.getCacheStrategy()) {//缓存策略
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
if (config.getTransformation() != null) {//glide用它来改变图形的形状
requestBuilder.transform(config.getTransformation());
}
if (config.getPlaceholder() != 0)//设置占位符
requestBuilder.placeholder(config.getPlaceholder());
if (config.getErrorPic() != 0)//设置错误的图片
requestBuilder.error(config.getErrorPic());
requestBuilder
.into(config.getImageView());
}
示例2: loadImage
import com.bumptech.glide.DrawableRequestBuilder; //导入方法依赖的package包/类
@Override
public void loadImage(Context ctx, GlideImageConfig config) {
if (ctx == null) throw new IllegalStateException("Context is required");
if (config == null) throw new IllegalStateException("GlideImageConfig is required");
//这里不抛异常空的就显示默认图片
// if (TextUtils.isEmpty(config.getUrl())) throw new IllegalStateException("url is required");
if (config.getImageView() == null) throw new IllegalStateException("imageview is required");
RequestManager manager;
manager = Glide.with(ctx);//如果context是activity则自动使用Activity的生命周期
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl())
.centerCrop();
if (config.fitCenter()) {
requestBuilder.fitCenter();
}
if (config.dontAnimation()) {
requestBuilder.dontAnimate();
} else {
requestBuilder.crossFade();
}
switch (config.getCacheStrategy()) {//缓存策略
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
if (config.getTransformation() != null) {//glide用它来改变图形的形状
requestBuilder.transform(config.getTransformation());
}
//设置占位符
if (config.getPlaceholder() != null) {
requestBuilder.placeholder(config.getPlaceholder());
} else if (config.getPlaceholderResId() != 0) {
requestBuilder.placeholder(config.getPlaceholderResId());
}
if (config.getErrorPic() != 0)//设置错误的图片
requestBuilder.error(config.getErrorPic());
requestBuilder.skipMemoryCache(config.skipMemoryCache());
requestBuilder.into(config.getImageView());
}
示例3: loadImage
import com.bumptech.glide.DrawableRequestBuilder; //导入方法依赖的package包/类
@Override
public void loadImage(Context ctx, GlideImageConfig config) {
RequestManager manager;
if (ctx instanceof Activity)//如果是activity则可以使用Activity的生命周期
manager = Glide.with((Activity) ctx);
else
manager = Glide.with(ctx);
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl())
.crossFade()
.centerCrop();
switch (config.getCacheStrategy()) {//缓存策略
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
if (config.getTransformation() != null) {//glide用它来改变图形的形状
requestBuilder.transform(config.getTransformation());
}
if (config.getPlaceholder() != 0)//设置占位符
requestBuilder.placeholder(config.getPlaceholder());
if (config.getErrorPic() != 0)//设置错误的图片
requestBuilder.error(config.getErrorPic());
requestBuilder
.into(config.getImageView());
}
示例4: load
import com.bumptech.glide.DrawableRequestBuilder; //导入方法依赖的package包/类
@Override
public void load(Context context, GlideImageConfig config) {
this.check(context, config);
RequestManager manager = Glide.with(context);
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.crossFade()// 默认显示淡入淡出动画
;
// 缓存策略
switch (config.getCacheStrategy()) {
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
// 改变图形的形状
if (config.getTransformation() != null) {
requestBuilder.transform(config.getTransformation());
}
// 设置占位符
if (config.getPlaceholder() != 0) {
requestBuilder.placeholder(config.getPlaceholder());
}
// 设置错误的图片
if (config.getError() != 0) {
requestBuilder.error(config.getError());
}
requestBuilder.into(config.getImageView());
}
示例5: loadImage
import com.bumptech.glide.DrawableRequestBuilder; //导入方法依赖的package包/类
@Override
public void loadImage(Context ctx, GlideImageConfig config) {
if (ctx == null) throw new IllegalStateException("Context is required");
if (config == null) throw new IllegalStateException("GlideImageConfig is required");
if (TextUtils.isEmpty(config.getUrl())) throw new IllegalStateException("Url is required");
if (config.getImageView() == null) throw new IllegalStateException("Imageview is required");
RequestManager manager;
manager = Glide.with(ctx);//如果context是activity则自动使用Activity的生命周期
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl())
.crossFade()
.centerCrop();
switch (config.getCacheStrategy()) {//缓存策略
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
if (config.getTransformation() != null) {//glide用它来改变图形的形状
requestBuilder.transform(config.getTransformation());
}
if (config.getPlaceholder() != 0)//设置占位符
requestBuilder.placeholder(config.getPlaceholder());
if (config.getErrorPic() != 0)//设置错误的图片
requestBuilder.error(config.getErrorPic());
requestBuilder
.into(config.getImageView());
}
示例6: loadImage
import com.bumptech.glide.DrawableRequestBuilder; //导入方法依赖的package包/类
/**
* 根据GlideImageConfig中的配置进行加载图片
*
* @param ctx context
* @param config 图片加载
*/
@Override
public void loadImage(Context ctx, GlideImageConfig config) {
if (ctx == null) throw new IllegalStateException("Context is required");
if (config == null) throw new IllegalStateException("GlideImageConfig is required");
if (TextUtils.isEmpty(config.getUrl())) throw new IllegalStateException("url is required");
if (config.getImageView() == null) throw new IllegalStateException("imageview is required");
RequestManager manager;
manager = Glide.with(ctx);//如果context是activity则自动使用Activity的生命周期
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl())
.crossFade()
.centerCrop();
switch (config.getCacheStrategy()) {//缓存策略
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
if (config.getTransformation() != null) {//glide用它来改变图形的形状
requestBuilder.transform(config.getTransformation());
}
if (config.getPlaceholder() != 0)//设置占位符
requestBuilder.placeholder(config.getPlaceholder());
if (config.getErrorPic() != 0)//设置错误的图片
requestBuilder.error(config.getErrorPic());
requestBuilder
.into(config.getImageView());
}