Find which resources are filtered - android

From the image above in a working android project. I would like a way to get the filters so I can compare them to something else I'm working on. For example I'd like to have an array that contains "mcc311,mnc490","mcc311,870".....,"mcc312,mnc530" etc. So I'm looking for a way to get the filters that the project actually uses.

Figured out a way to do this and it was pretty simple. In values-mcc310-mnc120 for example, i would put in a xml file defining a variable signifying what mcc and mnc identification im using.
For example, in values-mcc311-mnc870 i would have a xml file called networkcode.xml with contents of:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="network_id">MCC311/MNC870</string>
</resources>
this way i can read in that value of network_id at run time and know for certain what filter android is using.

Related

Text in android app (beginner...)

My problem is very simple: I've started an app for playing Darts. The app will have several activities ('pages').
One page will be about the rules of the game. I'll be using a scroll layout because it's quite some text. But how to get the text there?!
I assume working with strings is not the best way? Do I use the XML file to get the text on screen then or does it work via Java (Assetmanager)?
Maybe there are sample apps in which large chunks of text are used?
I know this really might seem like a trivial question but I haven't a clue where to begin.
Thanks in advance!
You should put your string in your strings.xml in your res\values folder.
You can define strings by ID which allows easier internationalization (i18n), so that you can easily adjust the strings used in your app to locale (which is done automatically using resource identifiers, and it falls back to strings.xml if it can't find a strings-hu.xml in case you have Hungarian locale set as system language).
You can also define string-array and the like in XMLs. Then all you need is create a layout XML with a ScrollView in it that has a TextView in it and then you set android:text="#string/rules" for that TextView and you're done.
It is so simple my friend.
You can simply use TextView and in "android:text" you refer to the string that you delared in strings.xml file (by its name)
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/text_name"
/>
If your text is dynamic, you can modify it in Java code!
Make a String Resource like this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string1"> your text </string>
<string name="string2"> your text </string>
</resources>
and access like this if you are in Activity.
getResources().getString(R.string.string1);
If you are a begginer you should read some tutorials after post a question...
I give you a three nice tutorials below :
Want to Learn How to Program for Android? Start Here
Android Programming Tutorial
Android Development with Android Studio or Eclipse ADT
About your question, if you don't know how to use the string.xml resource just read the string-resource guide
Hope it helps.

How to alphabetically sort code in XML file inside Intellij IDEA 13 for android?

I used eclipse for training in android but now using Intellij IDEA 13. I am used to the graphical string editor of eclipse which can alphabetically sort the string.xml file for me.
I want to do the same in intelliJ but couldn't find any solution.
This is how code look like
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ActionBar App</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>
and I want to sort it alphabetically like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">Settings</string>
<string name="app_name">ActionBar App</string>
<string name="hello_world">Hello world!</string>
</resources>
How to do this ? Please help!
The arrangement feature allows you to setup rules to arrange the order this appear in a file. Arrangement of attributes, particularly for Android files, was add via IDEA-72907. You can get a predefined arrangement style for android by going to Settings > [Project Settings] > Code Style > XML {Arrangement Tab} Click on the "Set from..." link near the top right and select Preferred Style > Android. That will populate the XML style (and arrangement) settings with a predefined style that you can tweak.
That said, I am unsure if the arrangement feature has the ability to sort by the attribute's value. I know it can sort the attributes in a particular order. If I get a chance, I'll see if I can find the syntax to sort by the attribute's value. In the meantime, you can take a look.
Also, you can try either the Lines Sorter or SortSelection third party plug-ins. A bit more basic, but one might work for you.
I found this link Rearrange Attributes in Android XML Files with IntelliJ IDEA 13
I chose the second option.
As mentioned go to the settings/Editor/Code Style/XML/Arrangement
Reordering the arrangement and changing to be reorder by name:
This won't sort the strings.xml by name, so
copy and paste into an excel worksheet and sort by A-Z
I am posting this two years after the fact, but there's another way to sort lines in IntelliJ IDEA that I'd like to mention here -- i.e. by using the IDE's Vim features.
If you want to sort a range of lines alphabetically -- say, lines 3 through 6 -- just do the following:
Open the Tools menu and make sure that 'Vim Emulator' is checked.
Type the following command in your editor:
:3,6sort
That's it -- your lines will now be sorted. All you need to do now is disable Vim if you don't use it. You can do this by Opening the Tools menu and unchecking 'Vim Emulator'.
Note that this isn't an XML sort -- it's an alphabetic line sort so spaces and so on could get in the way of a successful sort. But for simple cases like the one you mention above, this should work.
Darryl
You can't sort XML elements by its attribute value, e.g. 'name' via File → Settings → Editor → CodeStyle → XML → Arrangement. You only can sort the attribute order inside a tag or can sort the elements by its tag name.
For Android there is a plugin called AndroidXMLSorter (can only sort by attribute 'name', only in Android Projects)
If the entries are written in a single line you can select the text and use: Edit → Sort Lines (no need for a plugin)

What's "msgid" and "xliff" in strings.xml file?

Background
Sometimes I see some weird attributes on the "strings.xml" file made by Google's samples, for example, on the chips example (code available here), I can find this strings file of "res/values-en-rGB" (for English-Britain) :
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="more_string" msgid="8495478259330621990">"+<xliff:g id="COUNT">%1$s</xliff:g>"</string>
<string name="copy_email" msgid="7869435992461603532">"Copy email address"</string>
<string name="copy_number" msgid="530057841276106843">"Copy phone number"</string>
<string name="done" msgid="2356320650733788862">"Return"</string>
</resources>
I think both are used only for localized strings, as I never saw them inside "res/values" folder.
The question
What do those attributes mean?
What does the value of "xliff" mean?
When should you use them and what should you put there?
Are they even needed?
Is there any documentation about those things?
On Android Developers Localise your app page, search for xliff in the section named "Mark message parts that should not be translated".
The explanation is as follows:
Often strings contain contain text that should not be translated into
other languages. Common examples might be a piece of code, a
placeholder for a value, a special symbol, or a name. As you prepare
your strings for translation, look for and mark text that should
remain as-is, without translation, so that the translator doesn't
change it.
To mark text that should not be translated, use an
placeholder tag.
The suggestion is that text within the <xliff:g></xliff:g> tags should not be translated. These tags can also provide metadata about the non-translated text.
When you declare a placeholder tag, always add an id attribute that
explains what the placeholder is for. If your apps later replace the
placeholder value, be sure to provide an example attribute to clarify
the expected use.
For more information on the actual xliff tool, rather than how it relates to Android strings, check out the related question:
What does this mean "xmlns:xliff"? XML.

Problems with res folder and R.java

I'm doing Tutorials and I'm on section about images. It says to put them into the folder res/drawable. But I don't have that folder, I have three instead: res/drawable-hdpi, res/drawable-ldpi and res/drawable-mdpi. So whats the difference between them?
Im using this tutorial.
One of the steps is:
Create a strings.xml file in
res/values/ and edit the file to look
like
There already is strings.xml, combined with the above, telling me to use res/drawable, are these tutorials out of date?
This tutorial has code like:
R.id.spinner
R.array.planets_array
R.layout is just simple enum. Uses the main.xml in the layout folder. But where are R.id and R.array to come from. Because it is coming up in eclipse saying it doesn't know what they are. R.java gets updated automatically, so can someone tell me from reading that tutorial where id gets added to R? It says that
The R.array.planets_array ID
references the string-array defined
above
Only it doesn't work. I doubt it makes a difference that i didn't make strings.xml since it's the same filename in the same location. But since R.java is meant to be updated automatically I don't know how to fix this.
Those are for the different screen resolutions for the range of devices that are out there. Read about supporting multiple screens on the Android dev site.
Just so you know where the R stuff comes from.
The R.java file is a generated file which contains some kind of pointers to a resource in your application. It is a simple integer actually which uniquely identifies the resource in the internal resource management system of Android.
R.string identifiers are generated from resources XML files like this one for example.
<resources>
<string name="test">This is a test string.</string>
</resources>
R.array identifiers from string array XML files.
<resources>
<string-array name="days_of_week">
<item>Monday</item>
<item>Tuesday</item>
<item>Wednesday</item>
<item>Thursday</item>
<item>Friday</item>
<item>Saturday</item>
<item>Sunday</item>
</string-array>
</resources>
You can access that array using its identifier R.id.days_of_week now.
R.id identifiers are a bit special.
They are generated in two ways. The first one is when you define a View in your XML layout file using the #+id/... syntax. Note the + sign.
The other way is to define them in resource XML files like strings for example.
<resources>
<item type="id" name="first" />
<item type="id" name="second" />
</resources>
You'd then just use them in a layout XML file like this #id/first. Note that there is no + sign anymore as you reference it, before you were declaring it.
In code you then use it like this, R.id.first.
There are a lot of other resources. I'd like to point you to the Application Resources article and also make sure to checkout the Resource Types sub-article.
If you don't have the folder, just create it. It is basically the fallback for the case that you don't have a resource in a more specific folder like res/drawable-hdpi
The *-xx folders allow you to provide more specific drawables (images) for various screen resolutions.
The same principle applies to values/ and values-xx/ where xx is a country code ; the xx versions allow you to have translations for UI messages.

Eclipse + Android not recognizing my (dimension) values

I am teaching myself Android using Eclipse, the Android plug-in, and Sams "Teach Yourself Android Development" book. I have this weird little problem. I've been able to create xml files in the res/values directory that hold strings and color values (colors.xml and strings.xml). I have been able to reference these values in the properties of my Android screens (the xml in res/layout), for example setting the "Text" and "Text color" properties with references like "#string/topTitle" and "#color/titleColor," where topTitle and titleColor are defined in the xml files.
BUT: when I create a file called "dimens.xml" and have font sizes in it, Eclipse correctly puts this file in res/values, but when I try to reference these values, e.g. "#dimension/titleFont" I get an error "No resource found that matches the given name." I've tried lots of different names, I've tried "#dimens" instead of the type, still nothing. If I go into the layout xml file and set it explicitly to a font size, e.g. 22pt, it works.
So Eclipse recognized my "dimens.xml" file when I made it well enough to put it in res/values, and lets me edit it, and shows it full of (dimension) values. It just doesn't recognize my referring to it in other xml files.
The book I'm using doesn't actually show a dimension example so I must be doing something wrong. I checked the Android docs but couldn't see any problem.
Any help appreciated. Thanks.
The correct way to refer to a dimension variable (stored in your dimens.xml (don't think the name here really matters though, it's what's inside that does)) from another xml file is like this:
"#dimen/nameOfVariable"
Notice that it is neither dimension, dimensions or dimens, but dimen!
If you look inside your xml file where you have your values, this will make sense as dimen is the name of the xml elements storing dimension values:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<dimen name="someDimension">5dp</dimen>
<dimen name="anotherDimension">10dp</dimen>
</resources>

Categories

Resources