Hi all
I am very new to Glide so I apologise if I'm asking something obvious.
I have been tasked with adding support for rendering SVGs in an ImageView using Glide. We already have the code in our application which is loading non-svg files into the image view.
We are using Glide 4.10.0 and I have added the AndroidSVG library already (as i am using it elsewhere).
I have taken the code exactly from the 4.10.0 sample SVG project.
First I copied the SvgDecoder.java / SvgDrawableTranscoder.java / SvgModule.java exactly as is and put them in their own package.
In my code where I am loading images into an ImageView, I added code to support SVGs.
protected void loadAssetThumbnail(GlideUrl thumbnailUrl, boolean isSVG) {
if (isSVG) {
Glide.with(thumbnailImageView.getContext())
.as(PictureDrawable.class)
.load(glideUrl)
.placeholder(R.color.file_placeholder)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.listener(new RequestListener<PictureDrawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model,
Target<PictureDrawable> target, boolean isFirstResource) {
DataWorkflowTasks.log("thumbnail load failed!" + e.getMessage());
ImageView view = ((ImageViewTarget<?>) target).getView();
view.setLayerType(ImageView.LAYER_TYPE_NONE, null);
return false;
}
@Override
public boolean onResourceReady(PictureDrawable resource, Object model,
Target<PictureDrawable> target, DataSource dataSource,
boolean isFirstResource) {
ImageView view = ((ImageViewTarget<?>) target).getView();
view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null);
//on load success
return false;
}
})
.into(thumbnailImageView);
} else {
// load preview image using glide
Glide.with(thumbnailImageView.getContext())
.load(glideUrl)
.placeholder(R.color.file_placeholder)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model,
Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model,
Target<Drawable> target, DataSource dataSource,
boolean isFirstResource) {
return false;
}
})
.into(thumbnailImageView);
}
}
When i run this code, it does not load my SVG, the code comes into the onLoadFailed in my listener. The exception just shows that the load failed, but does not give me any clue as to why its failing.
I presume I have missed something very simple to get it to use the additional glide files to convert the SVG but I am not sure what I have missing.
Any help would be greatly appreciated.
Sarah