com.bumptech.glide.load.resource.SimpleResource#com.caverock.androidsvg.SVGParseException源码实例Demo

下面列出了com.bumptech.glide.load.resource.SimpleResource#com.caverock.androidsvg.SVGParseException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: NaviBee   文件: GroupConversation.java
public GroupConversation(String id, Date readTimestamp, Date createTimestamp, String name, String icon, Map<String, Boolean> users, String creator) {
    super(id, readTimestamp, createTimestamp);
    this.name = name;
    for (String user:users.keySet()){
        members.add(user);
    }
    this.creator = creator;
    this.createDate = createTimestamp;

    // generate icon using conversation id
    try {
        String hash = HashUtilitiesKt.sha256String(id);
        String svgString = Jdenticon.Companion.toSvg(hash, 256, 0.08f);
        iconBitmap = imageFromString(svgString);
    } catch (SVGParseException e) {
        iconBitmap = null;
    }

}
 
源代码2 项目: NaviBee   文件: GroupConversation.java
private static Bitmap imageFromString(String svgAsString) throws SVGParseException {

        SVG svg = SVG.getFromString(svgAsString);

        // Create a bitmap and canvas to draw onto
        float   svgWidth = (svg.getDocumentWidth() != -1) ? svg.getDocumentWidth() : 500f;
        float   svgHeight = (svg.getDocumentHeight() != -1) ? svg.getDocumentHeight() : 500f;

        Bitmap  newBM = Bitmap.createBitmap(Math.round(svgWidth),
                Math.round(svgHeight),
                Bitmap.Config.ARGB_8888);
        Canvas bmcanvas = new Canvas(newBM);

        // Clear background to white if you want
        bmcanvas.drawRGB(255, 255, 255);

        // Render our document onto our canvas
        svg.renderToCanvas(bmcanvas);

        return newBM;
    }
 
源代码3 项目: Markwon   文件: SvgMediaDecoder.java
@NonNull
@Override
public Drawable decode(@Nullable String contentType, @NonNull InputStream inputStream) {

    final SVG svg;
    try {
        svg = SVG.getFromInputStream(inputStream);
    } catch (SVGParseException e) {
        throw new IllegalStateException("Exception decoding SVG", e);
    }

    final float w = svg.getDocumentWidth();
    final float h = svg.getDocumentHeight();
    final float density = resources.getDisplayMetrics().density;

    final int width = (int) (w * density + .5F);
    final int height = (int) (h * density + .5F);

    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
    final Canvas canvas = new Canvas(bitmap);
    canvas.scale(density, density);
    svg.renderToCanvas(canvas);

    return new BitmapDrawable(resources, bitmap);
}
 
源代码4 项目: microMathematics   文件: CustomImageView.java
private void setSvg(String svgData)
{
    svg = null;
    try
    {
        svg = SVG.getFromString(svgData);
        originalWidth = (int) svg.getDocumentWidth();
        originalHeight = (int) svg.getDocumentHeight();
        svg.setDocumentWidth("100%");
        svg.setDocumentHeight("100%");
        svg.setDocumentViewBox(0, 0, originalWidth, originalHeight);
    }
    catch (SVGParseException e)
    {
        // nothing to do
    }
    if (svg != null)
    {
        this.svgData = svgData;
    }
    imageType = this.svg == null ? ImageType.NONE : ImageType.SVG;
}
 
源代码5 项目: proofmode   文件: UIHelpers.java
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();
	}
}
 
源代码6 项目: Carbon   文件: VectorDrawable.java
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) {

    }
}
 
源代码7 项目: PowerFileExplorer   文件: SvgDecoder.java
public Resource<SVG> decode(InputStream source, int width, int height) throws IOException {
    try {
        SVG svg = SVG.getFromInputStream(source);
        return new SimpleResource<SVG>(svg);
    } catch (SVGParseException ex) {
        throw new IOException("Cannot load SVG from stream", ex);
    }
}
 
源代码8 项目: GlideToVectorYou   文件: SvgDecoder.java
public Resource<SVG> decode(@NonNull InputStream source, int width, int height,
                            @NonNull Options options)
    throws IOException {
  try {
    SVG svg = SVG.getFromInputStream(source);
    return new SimpleResource<>(svg);
  } catch (SVGParseException ex) {
    throw new IOException("Cannot load SVG from stream", ex);
  }
}
 
