I am trying to add the ability to set an ImageView to an SVG using Glide and AndroidSVG (https://bigbadaboom.github.io/androidsvg/).
I am using the sample from Glide: https://github.com/bumptech/glide/tree/v4.10.0/samples/svg
I am using Glide 4.10.0
I am getting "onLoadFailed". The error just simply says that it can not load the resource, it does not indicate why.
Here is the code where I am calling Glide to load the SVG
GlideUrl glideUrl = .....
Glide.with(thumbnailImageView.getContext())
.as(PictureDrawable.class)
.load(glideUrl)
.placeholder(R.color.file_placeholder)
.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);
In the same package I have the following which are EXACT copies from the Glide 4.10.0 sample.
The SVG I am testing with is the following file https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg
I am wondering if i have not set up Glide correctly so its not picking up the SvgDecoder/SvgDrawableTranscoder/SvgModule
As expected I had not set up Glide correctly. I was missing this line in my build.gradle file:
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
Furthermore my Glide command should have been using "GlideApp" not "Glide", this is so that is uses the extra Glide files (SvgDecoder/SvgModule/SvgDrawableTranscoder) handling the SVG file.
I also had to comment out the placeholder image otherwise i was getting an error about bitmap missing the src attribute.
Glide.with(thumbnailImageView.getContext()) .as(PictureDrawable.class) .load(glideUrl)
.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);