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.
Related
I have made a website using HTML5.
However, I'm trying to make the app using the CSS, JavaScript and HTML I used for the website. Is that somehow possible?
I must use Android Studio.
Nope, you can't do that.
Android Studio is based on Java (logic) and XML (design).
XML and CSS are a little bit similar. You have paddings and margins too.
However. Prepare yourself to put work into the project.
But why do you need an app when you can also show the same contents in a website that works on way more devices? You can also use a WebView to show your website in the app.
If it must be native and you can't use a WebView, just rebuilt the design, Check out the material design guidelines, stick to them and your app will be easy to use for the users and look awesome.
Links:
https://material.google.com/ (read through the components stuff)
https://design.google.com/icons/ (all icons)
We are going to build a android library which will provide a API for developers to build applications which can embed certain charts easily (the charts would display specific contents particular to the API).
Since there are no charting libraries that are dominant in the market, what library would be ideal for this. Some of the chart types need to be developed for this that are currently not supported by any native libraries( like heatmaps). Keeping this in mind would you guys advice going in for a native lib or with webview embedded HTML/JS.
The problem with webview is that you cannot package assets(html/js) on a library project like resources. So its again a additional step for the developers using the library to copy the assets to the project.
Additional Info:
My API should allow the developer to easily embed a chart. Something like
<org.example.customPieChart
android:id="#+id=chart"
android:width="150dip"
android:height="150dip"
/>
And the API should take care of everything else. Only if the developer wants to change color, customize the stuff then possibly he will use the other parts of the API and do that.
I have used aChartEngine Library for the chart and its working fine. So I am suggesting you aChartEngine.
I'm building an Android app natively and my client requested me to add a sliding bannar used to be on mobile websites with JQuery Mobile and http://swipejs.com/.
Is there any native equivalent Views (or component?) that display images and slide them?
You can use ViewPager - finger-oriented view container. It was introduced in API level 11 but also available through Support Library. Also you may look to ImageSwitcher
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.
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.