com.larvalabs.svgandroid.SVGParser Java Examples

The following examples show how to use com.larvalabs.svgandroid.SVGParser. 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: AsyncExporter.java    From Android-Material-Icons with Apache License 2.0 6 votes vote down vote up
private Bitmap getBitmapSvg(Params params, String fileName, int densityIndex) {
    try {
        FileInputStream inputStream = new FileInputStream(mContext.getFilesDir() + MainActivity.ICONS_PATH + fileName);
        SVG svg = SVGParser.getSVGFromInputStream(inputStream);

        // Icon size relative to current processed density
        int fSize = ICONS_SIZE[densityIndex];

        Bitmap bitmap = Bitmap.createBitmap(fSize, fSize, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawPicture(svg.getPicture(), new Rect(0, 0, fSize, fSize));

        Bitmap finalBitmap = createTintedBitmap(bitmap, params.desiredColor);
        bitmap.recycle();
        return finalBitmap;
    } catch (IOException | SVGParseException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #2
Source File: PaperPlaneView.java    From SparkleMotion with MIT License 6 votes vote down vote up
private void init() {
    // Setup the paint.
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(Color.WHITE);
    mPaint.setStrokeWidth(10);
    mPaint.setPathEffect(new DashPathEffect(new float[] { 50f, 50f }, 100f));

    // Setup the bitmap and path.
    mPlaneBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.plane);

    // Make sure the plane is not shown before the animation.
    mPlaneCoordinate[0] = -mPlaneBitmap.getWidth();
    mPlaneCoordinate[1] = -mPlaneBitmap.getHeight();

    mPath = SVGParser.parsePath(PATH);
}
 
Example #3
Source File: SvgAndroidSampleActivity.java    From android-opensource-library-56 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_svg_android_sample);

    mMatrix = new Matrix();
    mImageView = (ImageView) findViewById(R.id.image);
    checkLayer(mImageView);

    SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.cute_fox);
    mImageView.setImageDrawable(svg.createPictureDrawable());
    mImageView.setImageMatrix(mMatrix);

    final ScaleGestureDetector detector = new ScaleGestureDetector(this,
            this);
    mImageView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return detector.onTouchEvent(event);
        }
    });
}
 
Example #4
Source File: SVGView.java    From Android-Material-Icons with Apache License 2.0 5 votes vote down vote up
@Override
protected SVG doInBackground(String... params) {
    try {
        FileInputStream inputStream = new FileInputStream(params[0]);
        SVG svg = SVGParser.getSVGFromInputStream(inputStream, Color.BLACK, Color.DKGRAY);
        inputStream.close();

        return svg;
    } catch (IOException | SVGParseException e) {
        Log.e("SVG", params[0]);
        e.printStackTrace();
        return null;
    }
}
 
Example #5
Source File: Utils.java    From Android-Material-Icons with Apache License 2.0 5 votes vote down vote up
public static Drawable getDrawableForSvg(Context context, String fileName) {
    try {
        FileInputStream inputStream = new FileInputStream(context.getFilesDir() + MainActivity.ICONS_PATH + fileName);
        SVG svg = SVGParser.getSVGFromInputStream(inputStream, Color.BLACK, Color.DKGRAY);

        return svg.createPictureDrawable();
    } catch (IOException | SVGParseException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #6
Source File: PdDroidPatchView.java    From PdDroidPublisher with GNU General Public License v3.0 5 votes vote down vote up
public PdDroidPatchView(Activity activity, PdPatch patch, PdDroidPartyConfig config) {
	super(activity);
	
	this.patch = patch;
	this.config = config;
	
	// disable graphic acceleration to have SVG properly rendered
	// not needed prior to API level 17
	// not possible prior to API level 11
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
		setSoftwareMode();
	}
	
	setFocusable(true);
	setFocusableInTouchMode(true);
	
	this.setOnTouchListener(this);
	this.setId(R.id.patch_view);
	
	paint.setColor(backgroundColor);
	paint.setAntiAlias(true);
	
	res = activity.getResources();
	
	// if there is a splash image, use it
	splash_res = res.getIdentifier("splash", "raw", activity.getPackageName());
	if (splash_res != 0) {
		// Get a drawable from the parsed SVG and set it as the drawable for the ImageView
		background = SVGParser.getSVGFromResource(res, splash_res).getPicture();
	} else {
		loadBackground();
	}
}
 
Example #7
Source File: SVGRenderActivity.java    From android-opensource-library-56 with Apache License 2.0 4 votes vote down vote up
public void setSVGResourceId(int id) {
    mSvg = SVGParser
            .getSVGFromResource(getContext().getResources(), id);
    mPict = mSvg.getPicture();
    mPict.endRecording();
}