Search in sources :

Example 11 with SVG

use of com.caverock.androidsvg.SVG in project PocketHub by pockethub.

the class SvgDrawableTranscoder method transcode.

@Nullable
@Override
public Resource<Drawable> transcode(@NonNull Resource<SVG> toTranscode, @NonNull Options options) {
    SVG svg = toTranscode.get();
    float ratio = svg.getDocumentAspectRatio();
    int width = svg.getDocumentWidth() > 0 ? (int) svg.getDocumentWidth() : 1024;
    int height = (int) (svg.getDocumentHeight() > 0 ? svg.getDocumentHeight() : (width / ratio));
    Picture picture = svg.renderToPicture(width, height);
    PictureDrawable drawable = new PictureDrawable(picture);
    return new SimpleResource<>(drawable);
}
Also used : SVG(com.caverock.androidsvg.SVG) Picture(android.graphics.Picture) PictureDrawable(android.graphics.drawable.PictureDrawable) SimpleResource(com.bumptech.glide.load.resource.SimpleResource) Nullable(androidx.annotation.Nullable)

Example 12 with SVG

use of com.caverock.androidsvg.SVG in project glide by bumptech.

the class SvgDrawableTranscoder method transcode.

@Nullable
@Override
public Resource<PictureDrawable> transcode(@NonNull Resource<SVG> toTranscode, @NonNull Options options) {
    SVG svg = toTranscode.get();
    Picture picture = svg.renderToPicture();
    PictureDrawable drawable = new PictureDrawable(picture);
    return new SimpleResource<>(drawable);
}
Also used : SVG(com.caverock.androidsvg.SVG) Picture(android.graphics.Picture) PictureDrawable(android.graphics.drawable.PictureDrawable) SimpleResource(com.bumptech.glide.load.resource.SimpleResource) Nullable(android.support.annotation.Nullable)

Example 13 with SVG

use of com.caverock.androidsvg.SVG in project android by nextcloud.

the class DisplayUtils method downloadSVGIcon.

private static void downloadSVGIcon(CurrentAccountProvider currentAccountProvider, ClientFactory clientFactory, Context context, String iconUrl, SimpleTarget imageView, int placeholder, int width, int height) {
    GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context).using(new CustomGlideUriLoader(currentAccountProvider.getUser(), clientFactory), InputStream.class).from(Uri.class).as(SVG.class).transcode(new SvgDrawableTranscoder(), PictureDrawable.class).sourceEncoder(new StreamEncoder()).cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder(height, width))).decoder(new SvgDecoder(height, width)).placeholder(placeholder).error(placeholder).animate(android.R.anim.fade_in);
    Uri uri = Uri.parse(iconUrl);
    requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE).load(uri).into(imageView);
}
Also used : SVG(com.caverock.androidsvg.SVG) SvgDrawableTranscoder(com.owncloud.android.utils.svg.SvgDrawableTranscoder) InputStream(java.io.InputStream) PictureDrawable(android.graphics.drawable.PictureDrawable) CustomGlideUriLoader(com.owncloud.android.utils.glide.CustomGlideUriLoader) SvgDecoder(com.owncloud.android.utils.svg.SvgDecoder) Uri(android.net.Uri) StreamEncoder(com.bumptech.glide.load.model.StreamEncoder)

Example 14 with SVG

use of com.caverock.androidsvg.SVG in project android by nextcloud.

the class SvgDrawableTranscoder method transcode.

@Override
public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode) {
    SVG svg = toTranscode.get();
    Picture picture = svg.renderToPicture();
    PictureDrawable drawable = new PictureDrawable(picture);
    return new SimpleResource<PictureDrawable>(drawable);
}
Also used : SVG(com.caverock.androidsvg.SVG) Picture(android.graphics.Picture) PictureDrawable(android.graphics.drawable.PictureDrawable) SimpleResource(com.bumptech.glide.load.resource.SimpleResource)

Example 15 with SVG

use of com.caverock.androidsvg.SVG in project android by nextcloud.

the class SvgOrImageDecoder method decode.

public Resource<SVGorImage> decode(InputStream source, int w, int h) throws IOException {
    byte[] array = new byte[source.available()];
    source.read(array);
    ByteArrayInputStream svgInputStream = new ByteArrayInputStream(array.clone());
    ByteArrayInputStream pngInputStream = new ByteArrayInputStream(array.clone());
    try {
        SVG svg = SVG.getFromInputStream(svgInputStream);
        source.close();
        pngInputStream.close();
        if (width > 0) {
            svg.setDocumentWidth(width);
        }
        if (height > 0) {
            svg.setDocumentHeight(height);
        }
        svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX);
        return new SimpleResource<>(new SVGorImage(svg, null));
    } catch (SVGParseException ex) {
        Bitmap bitmap = BitmapFactory.decodeStream(pngInputStream);
        return new SimpleResource<>(new SVGorImage(null, bitmap));
    }
}
Also used : Bitmap(android.graphics.Bitmap) ByteArrayInputStream(java.io.ByteArrayInputStream) SVG(com.caverock.androidsvg.SVG) SVGParseException(com.caverock.androidsvg.SVGParseException) SimpleResource(com.bumptech.glide.load.resource.SimpleResource)

Aggregations

SVG (com.caverock.androidsvg.SVG)16 PictureDrawable (android.graphics.drawable.PictureDrawable)8 SimpleResource (com.bumptech.glide.load.resource.SimpleResource)8 SVGParseException (com.caverock.androidsvg.SVGParseException)7 Bitmap (android.graphics.Bitmap)6 Canvas (android.graphics.Canvas)5 Uri (android.net.Uri)5 StreamEncoder (com.bumptech.glide.load.model.StreamEncoder)5 SvgDecoder (com.owncloud.android.utils.svg.SvgDecoder)5 InputStream (java.io.InputStream)5 Picture (android.graphics.Picture)4 SvgDrawableTranscoder (com.owncloud.android.utils.svg.SvgDrawableTranscoder)4 FileToStreamDecoder (com.bumptech.glide.load.resource.file.FileToStreamDecoder)2 BitmapShader (android.graphics.BitmapShader)1 Matrix (android.graphics.Matrix)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1 Nullable (android.support.annotation.Nullable)1 Nullable (androidx.annotation.Nullable)1 CustomGlideUriLoader (com.owncloud.android.utils.glide.CustomGlideUriLoader)1