Java Code Examples for com.caverock.androidsvg.SVGParseException#printStackTrace()

The following examples show how to use com.caverock.androidsvg.SVGParseException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UIHelpers.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
public static void populateContainerWithSVG(View rootView, int offsetX, int idSVG, int idContainer) {
	try {
		SVG svg = SVG.getFromResource(rootView.getContext(), idSVG);
		if (offsetX != 0) {
			RectF viewBox = svg.getDocumentViewBox();
			viewBox.offset(offsetX, 0);
			svg.setDocumentViewBox(viewBox.left, viewBox.top, viewBox.width(), viewBox.height());
		}
		SVGImageView svgImageView = new SVGImageView(rootView.getContext());
		svgImageView.setFocusable(false);
		svgImageView.setFocusableInTouchMode(false);
		svgImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
		svgImageView.setSVG(svg);
		svgImageView.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.MATCH_PARENT));
		ViewGroup layout = (ViewGroup) rootView.findViewById(idContainer);
		layout.addView(svgImageView);
	} catch (SVGParseException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: SVGMediaMetadataRetriever.java    From MediaMetadataRetrieverCompat with MIT License 5 votes vote down vote up
@Override
public void setDataSource(@NonNull DataSource source) throws IOException {
    try {
        mSVG = SVG.getFromInputStream(source.toStream());
    } catch (SVGParseException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: SvgDecoderExample.java    From fresco with MIT License 5 votes vote down vote up
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  try {
    SVG svg = SVG.getFromInputStream(encodedImage.getInputStream());
    return new CloseableSvgImage(svg);
  } catch (SVGParseException e) {
    e.printStackTrace();
  }
  return null;
}
 
Example 4
Source File: XulSVGDrawable.java    From starcor.xul with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static XulDrawable buildSVGDrawable(InputStream stream, String url, String imageKey, int width, int height) {
	if (stream == null) {
		return null;
	}

	XulSVGDrawable drawable = new XulSVGDrawable();

	try {
		drawable._svg = SVG.getFromInputStream(stream);
	} catch (SVGParseException e) {
		e.printStackTrace();
		return null;
	}

	float offsetX = 0;
	float offsetY = 0;

	float xScalar = 1.0f;
	float yScalar = 1.0f;

	RectF documentViewBox = drawable._svg.getDocumentViewBox();
	if (documentViewBox == null) {
		float documentWidth = drawable._svg.getDocumentWidth();
		float documentHeight = drawable._svg.getDocumentHeight();
		if (documentWidth <= 0 && documentHeight <= 0) {
			documentWidth = 256;
			documentHeight = 256;
			drawable._svg.setDocumentWidth(documentWidth);
			drawable._svg.setDocumentHeight(documentHeight);
		}
		drawable._svg.setDocumentViewBox(0, 0, documentWidth, documentHeight);
		documentViewBox = drawable._svg.getDocumentViewBox();
	}

	int docWidth = XulUtils.roundToInt(documentViewBox.width());
	int docHeight = XulUtils.roundToInt(documentViewBox.height());
	if (width == 0 && height == 0) {
		width = docWidth;
		height = docHeight;
	} else if (width == 0) {
		xScalar = yScalar = (float)(height)/docHeight;
		width = XulUtils.roundToInt(docWidth*xScalar);
		docWidth = width;
		docHeight = height;
	} else if (height == 0) {
		xScalar = yScalar = (float)(width)/docWidth;
		height = XulUtils.roundToInt(docHeight*xScalar);
		docWidth = width;
		docHeight = height;
	} else {
		float wScalar = (float) width / docWidth;
		float hScalar = (float) height / docHeight;
		if (wScalar > hScalar) {
			docWidth *= wScalar;
			docHeight *= wScalar;
			xScalar = yScalar = wScalar;
		} else {
			docWidth *= hScalar;
			docHeight *= hScalar;
			xScalar = yScalar = hScalar;
		}
		offsetX = (docWidth - width) / 2.0f;
		offsetY = (docHeight - height) / 2.0f;
	}

	XulUtils.ticketMarker ticketMarker = new XulUtils.ticketMarker("BENCH!!!", true);
	ticketMarker.mark();

	drawable._cachedBmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	Canvas c = new Canvas(drawable._cachedBmp);
	c.translate(-offsetX, -offsetY);
	c.scale(xScalar, yScalar);
	drawable._svg.renderToCanvas(c, documentViewBox);

	ticketMarker.mark("svg");
	Log.d("BENCH", ticketMarker.toString());

	drawable._url = url;
	drawable._key = imageKey;
	return drawable;
}