DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app
A simple in-memory cache was implemented to store downloaded vector images locally;
Inside the app, vector images are represented in the format of PictureDrawable;
To render SVG, a new onSuccess(PictureDrawable) method was added in the DivImageDownloadCallback interface.
Picasso and Glide backward compatibility
The interface of DivImageLoader has been extended to have doesSupportSvg() method indicating whether the image loader supports SVG;
To make Picasso and Glide work with SVG images, a special FlexibleImageLoader bean was created;
It represents a wrapper over the standard image loader which can replace it with the SvgImageLoader under the hood if SVG format is not supported by the chosen image loader;
Rendering Vector Images
Vector images are being rendered inside of onSuccess(PictureDrawable) method in a similar way as bitmaps;
Images in vector format don't support tints and filters. To overcome this, DivImage shouldBeRasterized property was created which is being set to true if the tint or filters are overridden for the image;
If it should be rasterized, then that image is converted into bitmap of the size of the original SVG;
Background images don't support transparency and filters. When such properties are specified, then background image is converted to bitmap in a similar way.
Previews
To decode SVG images from base64, DecodeBase64ImageTask was extended to work with both formats;
Instead of working only with Bitmaps, it now supports Bitmap and PictureDrawable which are aggregated under a newly created ImageRepresentation sealed template class.
Samples and Testing Screens Updates
To demonstrate the features of vector images, Sample and Testing screens were updated accordingly.
I hereby agree to the terms of the CLA available at: link
Notes
This pull request contains the changes that support loading images in SVG format.
SVG Image Loading
onSuccess(PictureDrawable)
method was added in theDivImageDownloadCallback
interface.Picasso and Glide backward compatibility
doesSupportSvg()
method indicating whether the image loader supports SVG;FlexibleImageLoader
bean was created;Rendering Vector Images
onSuccess(PictureDrawable)
method in a similar way as bitmaps;shouldBeRasterized
property was created which is being set to true if the tint or filters are overridden for the image;Previews
DecodeBase64ImageTask
was extended to work with both formats;ImageRepresentation
sealed template class.Samples and Testing Screens Updates
Sample
andTesting
screens were updated accordingly.