android: how to make #String/name work in res folder? - android

Android
I got the following code in an xml file in the res folder.
<?xml version="1.0" encoding="utf-8"?>
<designs>
<design name="2Parts">
<module id="0" posY="0" posX="0" height="0.5" width="1" capHeight="0.2"></module>
<module id="1" posY="0.5" posX="0" height="0.66" width="1" capHeight="0.2"></module>
</design>
Instead of using height="0.5" I'd like to have a variable from the Strings like height="#string/height_one" . But somehow I can't use the #string function.
Is that possible?
Is there an easy way to calculate with the strings in other files?
For an example :
height="#string/height_one * 0.5" ?
Looking forward to your answers

Related

Tasker: edit settings for android app in xml file

I use tasker to edit setting from google maps. I have a xml file with following content.
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
...
<set name="nontransit_route_options$105347668285068041666">
<string>AVOID_TOLLS</string>
<string>AVOID_HIGHWAYS</string>
<string>AVOID_FERRIES</string>
</set>
...
</map>
Settings in UI
Each togglebutton add by activating a line with
<string>AVOID_*</string>.
And remove the line by deactivating.
So now I want to add or remove a line with tasker. For example %avoid_highway is true so add line in set-tag.
Step 1
First I need to read the set-tag like (perl regex):
/<set.*name="nontransit_route_options.*(<\/set>|\/>)/gsu
I ignore the number cause I don't know what it means.
Step 2
I build my own set-tag and add the tag lines. Then replace the set-tag and save it.
One problem more: If all togglebuttons are deactivated the tag is self closed:
<set name="nontransit_route_options$105347668285068041666" />

Freemarker placeholder in html file in Android IDE Template Format

I'm working with android studio to develop Android app. I'm working on the creation of a template to use in my applications. I have read the Android IDE Template Format specification and so i start my personal template starting from Dummy template.
I have a .ftl file with the following line of code:
<applicationGestureListenerClazz>${projectPackageName}.listeners.${projectShortName}GestureListener</applicationGestureListenerClazz>
When i execute the template i obtain the following line:
<applicationGestureListenerClazz>org.abubu.dummy.listeners.DummyGestureListener
</applicationGestureListenerClazz>
The variables are correctly defined (in other file they work fine). I don't known why.. it add a CRLF after this line.
Anybody has analogue problem?
UPDATE
I discover that the problem is linked to extension of output file. For example. I have a file **license_key_strings.txt.ftl* that contains:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di ${projectPackageName}.key-->
<string name="publicKey">${licenseKey}</string>
</resources>
<!-- fine -->
If i use it to create a xml file
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.xml"/>
I obtain this file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">
MIIBIjANBgkqhkiG9w0BAQ
</string>
</resources>
But the output filename ends with .txt
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.txt"/>
The final output become:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">MIIBIjANBgkqhkiG9w0BAQ</string>
</resources>
<!-- fine -->
I'm working with Android Studio 1.4

Appcelerator Titanium Internationalization not working right

Here's one that's driving me crazy:
I have recently started looking into Appcelerator Titanium. I have built a few small apps both with a normal project and using Alloy so I understand the basics at least.
One thing I just cannot get working is the i18n folder/files.
Here is what ive done:
- Create a "Default Project"
- add folder to root directory "i18n"
- add "en" and "es" folder to "i18n"
- add "strings.xml" to both those new folders.
- added:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome TEST</string>
</resources>
to both the strings.xml, except in the es strings I put "ES Welcome TEST".
- In Resources -> app.js I changed "I am Window 1" to L('welcome_message')
- Ran the application
Both the normal and alloy versions just show a blank screen. I would like to get my alloy app working the most but from what I understand the localization code should work the same in both apps. In alloy I may just have to put it in the style.
Any pointers would be great! I have looked at other post claiming its not working but all of them were either syntax errors or just set it up wrong. I have copied their code and have the exact same issue with it not working so I have a feeling im missing a newbie step.
-- Here are some screenshots, I just created a brand new regular(not alloy) project, added the code above and try to use L('welcome_message') to no luck. I tried installing everything on a new PC to make sure I wasn't messing anything up on my main computer.
Heres the answer:
https://wiki.appcelerator.org/display/guides/Internationalization
Ends up by default your manifest file is not setup by default to allow localization UNLESS you choose a tabbed project.
Kinda silly if you ask me.
For the topic poster:
My new string.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Don't Help Austin</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
Screenshot of my non-Alloy experiment:
For those looking to answer the question in the topic, this is a possible answer below.
My i18n folder is on the same hierarchy level as app and plugins, so mine isn't inside the app folder like the rest of the Alloy resources.
index.xml
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick"></Label>
</Window>
</Alloy>
index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: L("welcome_message")
}
strings.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome to Kitchen Sink for Titanium</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
When I placed the L("welcome_message") inside the index.xml, it didn't work.

