SVG support on Android - android

Does Android support SVG? any example?

The most complete answer is this:
The Android 2.x default browser does not natively support SVG.
The Android 3+ default browsers DO support SVG.
To add SVG support to 2.x versions of the platform, you have two basic choices:
Install a more capable browser (like Firefox or Opera Mobile - both support SVG)
Use a JavaScript polyfill that can parse SVG and render it to an HTML5 canvas
The first option is okay if you're just trying to make SVG work for personal uses or a limited (controllable) set of users. It's not a great option if you want to use SVG while targeting a large, uncontrolled user base.
In the later case, you want to use a polyfill. There are many JavaScript libraries available today that can prase SVG and render to a canvas. Two examples are:
canvg
fabric.js
Using a polyfill, you can render your SVG in a canavs on all versions of Android 2.x.
For a more complete example of this approach, you can refer to this blog post that discusses the use of the canvg polyfill for making Kendo UI DataViz charts (SVG-based) work on Android 2.x. Hope that helps!

There is a new open-source library that supports loading and drawing SVG Basic 1.1 files: https://github.com/pents90/svg-android. Performance is good as the actual drawing is handled natively by an android.graphics.Picture object.

There is a new library (under active development) androidsvg which allows one to incorporate svg images directly in to projects. It has the advantage of defining an SVGImageView which allows one to incorporate an svg directly in the layout xml.
Finally, including svg in android is straightforward.
More details: Stack Overflow post

Android supports vector drawables: https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html
And there exists an Android SVG to VectorDrawable Converter:
http://inloop.github.io/svg2android/

I know my solution is somewhat hardcore, but it works great, doesn't require any external libraries (at least not in your final code) and is extremely fast.
1) Just take an existing SVG loading library, such as for example svg-android-2 (which is a fork of svg-android mentioned in another answer, just with more features and bugfixes): https://code.google.com/p/svg-android-2/
2) Write a simple app that will do nothing else but load and display your SVG image.
3) Modify the SVG loading library, so that it prints the Java code that creates the Picture class or saves it in a String variable.
4) Copy-paste the Java code obtained this way into the app you are writing.
To get more information about this technique and download sample source code, go to my blog:
http://androiddreamrevised.blogspot.it/2014/06/transforming-svg-images-into-android.html
You can get a working example of this technique from Google Play here:
https://play.google.com/store/apps/details?id=pl.bartoszwesolowski.svgtodrawablesample
Here's an example of a commercial app created using this technique (Milan metro map):
https://play.google.com/store/apps/details?id=pl.bartoszwesolowski.atmmetroplan
Notice how fast the map loads and how pretty it looks, even when magnified.

Firefox for Android supports SVG.

Opera Mobile for Android supports svg, and Opera Mini supports static svg content.

Related

Get groups/id from svg image in android

I am developing an android app using the library androidsvg. Basically, I'm using an svg image as a map, each part of the map has it own group and id.
Is it possible to get the id's and add onClick listeners using only one svg img? If not, any suggestions about how to do that?
AndroidSVG is just a rendering library. It has no support for interactivity (yet - it is on the todo list).
In the meantime the simplest solution is probably just to use a WebView. Be aware though that WebView only has native support for SVG from Android 3.0 on. If you need to support earlier versions of Android, there are ways to do it with JS polyfills. See: Android webView support for svg rendering.

Extensive use of SVG in phonegap project

I have a web site that makes extensive use of SVG for scalable maps. After using phonegap ton convert to an app for an android, none of the graphics are rendered correctly or are visible. What is recommended to address this? Should I convert the SVG? Recommend a plug-in...? Would phonegap build handle such a task?
Thanks!
I downloaded and used Cordova and all rendering worked perfectly.

Is there a (somewhat high level) C++ library to create pdf documents that runs on iOS and Android?

I need a C++ library that runs on Android and iOS which can be used to create PDF documents.
So far I have found libHaru:
libHaru is a free, cross platform, open source library for generating PDF files.
The library seems fine and I already found a working example on how to use it with iOS.
But I would like to have a library less "low level", because in libHaru you have to manually create new pages, line breaks etc. So the question is if someone can advice me any C++ library which can run on Android and iOS and is a little bit more high level.
As a bonus: It would be great, if that library is also free (as in freedom) or at least free to use.
Edit: I have tried Qt and it is rather clumsy to use in such an early development stage (regarding iOS and Android development). I would appreciate a stable library with good documentation provided.
You can use Qt for that. The class you would be looking for is QPdfWriter The nice thing about it is, that as you draw onto that thingy, you can replace the QPdfWriter with different kinds of QPaintDevices, like QWidget or QImage and so forth. It's very generic and high level, but Qt is also quite big.

how to embed an SVG enabled webkit webview in an Android app?

Is there a way to embed a customized webkit engine in an app to add a WebView with SVG support ?
The according Bug Entry mentions some android core dependencies which seem not-so-easy to replace, not sure if all of that could be included in a built to provide exactly a webkit webview with your app.
However, in general one can use another library project to be referenced and included on compilation. And then there is a way to include other JAR files, a way to convert an existing project into a library as well as even a way to butcher an .apk and get the code out (which again you can turn into a libary).
Never done it, but in theory, get a library, .jar or .apk of the browser you want to bundle (as mentioned the beginning seems not the best candidate), look into the original code what is done to instantiate that browsers view in an activity - and off you go.
Would love to hear when you or anybody else has accomplished to do such a thing, i couldn't wait to see if we could bundle it with multitouch enabled (another big drawback in 2.x) for multitouch on the android stock browser on 2.x devices i started a polyfill project out of desparation (which works surprisingly well, but is also way simpler than emulating a complete SVG interpreter), so for matter of SVG and providing the best browser runtime for the job, this would be great.
P.S. There is one completely different workaround depending on what you want to do with SVG. If it's just some small stuff to fill on the screen at times you might check google for "svg polyfill" which leads to a myriad of solutions - i couldn't recommend one straightaway, as those implementations are so different that you should evaluate them with your actual app.

Working with SVG on Android

I need to develop a small game that should use SVG elements.
I know I can use the android svg library.
My question is what performance should I expect from this library - is it good enough?
Are there any other good libraries I can use?
Thanks
Good enough for what? You need to be more specific. The Android graphics package has native implementation for most (all?) of the SVG primitives, so the only overhead of the library should come from parsing the XML. Drawing/refresh speed will mostly depend on the actual device hardware, so you'll need to benchmark with a specific device in mind.
Try http://code.google.com/p/svg-android/ it was used by google in Androidify and from my experience it is the best solution out there (although it doesn't support the full SVG spec).
There is also AndroidSVG (http://code.google.com/p/androidsvg/) which implements more of the spec than svg-android.

Categories

Resources