I'm new to game programming, and am trying to write the Map storage portion of my 2D tile based game on android. At first, my plan was to store the maps in XML. I found a tool (http://www.mapeditor.org/) that stores the created maps in a format close to what I was thinking. However, it seems like Android is very limited when it comes to XML. I'm used to working with XML Beans which doesn't work on Android, though I admit XML Beans would probably be too resource heavy for mobile devices anyways. However, after searching around for XML parser options, it seems like even basic XML validation isn't even included by default with the Android SDK. It's starting to look like XML might not be the best answer.
Does anyone know of a good standard way to store map configuration besides XML? Or some strong XML tools available in Android that handle validation (against a defined schema), and preferably simple parsing? I would really like to avoid defining my own flat file text format for maps...
Check out AndEngine. If I remember correctly AndEngine already has the classes needed to load a map from an XML file for rendering.
As far as a standard way to store map configurations, I would say XML is the way to go. I mean you could create your own format, but why re-invent the wheel?
I parse XML in Android with javax.xml.parsers.DocumentBuilderFactory and various other XML parts. It hasn't failed me yet!
For example see: http://www.developerfusion.com/code/2064/a-simple-way-to-read-an-xml-file-in-java/
Related
My app is going to be translated by several amateur translators for several languages. I can send them the xml file with all the strings that need to be translated. But, is there a cleaner way to have two files uploaded, the one in English and the one to be translated, to easily identify the strings that are still missing? Basically is like having the Translation Editor of Android Studio but online.
Maybe using google docs? How do you do this?
You can use Google Docs, but that's quite an outdated way to handle this.
The major cons:
it would be cumbersome to update strings this way
no easy way to make sure the new ones have new translations, not the old ones, etc.
no good way to provide context, if needed (typically translators have questions). You can create a column with context and take any discussions into comments, but it can get messy
A few pros:
it's fast to create (although slow to keep up-to-date)
you cooperate online and have shared access
Most developers use localization platforms, which makes updating content and online cooperation much faster.
Main pros:
it's easy to identify strings that are missing
any number of translators can translate simultaneously
track work that is done by each of translators
you can add a review/proofreading step to the process to ensure the quality of translations
leverage Machine Translations and then just have translators review them (saves lots of time)
update content, as most platforms support agile workflow
you can see who's the top translator (give some rewards, invite to other projects, etc.)
integrations (with your Git tool, Android Studio, etc), so you can automate content updates, no manual copy-pasting
Cons:
some of them are paid (still, if you're open source, you can expect a free plan)
Regarding the tools, I can suggest looking at Crowdin or Poedit.
There are many alternatives you can research, some are listed on Wikipedia.
At my work we had to translate english into Norwegian, we've done that by working with an python script that generated an ui from an csv file, after that the file could be exported in several formates as well. But your question indicates that you would like to deploy only on android, so this might be an overkill.
a simple python xml filter would fit your aproach and you could work as well with git as long as the lines stays in the same order.
if you need an quick example please comment, and ill edit this answer as soon as i get time.
At one point I have also had the same question. I need the translation for my vernacular app, also I had the requirement to maintain such that I could easily compare the translation. Here I could suggest a few things that worked out for me.
First, take the string XML file and convert it in an Excel sheet, You may generate multiple excel sheet and having a copy, paste and merge all the translations into a single sheet.
Going forward it will be easy for you to maintain all the translation. Just share a single sheet which has a string key and multiple language column. So you could easily have a look at all language translations.
In the long run, it will be helpful to you.
Few links for the conversion of XML to excel -
Convert string XML to Excel sheet
Using the below online tool works for me. Free and Opensource easy and best.
https://asrt.gluege.boerde.de/
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 would like to know why we use XML for the creating user interface layouts in Android. I know that it decouples the business logic from the design but what is the significance of the XML other than that?
Also I would like to know the significance of the auto-generated R.java file in this. All I know that it is generated according to the changes in the resources and that it helps us to access the widgets and resources through their IDs.
It would be great if someone could give a clear idea on these two aspects.
Unlike what everyone said about the XML being easy and efficient. Here is what I read in Hello Android by Ed Brunnette (p. 49) which made sense.
Android is optimized for mobile devices with limited memory and
horsepower, so you may find it strange that it uses XML so
pervasively. After all, XML is a verbose, human-readable format not
known for its brevity or efficiency, right?
Although you see XML when writing your program, the Eclipse plug-in
invokes the Android resource compiler, aapt, to preprocess the XML
into a compressed binary format.**It is this format, not the original
XML text, that is stored on the device.
This was the kind of answer that i was looking for.(sorry if my question meant otherwise).
The reason that XML was chosen is mainly because of its familiarity and the number of IDE tools that natively support it. The developers could have chosen JSON for example and still compiled that to binary.The auto-generated R.java file is a helper for the IDE so that you can get the benefit of autocomplete when you want to access a resource.
XML is easy to parse and manipulate programmatically, it's basically a tree structure and most UI creation tools already use it. It really has nothing to do with decoupling business logic because you can define Java code in Android using a Model-View-Controller pattern just as well.
The auto-generated R.java file is a helper for the IDE so that you can get the benefit of autocomplete when you want to access a resource. It also stops you from making stupid mistakes since the compiler will complain if you try to access a resource you haven't defined. If you were using a simple properties file you wouldn't know until runtime that the 'key' you are using is missing.
Same as why is silverlight with xml the answer is simple xml give power by integration and scalability. R.java is for indexing having things organized is never bad.
Sorry my english
One possible reason is that you need not have any working java underneath in order to be able to see the visual layout of the interface you are working on. The xml ui element/page is essentially a document that you can parse and display. If this were a source file you would have to either carefully parse it or compile and run it (all of which are more complex than parsing xml)
Xml as itself is well readable both by human and machine. Also, it is scalable and simple to develop. Also, you have already mentioned the decoupling.
As for R.java - it is just the way of accessing widgets. The solution is rather good, as it is using ints instead of string to use less memory and in the same time provides well readable names for the simplicity of development.
Android Layouts are tree like structures with some enforced rules. XMLs are perfect fit for this purpose.
JSON also have tree like structure but they are data-oriented while XML is document-oriented.** :
Meaning XML is based on the idea that documents have structural and
other semantic elements that can be described without reference to
how such elements should be displayed.
The actual display of such a document may vary, depending on the
output medium and style preferences.
While JSON was designed to
represent JavaScript and their prime purpose is data exchange . They are well suited in data-oriented areas
because of light weight and simplicity & closer in syntactic form to programming data structures.
I've developped an application using XML Eclipse tool too build my UI.
Now, i'd like to use a tool like Axure to create a "nicer" interface.
My problem is : is there an easy way to switch from XML to HTML (because Axure is producting HTML file from Wireframe design) ?
And if not, how to "plug" HTML file to the existing application (which is using R.layout.xxx or R.id.xxx to access displayed elements).
I'm quite new in Android by the way...
thanks !
You can't really do what you describe. The way Android layout is specified in XML cannot be compared at all to HTML for websites. Besides, Axure is a mock-up tool. It creates interactive mockups and prototypes - not final solutions for anything.
If you really want to use Axure, perhaps you would want to go for web apps with something like PhoneGap - they are written in HTML and JavaScript, but have less possibilities.
I am working on a project in Android now that involves parsing XML from a local file.
I have done XML work extensiely in flex and have become used to the power and flexibility of E4X and it's capabilities. I wonder now if I can do something similar in android or will I be forced to parse the XML manually?
Thanks
Quoting #Andreas_D:
E4X is a language extension, XML is treated like a primitive. E4X is not just for parsing XML, it's using XML as real types.
This can't be simulated or done with a Java 'framework', it would require a language extension for Java.
And, since Android does not have JAXB, you don't have that, either.
You have your choice of DOM, SAX, and the XmlPullParser, plus any third-party Java libraries you can find that have been ported to Android and fit whatever size constraints you may have.
check this out-
Working with XML on Android