How to read & update xml file in android?

It may be a basic question but I am new to xml parsing, that's why I need some help. So the question is: I just want to read a xml file from res folder in android and update the values for some tag in that file; so, howcan it be done? Please help me out. Following is the xml file and I want to update the value of the tag "event filter" which is currently having value "moneyback". I had searched many threads but still I am unable to solve the issue.
<?xml version="1.0" encoding="UTF-8"?>
<HawkAgentPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<config>
<installedappthreadtime>10</installedappthreadtime>
<runningprocessthreadtime>10</runningprocessthreadtime>
<networkconnectionsthreadtime>10</networkconnectionsthreadtime>
</config>
<policy name="DayCapturePolicy" type="capture">
<starttime>9:00:00 AM</starttime>
<endtime>9:00:00 PM</endtime>
<event name="NEW_APP_INSTALLED">
<eventFilter selectedAppName="Moneyback"/>
<eventParam>selectedAppName</eventParam>
<eventParam>selectedAppVersion</eventParam>
<eventParam>appPackageName</eventParam>
<eventParam>appDirPath</eventParam>
</event>
<event name="NEW_PROCESS_STARTED">
<eventFilter runningAppName="Moneyback" />
<eventParam>runningAppName</eventParam>
<eventParam>runningAppProcessId</eventParam>
<eventParam>runningProcessName</eventParam>
</event>
<event name="INBOUND_CONNECTION">
<eventFilter netAppName="Moneyback"/>
<eventParam>netProtocol</eventParam>
<eventParam>netRemoteIP</eventParam>
<eventParam>netRemotePort</eventParam>
<eventParam>netStatus</eventParam>
<eventParam>netUID</eventParam>
<eventParam>netAppName</eventParam>
</event>
<event name="OUTBOUND_CONNECTION">
<eventFilter netAppName="Moneyback"/>
<eventParam>netProtocol</eventParam>
<eventParam>netRemoteIP</eventParam>
<eventParam>netRemotePort</eventParam>
<eventParam>netStatus</eventParam>
<eventParam>netUID</eventParam>
<eventParam>netAppName</eventParam>
</event>
</policy>
</HawkAgentPolicy>

res folder inside bin has gone empty,causing errors.How to fix?Something to do with options menu?

The res folder inside of bin is supposed to contain .dex,.apk and .ap_ i think.Mines gone empty somehow causing errors like not being able to access the layout resources.I have tried clean and build but it doesent seem to work.Just seem to create an empty res folder.So any idea how to fix this?
Thanks.
Ok my problem is with an xml file i'm creating inside of res/menu inorder to create an options menu:
options.xml:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/setmenu"
android:title="#string/settings"
android:icon="#android:drawable/ic_menu_preferences"></item>
<item
android:id="#+id/helpmenu"
android:title="#string/help"
androidLicon="#android:drawable/ic_menu_help"></item>
</menu>
Heres the error i am getting:
Description Resource Path Location Type
Unparsed aapt error(s)! Check the console for output. TriviaQuiz line 1 Android ADT Problem
Console Messages:
[2011-11-19 16:47:24 - TriviaQuiz] W/ResourceType( 4672): Bad XML block: header size 116 or total size 7602372 is larger than data size 0
[2011-11-19 16:47:24 - TriviaQuiz] H:\workspace\TriviaQuiz\res\menu\options.xml:5: error: Error parsing XML: unbound prefix
Any idea what it is.
I find that an error in one of my resources (usually a layout) causes this. Missing quotes or /> in particular are a good starting point - that's my personal blind spot and eclipse punishes it mercilessly!
As alextsc says, check everything you edited recently.

Categories

Resources