在Glide 4中使用AppGlideModule中的RequestOptions [英] Using RequestOptions in AppGlideModule with Glide 4
问题描述
我将Glide库与AppGlideModule(4.1.1版)一起使用.这是我的滑行模块类:
@GlideModule
public class GlideUtil extends AppGlideModule {
private final int IMAGE_CACHE_SIZE = 20 * 1024 * 1024; // 20 MB
private final String IMAGE_FOLDER = "/User/Images";
@Override
public void applyOptions(Context context, GlideBuilder builder) {
RequestOptions requestOptions = new RequestOptions();
requestOptions.format(DecodeFormat.PREFER_ARGB_8888);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
builder.setDefaultRequestOptions(requestOptions);
InternalCacheDiskCacheFactory factory = new InternalCacheDiskCacheFactory(context, IMAGE_FOLDER, IMAGE_CACHE_SIZE);
builder.setDiskCache(factory);
}
@Override
public boolean isManifestParsingEnabled() {
return false;
}
此代码成功运行.但是当我将滑行库的版本更新为4.3.1
compile 'com.github.bumptech.glide:glide:4.3.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
在GlideUtil类中,我看到以下消息:未使用格式的结果",未使用diskCacheStrategyis的结果":
那么,如何解决这个问题?并且diskCacheStrategy
和format
方法在Glide 4.3.1上可以工作吗?
问题是,您没有使用请参见用@CheckResult
注释的方法,这是皮棉理解的方式,您使用的是错误的方式,因为您正在不检查结果" . >
请执行以下操作:
RequestOptions requestOptions = new RequestOptions();
requestOptions = requestOptions.format(DecodeFormat.PREFER_ARGB_8888);
requestOptions = requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
现在警告消失了.
或者您可以直接执行以下操作:
builder.setDefaultRequestOptions(new RequestOptions()
.format(DecodeFormat.PREFER_ARGB_8888)
.diskCacheStrategy(DiskCacheStrategy.ALL));
I used the `Glide library with AppGlideModule, version of library 4.1.1. Here is my glide module class:
@GlideModule
public class GlideUtil extends AppGlideModule {
private final int IMAGE_CACHE_SIZE = 20 * 1024 * 1024; // 20 MB
private final String IMAGE_FOLDER = "/User/Images";
@Override
public void applyOptions(Context context, GlideBuilder builder) {
RequestOptions requestOptions = new RequestOptions();
requestOptions.format(DecodeFormat.PREFER_ARGB_8888);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
builder.setDefaultRequestOptions(requestOptions);
InternalCacheDiskCacheFactory factory = new InternalCacheDiskCacheFactory(context, IMAGE_FOLDER, IMAGE_CACHE_SIZE);
builder.setDiskCache(factory);
}
@Override
public boolean isManifestParsingEnabled() {
return false;
}
This code worked successfully. But when i updated version of glide library to 4.3.1
compile 'com.github.bumptech.glide:glide:4.3.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
in GlideUtil class i saw messages: "The result of format is not used", "The result of diskCacheStrategyis not used":
So, how to resolve this? And do the methods diskCacheStrategy
and format
work on Glide 4.3.1 ?
The problem is, that you are not using the builder object, that is returned by format()
, thus your actions become pointless, that's why lint warns you. You can see that method annotated with @CheckResult
, that's how lint understands, that you are on a wrong way, because you are "not checking the result" returned by that method.
Instead perform following:
RequestOptions requestOptions = new RequestOptions();
requestOptions = requestOptions.format(DecodeFormat.PREFER_ARGB_8888);
requestOptions = requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
Now the warning would be gone.
Or you may perform following directly:
builder.setDefaultRequestOptions(new RequestOptions()
.format(DecodeFormat.PREFER_ARGB_8888)
.diskCacheStrategy(DiskCacheStrategy.ALL));
这篇关于在Glide 4中使用AppGlideModule中的RequestOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!