I want to create an app that will display position on some floor plan. Navigation is implementing via WiFi in certain way, I've done it and so now I have a problem of displaying floor plan.
It might be in some vector format, after surfing internet for some time I've decided that it must be svg file.
I found some solutions, but it isn't working for me!
Library svg-android
There is opportunity to display .svg files, but only "simple" files. It works fine only for file in tutorial, but not for any other .svg file (for example, some other file, that you'll create with Inkscape).
So, I decided, that I'll parse .svg file, make DOM from it, somehow get objects and attributes and draw it via OpenGL ES.
Apache Batik
At first glance, very good solution, but there is a problem. Android has some "native" apache libraries and when I try to do something with batik, it throws NoClassDefFoundError, because it's searching not in batik libraries, but in "native" libraries.
Of course, we can add source code in our project, take only batik parser for .svg files and edit it in some way, but there is a lot of work, with same success we can write our own parser.
Tiny Line
There is no trial version, but if we'll see description of how it works for svg files and android, we'll see that there is only rasterization of such files and that's all.
Is there any solution better than writing own parser?
Did anyone come across this problem?
I would suggest using #1. Don't write your own parser. It's just going to be a huge headache.
How detailed does your floor plan have to be? android-svg supports SVG fairly well. It just doesn't have great support for filters or light sources. Your SVG isn't going to have those in them (I hope).
If you don't want to do that, look into quad trees. You can render out a huge image and break that down into a quadtree like format then only load the quads you require.
I have authored an SVG libaray for android the website is
http://www.vectoroid.com
the main thing missing is SVG arc support this is currently fixed and will be in a release in the near future.
I am looking for feedback on it, as i have been working on it for about a year. So if you have any please do tell ...
I've using yet another SVG for Android; seems it is relatively new.
GPLv3, CSS2 support, fonts, texts and spans, linear and radial gradients, SVG and SVGZ, initial filtering support, images from assets, from web and inline base64-encoded images. Fastest from all I've tried.
Of course filters support might be better, but except this it works well and even displays 20-megabytes SVG files.
Successfully tested these 2 libraries:
https://github.com/BigBadaboom/androidsvg - Apache License 2.0
https://scand.com/products/svgkit-android/ - needed tweaking to compile with modern SDK (suppress warnings, update gradle file); LGPL / commercial
androidsvg looks better so far.
Related
Sorry if this is a repeat but I searched diligently and didn't find this question asked yet...
So back in ye olden days of Android, you could just add something like this to a WebView's source html:
<img src='file:///android_res/drawable/my.png'/>
And it would display my.png correctly in the WebView. But-- Android now supports (and prefers we use) these new-fangled vector drawables, and Android Studio's Vector Asset Studio makes it really easy to import them from SVG files or whatever.
The great thing is that for backwards compatibility, .pngs are automatically generated during the build for various dpi/screen sizes to support older devices. So if you're targeting an older device, there are .png images there.
If only I could reach them. Because, as far as I can tell, using vector graphics does break those file:///android_res/drawable/ img links in WebViews. Which is weird, because as I say there are .png files to see, if it only looked.
I've thought about a few methods to fix this, but none have worked:
Since .pngs are generated on-the-fly and are included in the .apk, I thought maybe I could point directly to one of the generated files with something like file:///android_res/drawable-hdpi-v4/my.png. (I checked the .apk file and that's where one of them was..) But no such luck there. Broken image.
Okay, I thought-- maybe there's a way to get the WebView to display the vector objects directly. That is, maybe the WebView would recognize an <img src="file:///android_res/drawable/my_image.xml"/> or something similar. I mean, Chrome can render svg right? Maybe it supports the .xml vector format too. But no dice here either. (Even if it had worked, it would be unlikely to support older pre-chromium webview versions.)
The third thing I tried is to include just one xxxhdpi-sized .png in res/drawable so that the webview would find it and hopefully display it. Unfortunately, this doesn't work either. It appears that just having an .xml vector in /drawable is enough to have it block the png, no matter if it's in the /drawable or /drawable-xxxhdpi directories.
So the obvious question: Is there a way to get the WebView to either display the vector xml (or the associated support .png that was generated)? How do we access drawables from HTML in a WebView w/Vector drawables? Esp. without having to do anything programmatically?
Anyone know how this is supposed to work? I guess the next thing to do is delve into the chromium/android source to try to find out how file:///android_res/drawable/ works, but that doesn't sound fun, so if anyone has an answer, that would be helpful.
I'm probably missing something really obvious here. Thx in advance!
Update: Other things I tried/ruled out include (1) removing underscores in image names (as I thought they might be replaced with "/"), (2) various permutations of baseurl in loadDataWithBaseUrl()
Well, four years later and the best solution I've come up with is just to have two vector files-- (1) the xml Android vector file for the app, and then (2) the identical image in the .svg format for the webview. This is still a smaller solution compared with providing a seperate .png or .gif for every dpi, etc.
SVG and the vector format are internally very similar, so it's not difficult to convert one to the other. In fact, Android Studio will convert SVG->XML. If you want to go the other way, just compare a few examples.
So just put your svgs in assets/svg/, and then you can access from a webview using <img src='file:///android_asset/svg/mysvg.svg'/> in your HTML.
There's still a storage hit. But svgs are relatively tiny (and you can minify-- ie, scoop out some of the extra fluff in the SVG file that isn't used by the webview) so it's not as bad as the alternative-- providing large binary image files in the apk.
How to convert psd image to xml code to reducing size of android application and work effectively and android xml design improve to application performance fast.
you can use these software for convert the psd to xml
http://www.psd2androidxml.com/
2nd is you can use the png file to drawable folder and use it
There are some ways to achieve this.
One way is to watch tutorials and learn how to do it by yourself.
The second way is to use some automated online tools, however they are not reliable, and you will have to correct the code manually.
The site that was mentioned by Nirav Shah, www.psd2androidxml.com, is a service, not a software. You send the PSD files to them, and they hand code them according to your specifications. It may cost more than the previous two solutions, but the result is better compared to automated online tools.
I'm making a illustrated instruction for how to use an app that will be needed
for Android/iPhone
I'm not much into coding for Android and I though the client just needed the
illustration but he asks:
"We will need the illustration saved to a file that we can run on mobile devices (iPhone/Android) as well as the source code."
Isn't jpg enough? is there some additional code that you android programmers are
aware of?
No. In Android you can just use a Drawable. This can be a number of different file formats, including your jpeg. It may be good to have a look at Android Asset Studio. With this tool you can get a nice zip file for all your different screen densities. If you keep the file structure that asset studio outputs then Android will do all the heavy lifting for you.
It might also help you to know something about 9-patches. This is how Android knows how to resize and stretch your image. Asset Studio has an option to set this as well.
I have a problem with an image for an android game. The problem is not a problem with the code because the code that I use I took from a book (Beginning Android 4 Games Developer).
The problem is this: I know the format that I have to use in android: png, but I don't know the settings for this format that I have to use (like RGB565...). Because if I use simply png, when I run the game the images are not good. So I need someone to explain to which settings I need to use for images for android games.
P.S The software that I used is photoshop. If there is better software for this purpose tell me.
I think there is a strong misconception in your understanding of Android and how it implements graphics. You are not constrained to .png for nearly any of your development. The .png and .9.png are only enforced strictly for managing drawable constants.
Android uses Java and has the capability to utilize nearly any graphical format. In particular native support for .bmp, .png, and .jpg are present for every device and Android OS version. You may even create your graphics in realtime byte by byte.
As for a good image editor, there are a number out there. I often use a combination of GIMP and Photoshop, myself.
Hope this helps,
FuzzicalLogic
I would like to use more vector drawings in my Android applications. Providing images isn't as space efficient or as scalable as I would like it to be.
Android provides a series of Drawable file formats, such as ShapeDrawable, which can be combined in a LayeredDrawable. To go very far down this path, it would be nice if there was a designer for visualizing the results, doing the drawing in, and handling all the resulting files.
C# WPF has Expression Blend, Adobe has Flash CS4, and the iPhone has Opacity. So my question is, is there a designer or drawing tool for Android?
Note: Other questions have talked about using SVG in Android. Android doesn't have native support for SVG, so the only way to do it is with an external library. I would like to avoid that and am asking for a developer side tool. An SVG to Drawable converter would be fine, but I'm not aware of one.
I faced the same problem and I've just released a little library on github that allow to export svg to drawable more quickly.
https://github.com/r3gis3r/svg2drawable
Hope can be useful for you.
For the sub-subset of rectangular ShapeDrawables there is a nice tool online at Angry Tools which allows one to edit a button's drawable:
http://angrytools.com/android/button/
I would suggest you using Vector Drawables, which are natively supported by Android 5.0+. There is an SVG to VectorDrawable Converter, so you can create SVG images in your favorite editor.
BetterVectorDrawable is the VectorDrawable implementation for Android 4.0+ with configurable fall-back behavior on Android 5.0+.
SVG to VectorDrawable Converter is the batch converter of SVG images to Android VectorDrawable XML resource files. Online version exists.
Links point to readmes, which provide enough information on how to use the lib and the converter.
Yes, there is.
https://play.google.com/store/apps/details?id=com.tiraisoft.drawabledesigner
It runs on Android so you can see the changes live.
Disclaimer:
I'm the author