use of com.caverock.androidsvg.SVG in project glide by bumptech.
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);
}
use of com.caverock.androidsvg.SVG in project Carbon by ZieIony.
the class CheckableDrawable method renderSVGs.
private void renderSVGs() {
Rect bounds = getBounds();
if (bounds.width() <= 0 && bounds.height() <= 0)
return;
try {
{
SVG svg = SVG.getFromResource(context, checkedRes);
checkedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(checkedBitmap);
svg.setDocumentWidth(checkedBitmap.getWidth());
svg.setDocumentHeight(checkedBitmap.getHeight());
svg.renderToCanvas(canvas);
checkedShader = new BitmapShader(checkedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Matrix matrix = new Matrix();
matrix.postTranslate(bounds.left, bounds.top);
checkedShader.setLocalMatrix(matrix);
}
{
SVG svg2 = SVG.getFromResource(context, uncheckedRes);
uncheckedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(uncheckedBitmap);
svg2.setDocumentWidth(uncheckedBitmap.getWidth());
svg2.setDocumentHeight(uncheckedBitmap.getHeight());
svg2.renderToCanvas(canvas);
}
{
SVG svg3 = SVG.getFromResource(context, filledRes);
filledBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(filledBitmap);
svg3.setDocumentWidth(filledBitmap.getWidth());
svg3.setDocumentHeight(filledBitmap.getHeight());
svg3.renderToCanvas(canvas);
}
maskBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
maskCanvas = new Canvas(maskBitmap);
radius = (float) (Math.sqrt(2) * bounds.width() / 2);
} catch (SVGParseException e) {
Log.e(CheckableDrawable.class.getSimpleName(), "There was an error parsing SVG");
} catch (NullPointerException e) {
// TODO: what is this catch for?
}
}
use of com.caverock.androidsvg.SVG in project android by nextcloud.
the class DisplayUtils method downloadSVGIcon.
private static void downloadSVGIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder, int width, int height) {
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context).using(Glide.buildStreamModelLoader(Uri.class, context), 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);
}
use of com.caverock.androidsvg.SVG in project gh4a by slapperwan.
the class HttpImageGetter method renderSvgToBitmap.
private static Bitmap renderSvgToBitmap(Resources res, InputStream is, int maxWidth, int maxHeight) {
// noinspection TryWithIdenticalCatches
try {
SVG svg = SVG.getFromInputStream(is);
if (svg != null) {
svg.setRenderDPI(DisplayMetrics.DENSITY_DEFAULT);
Float density = res.getDisplayMetrics().density;
int docWidth = (int) (svg.getDocumentWidth() * density);
int docHeight = (int) (svg.getDocumentHeight() * density);
if (docWidth < 0 || docHeight < 0) {
float aspectRatio = svg.getDocumentAspectRatio();
if (aspectRatio > 0) {
float heightForAspect = (float) maxWidth / aspectRatio;
float widthForAspect = (float) maxHeight * aspectRatio;
if (widthForAspect < heightForAspect) {
docWidth = Math.round(widthForAspect);
docHeight = maxHeight;
} else {
docWidth = maxWidth;
docHeight = Math.round(heightForAspect);
}
} else {
docWidth = maxWidth;
docHeight = maxHeight;
}
// we didn't take density into account anymore when calculating docWidth
// and docHeight, so don't scale with it and just let the renderer
// figure out the scaling
density = null;
}
while (docWidth >= maxWidth || docHeight >= maxHeight) {
docWidth /= 2;
docHeight /= 2;
if (density != null) {
density /= 2;
}
}
Bitmap bitmap = Bitmap.createBitmap(docWidth, docHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
if (density != null) {
canvas.scale(density, density);
}
svg.renderToCanvas(canvas);
return bitmap;
}
} catch (SVGParseException e) {
// fall through
} catch (NullPointerException e) {
// https://github.com/BigBadaboom/androidsvg/issues/81
// remove me when there's a 1.2.3 release
}
return null;
}
use of com.caverock.androidsvg.SVG in project android by nextcloud.
the class ActivityListAdapter method downloadIcon.
private void downloadIcon(Activity activity, ImageView itemViewType) {
GenericRequestBuilder<Uri, InputStream, SVG, Bitmap> requestBuilder = Glide.with(context).using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class).from(Uri.class).as(SVG.class).transcode(new SvgBitmapTranscoder(128, 128), Bitmap.class).sourceEncoder(new StreamEncoder()).cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder())).decoder(new SvgDecoder()).placeholder(R.drawable.ic_activity).error(R.drawable.ic_activity).animate(android.R.anim.fade_in);
Uri uri = Uri.parse(activity.getIcon());
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE).load(uri).into(itemViewType);
}
Aggregations