Link one resource file to another instead of duplicating - android

According to this thread, in order to make Hebrew available on all devices, I need to maintain two similar files of each resource type, one in values-iw and another in values-he. Having a ready-to-use strings.xml, I was wondering if there's a way to "link" the files in one of these folders to the files in the second folder instead of making an alias for each string (exampled here).
Thanks!

Related

Can I allow drawable files to contain capital letters? if not...?

I am currently developing an Android version of a pre-existing iOS application.
I have the original resource folder with all the drawable files (200+ .png files).
The person who wrote the iOS named every single .png file like this: "examplePngName.png"
is there anyway I can allow the res drawable folders to allow capitals or a better way than manually renaming over 200 files..?
Search the web and download a Bulk Rename Utility for your OS.
For example BulkRenameUtility (Note: this one purports to handle case changes as you require, but I haven't tried it myself. It was just the first one on the list in a quick google search!).

Dynamically Determine Android Resources

I have a number of different string resource files that are built with my Android application using our build system. These string files can be added incrementally at any time and our build system will pick them up from their separate directory. I want to enumerate all of the string files or be able to obtain a single string in them without having to know the name or id of the string resource in them. I also don't want the person adding these to have to edit a main string file in my package that includes an array listing the different files. Is there any way to accomplish this?
Example:
SoccerStrings.xml
id="SoccerDetails" value="soccer"
CricketStrings.xml
id="CricketDetails" value="cricket"
Without knowing these files exist how can I provide a list view with two items: Cricket and Soccer in addition to automatically supporting any additional files that might appear.
I was thinking the best possible approach would be to have the build system pull the individual files under assets folder and then use the getAssets().list("") functionality along with the XMLResourceParser class to access the string values. Would this work and allow me to have id conflicts (ex: id="name")? Is there an easier way?
I would look at aapt. I know you can get the resources out of the .apk with the following command --
aapt d --values resources app.apk
It might be possible to use aapt to get the resources earlier in the build process. It has the following option which looks prosmising, but aapt documentation is a bit thin.
--output-text-symbols
Generates a text file containing the resource symbols of the R class in the
specified folder.
As another alternative, you could modify your build process and parse the string class directly out of the gen/<package>/R.java file after it has been generated. You could store that in a loadable file, or generate your own source file to add to the build.
I am not going to tell you how to do it. I am answering the question to advise against it.
What you are planning to do does not go well with the resource files. These files are basically code. What you want to do is about data. You should have your data in assets directory. Then these files won't be precompiled in your build like the resource file. You can process these files any way you want. There will be then quite a bit coding involved to convert all that into business logic, but that would be price to pay to write good, maintainable code.
Playing with resource files the way you are suggesting is akin to Java reflection. You want to use it only because you have functionality that is about such feature, not because it's the easiest way out.
Having said that, you might be exactly in a situation where you have to handle the resource files the way you stated. In that case, please accept my apologies.

Is it possible to make use of the Android resource resolver on a self-created folder in the file system?

I'd like the ability to "overwrite" the Android resources packaged within my apk by having the app periodically download a zipped file containing overrides that follow the same naming convention as the source does. For example, the zip might consist of the following paths:
res/values/strings.json
res/values-land/strings.json
My code would parse those files and produce a Map> that would map the string resource id to a folder->value pair (or something along these lines). At this point I'm really only concerned with strings and images (maybe arrays), but not layouts, etc.
To the point: Is there any method available, that, given a list of folder names, would tell me which one the Android resolver would choose based on current state? I'm assuming this is difficult because the compiler breaks everything down to ids, but figured it was worth a shot. Any ideas?
Is there any method available, that, given a list of folder names, would tell me which one the Android resolver would choose based on current state?
No. You are welcome to roll this yourself based on Configuration, DeviceMetrics, and kin. You will also need to create your own parsers for your own files, as Android's resource system only works with resources, not arbitrary files retrieved from arbitrary locations.
The expectation in Android is that if you want to update resources, you update the app, probably because there were also code changes as well. Admittedly, this approach has its limitations.

organizing android apps in eclipse

I have an app on the iPhone and need to port it to android. For this I would like to group screen related files like classes and xml per screen in one "screen group" per screen somehow, ideally also strings and other value files
if I use folders I can only group res files separately and src files separately.
what would be the best way?
Thanks very much!
EDIT:
If that should not be possible, how to best then solve this issue? Do you create a subfolder in the src and another in the res for each screen?
The way you group files for the iphone is not possible for an android project. Android has pre determined folders which hold specific files, if you break this structure, your building process will fail. Its not ideal but that just how it it.
When it comes to source java files, they follow the concept of packages which are basically folders. The 'src' folder is the part where you can create sub folders as you desire. If you are adamant about keeping the files related to a screen in one place, you should create the layouts with java code and not use layout xml files.
But using xml layout files make development much easier and faster. Consider that as the presentation and java files as the logic+data. So group java files as you want and leave xml files in the layout folder with easy to identify names.
android uses certain directory layout for project structures (i.e. convention over configuration). Basically you will want to put your XML layout files in res/layout directory. Please read http://developer.android.com/guide/developing/projects/index.html#ApplicationProjects for further information.
Unfortunately, there's no easy way to do this in Eclipse. You can't create custom directories in your Android app's /res directory, you can only use permitted dir-names. E.g. you can't have a /res/layout-myscreen1 and /res/layout-myscreen2. You also must put your resources in /res, and your code files in packages, so they're at separate places in your project.
You can use Working Sets to group related files together however, but they're quite painful to use IMHO. Check the eclipse docs and tutorials out on them.

Android raw resource

I have some sql queries that I would like to put in a .txt file and import to my application on start up. 2 questions:
1) Where is the best place to put these files?
2) I thought maybe I can put them in /res/raw/sql/ but the files don't come up with AutoComplete. (They come up if I put them in /res/raw/). Any ideas?
You cannot make sub folders of the resources folder Android provides per default. The same is true for the various layout folders etc. So you have to put them directly in /res/raw. But anyway, I think there it is the best place to save them.

Categories

Resources