Java Code Examples for com.caverock.androidsvg.SVG#getFromResource()

The following examples show how to use com.caverock.androidsvg.SVG#getFromResource() . 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: VectorDrawable.java    From Carbon with Apache License 2.0 6 votes vote down vote up
public VectorDrawable(Resources res, int resId) {
    if (resId == 0)
        return;
    try {
        SVG svg = cache.get(resId);
        if (svg == null) {
            svg = SVG.getFromResource(res, resId);
            cache.put(resId, svg);
        }
        float density = res.getDisplayMetrics().density;

        float width = svg.getDocumentViewBox().width();
        float height = svg.getDocumentViewBox().height();

        int intWidth = (int) (width * density);
        int intHeight = (int) (height * density);
        state = new VectorDrawableState(svg, intWidth, intHeight);
        setBounds(0, 0, state.intWidth, state.intHeight);
    } catch (SVGParseException e) {

    }
}
 
Example 3
Source File: RawResourceSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(@NonNull Uri source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SVG.getFromResource(mResources, ResourceUtils.getRawResourceId(mResources, source));
    } catch (SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example 4
Source File: SvgUtils.java    From ACDD with MIT License 5 votes vote down vote up
/**
 * Loading the svg from the resources.
 *
 * @param context     Context object to get the resources.
 * @param svgResource int resource id of the svg.
 */
public void load(Context context, int svgResource) {
    if (mSvg != null) return;
    try {
        mSvg = SVG.getFromResource(context, svgResource);
        mSvg.setDocumentPreserveAspectRatio(PreserveAspectRatio.UNSCALED);
    } catch (SVGParseException e) {
        Log.e(LOG_TAG, "Could not load specified SVG resource", e);
    }
}
 
Example 5
Source File: SvgUtils.java    From android-pathview with Apache License 2.0 5 votes vote down vote up
/**
 * Loading the svg from the resources.
 *
 * @param context     Context object to get the resources.
 * @param svgResource int resource id of the svg.
 */
public void load(Context context, int svgResource) {
    if (mSvg != null) 
        return;
    try {
        mSvg = SVG.getFromResource(context, svgResource);
        mSvg.setDocumentPreserveAspectRatio(PreserveAspectRatio.UNSCALED);
    } catch (SVGParseException e) {
        Log.e(LOG_TAG, "Could not load specified SVG resource", e);
    }
}
 
Example 6
Source File: SvgHelper.java    From google-io-2014-compat with Apache License 2.0 5 votes vote down vote up
public void load(Context context, int svgResource) {
    if (mSvg != null) return;
    try {
        mSvg = SVG.getFromResource(context, svgResource);
        mSvg.setDocumentPreserveAspectRatio(PreserveAspectRatio.UNSCALED);
    } catch (SVGParseException e) {
        Log.e(LOG_TAG, "Could not load specified SVG resource", e);
    }
}
 
Example 7
Source File: SvgHelper.java    From Android-Anim-Playground with MIT License 5 votes vote down vote up
public void load(Context context, int svgResource) {
    if (mSvg != null) return;
    try {
        mSvg = SVG.getFromResource(context, svgResource);
        mSvg.setDocumentPreserveAspectRatio(PreserveAspectRatio.UNSCALED);
    } catch (SVGParseException e) {
        Log.e(LOG_TAG, "Could not load specified SVG resource", e);
    }
}
 
Example 8
Source File: SvgHelper.java    From google-io-2014 with Apache License 2.0 5 votes vote down vote up
public void load(Context context, int svgResource) {
    if (mSvg != null) return;
    try {
        mSvg = SVG.getFromResource(context, svgResource);
        mSvg.setDocumentPreserveAspectRatio(PreserveAspectRatio.UNSCALED);
    } catch (SVGParseException e) {
        Log.e(LOG_TAG, "Could not load specified SVG resource", e);
    }
}
 
Example 9
Source File: SvgHelper.java    From road-trip with Apache License 2.0 5 votes vote down vote up
public void load(Context context, int svgResource) {
    if (mSvg != null) return;
    try {
        mSvg = SVG.getFromResource(context, svgResource);
        mSvg.setDocumentPreserveAspectRatio(PreserveAspectRatio.UNSCALED);
    } catch (SVGParseException e) {
        Log.e(LOG_TAG, "Could not load specified SVG resource", e);
    }
}