源代码9 项目: SvgGlidePlugins   文件: SvgUtils.java
public static SVG getSvg(@NonNull File file) throws SVGParseException, IOException {
    if (!file.exists()) {
        throw new FileNotFoundException("File: '" + file.getAbsolutePath() + "' not exists");
    }

    try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
        return SVG.getFromInputStream(is);
    }
}
 
源代码10 项目: SvgGlidePlugins   文件: SvgUtils.java
public static SVG getSvg(@NonNull FileDescriptor descriptor)
        throws SVGParseException, IOException {

    try (InputStream is = new BufferedInputStream(new FileInputStream(descriptor))) {
        return SVG.getFromInputStream(is);
    }
}
 
源代码11 项目: SvgGlidePlugins   文件: ByteBufferSvgDecoder.java
@Override
SVG loadSvg(@NonNull ByteBuffer source, int width, int height, @NonNull Options options) throws SvgParseException {
    try (InputStream is = ByteBufferUtil.toStream(source)) {
        return SVG.getFromInputStream(is);
    } catch (IOException | SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
源代码12 项目: SvgGlidePlugins   文件: InputStreamSvgDecoder.java
@Override
SVG loadSvg(@NonNull InputStream source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SVG.getFromInputStream(source);
    } catch (SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
源代码13 项目: SvgGlidePlugins   文件: FileSvgDecoder.java
@Override
SVG loadSvg(@NonNull File source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SvgUtils.getSvg(source);
    } catch (IOException | SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
源代码14 项目: SvgGlidePlugins   文件: RawResourceSvgDecoder.java
@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);
    }
}
 
源代码15 项目: SvgGlidePlugins   文件: StringSvgDecoder.java
@Override
SVG loadSvg(@NonNull String source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SVG.getFromString(source);
    } catch (SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
源代码16 项目: SvgGlidePlugins   文件: FileDescriptorSvgDecoder.java
@Override
SVG loadSvg(
        @NonNull FileDescriptor source,
        int width,
        int height,
        @NonNull Options options
) throws SvgParseException {
    try {
        return SvgUtils.getSvg(source);
    } catch (IOException | SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
@Override
public void setDataSource(@NonNull DataSource source) throws IOException {
    try {
        mSVG = SVG.getFromInputStream(source.toStream());
    } catch (SVGParseException e) {
        e.printStackTrace();
    }
}
 
源代码18 项目: Markwon   文件: SvgPictureMediaDecoder.java
@NonNull
@Override
public Drawable decode(@Nullable String contentType, @NonNull InputStream inputStream) {

    final SVG svg;
    try {
        svg = SVG.getFromInputStream(inputStream);
    } catch (SVGParseException e) {
        throw new IllegalStateException("Exception decoding SVG", e);
    }

    final Picture picture = svg.renderToPicture();
    return new PictureDrawable(picture);
}
 
源代码19 项目: ACDD   文件: SvgUtils.java
/**
 * 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);
    }
}
 
源代码20 项目: incubator-taverna-mobile   文件: SvgDecoder.java
public Resource<SVG> decode(InputStream source, int width, int height) throws IOException {
    try {
        SVG svg = SVG.getFromInputStream(source);
        return new SimpleResource<SVG>(svg);
    } catch (SVGParseException ex) {
        throw new IOException("Cannot load SVG from stream", ex);
    }
}
 
源代码21 项目: android-pathview   文件: SvgUtils.java
/**
 * 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);
    }
}
 
源代码22 项目: fresco   文件: SvgDecoderExample.java
@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;
}
 
源代码23 项目: google-io-2014-compat   文件: SvgHelper.java
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);
    }
}
 
源代码24 项目: Android-Anim-Playground   文件: SvgHelper.java
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);
    }
}
 
源代码25 项目: google-io-2014   文件: SvgHelper.java
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);
    }
}
 
源代码26 项目: road-trip   文件: SvgHelper.java
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);
    }
}
 
源代码27 项目: starcor.xul   文件: XulSVGDrawable.java
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;
}