I'm trying to use Glide to get a SVG resource from a URL, but I don't know how to get a Bitmap object instead of loading it in into a View.
The reason for that is that I need to load some SVG files on a Widget.
I used this example: https://stackoverflow.com/a/30938082/3346625
UPDATE 1: Setup GenericRequestBuilder
final RemoteViews fViews = views;
final int fViewId = viewId;
Runnable myRunnable = new Runnable() {
@Override
public void run() {
GenericRequestBuilder<Uri, InputStream, SVG, Bitmap> requestBuilder;
requestBuilder = Glide.with(mContext)
.using(Glide.buildStreamModelLoader(Uri.class, mContext), InputStream.class)
.from(Uri.class)
.as(SVG.class)
.transcode(new SvgBitmapTranscoder(), Bitmap.class)
.sourceEncoder(new StreamEncoder())
.cacheDecoder(new FileToStreamDecoder<SVG>(new SvgDecoder()))
.decoder(new SvgDecoder())
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.no_icon)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(Uri.parse(url));
requestBuilder.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
fViews.setImageViewBitmap(fViewId, resource);
}
});
}
};
mainHandler.post(myRunnable);
- I had to use a Runnable as requestBuilder.into needs to run on the main thread.
How can I get a Bitmap to later use it with a RemoteView?