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.
Related
Good day!
I am a newbie to Android programming, and by being the curious animal that i am, there are a few things that i would like to know about the Android libraries, the support libraries to be specific, i did my homework(google) and found some answers but they are either old or unclear;
• How significant is performance hit inflicted by the support library if any?
• I hear that using support library makes your app, memory hogs. is this that bad when developing memory intensive apps (etc image-processing/signal-processing)?
• Let's say I'm completely ignoring any Android below 4.2, is it possible to make a "Support-library free" application? or rather, is there a corresponding alternative native Class or mechanism for every support library class or mechanism(ex. ViewPager)?
• And with regards to later support libraries(ex. V7), are they cumulative or they just add new features?
Thank you.
The Support Library includes a large amount of unique functionality that is not found elsewhere - this includes elements such as ViewPager. AppCompat, for example, is one of the few ways to get a consistent look to your app between pre-5.0 and 5.0+ devices (where 5.0 changed to Material Design).
There is little to no performance impact when using the Support Library. There is, of course, an increase in the size of your APK which can be countered for the most part by using ProGuard to strip out unused classes in addition to shrinkResources to remove unused bitmaps.
I'd suggest reading through the full list of features or watching the Support Library overview video to better understand what is in each library and why you might want to use each.
Does Xamarin support 9-patch images in a cross-platform way? The ideal would be to create the image from the same file for iOS, Android, and Windows.
As best I can tell, the answer appears to be "not in any way that makes sense for me to use." The best option is going to be to have separate image resources for each platform. The splat library does do some cross-platform image handling, but not 9-patch, and I'm not sure about its performance.
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.
I have just learned about Android nine-patches idea, and it is a pretty good idea. My question is if it is an Android pattern or there is implementations like that for other platforms, probably differently named.
Thanks!
In iOS you can also strech images in code with StretchableImages. You specify the left, right caps and the "rest" is stretched. I think is basicaly the same idea, this is something like a tutorial on it: http://blog.chomperstomp.com/creating-dynamically-re-sizable-buttons-for-iphone-apps/
There is another SO question here that mentions a library released under Apache license for iPhone. I haven't used it but is worth checking out.
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.