3.0Android图片三级缓存如何实现
3.0Android图片三级缓存如何实现
引擎初始化的时候,可以自定义processor实现
Processor customProcessor = new CustomProcessor()
List<Processor> processors = new ArrayList<>();
processors.add(customProcessor);
initParams.processors = processors;
// 使用glide图片缓存库
public class CustomProcessor extends Processor {
@override
public void handleRequestAsync(ResourceHolder holder, VfsManager.ProcessorCallback callback) {
if (holder.requestParams != null && holder.requestParams.get(ImageLoader.REQUEST_CONTENT_TYPE) != null && holder.requestParams.get(ImageLoader.REQUEST_CONTENT_TYPE)
.equals(ImageLoader.REQUEST_CONTENT_TYPE_IMAGE)) {
int width = Integer.valueOf(holder.requestParams.get("width"));
int height = Integer.valueOf(holder.requestParams.get("height"));
if (width == 0) {
width = Target.SIZE_ORIGINAL;
}
if (height == 0) {
height = Target.SIZE_ORIGINAL;
}
Bitmap bitmap = Glide.with(context)
.asBitmap()
.load(holder.uri)
.submit(width, height)
.get()
holder.bitmap = bitmap;
holder.resultCode = HippyResourceLoader.FetchResultCode.OK.oridinal();
callback.onHandleCompleted();
return;
}
callback.goNext();
}
}
Bitmap bitmap = Glide.with(context) .asBitmap() .load(holder.uri) .submit(width, height) .get() glide 这种同步执行在主线程会报错。使用异步操作,onResourceReady 后执行callback.onHandleCompleted(); 会导致图片错乱显示。
Pay attention 🛎️ !! There has been no activity on this issue for 2 months, so I will label it stalled. It will be automatically closed in 60 days if no more activity. Feel free to leave a comment if you have any questions.
Sorry, closing this issue because it has stalled for over 3 months. Feel free to reopen if this issue is still relevant, or to ping the collaborator if you have any questions.