Option to change language in an android app - java

I'm building an android app where i have a settings activity.
In this settings Activity, I have a ListPreference with 3 values, each for a language.
I would like to get the value selected by the user and then change the language of the application according to the choice of the user
How would you do this guys ?
Thanks for reading and help !

The link in the comments above is the complete answer, but just to get you started, to support whatever language the user's device is set to, you need to extract all of the text in your app that will be visible on screen out to a 'strings.xml' file. Then translate all of the strings in that file into a separate 'strings.xml' file for each language you wish to support. This file lives in the res/values folder, and if you wanted to do a Spanish translation, you would create a res/values-es folder, and add a 'strings.xml' file there, with entries that have the same 'name' as the English translation, but with the Spanish translation as the 'value' example:
res/values/strings.xml
<string name="change_voter">Change Voter</string>
res/values-es/strings.xml
<string name="change_voter">Cambiar de Votantes</string>
//Then you get the value into your label like so:
tvVoter.setText(getResources().getText(R.string.change_voter));
You will also need to consider any graphics (bitmaps, backgrounds, buttons) and if they have words written in the default language, there will need to be copies of those translated into the other language and in another localized folder.

Related

How To Use ID3 Tags (Audio File Details and Information) for a Java Clip

EDIT
Special thanks to Manoj Khanna who has alerted me that the "details" I referred to in this question are actually called ID3 Tags. Part of the reason I needed the community's help was because I didn't know the name of these tags, so thank you for responding to my question! You guys are a huge help!
Original Question
I created a simple Java application (in Java 8) that plays .WAV Audio Files stored on my computer. I use the javax.sound.sampled.AudioSystem to play a javax.sound.sampled.Clip using this code:
Clip l = AudioSystem.getClip();
l.open(AudioSystem.getAudioInputStream(new File("song.wav")));
l.setFramePosition(0);
l.start();
That code works completely fine, and I am very happy with how it works. I get the name of the file to identify the songs, and it works well. However, what I am asking for help with is how to use the .WAV Audio File's song "details" and "information."
This is a bit hard to explain, so I will use include pictures and specific applications to clarify.
Other audio applications (as an example, I will use Microsoft's "Groove Music" app in Windows 10) send the "details" of the track to the speakers and the operating system.
IMAGE ONE: You can set the "details" of an audio track in the properties of a file, or set them when you create the file. This hyperlink links to a screenshot showing the "details" of the song (the title and contributing artists).
Notice that the name of the file has nothing to do with the details shown in the image linked about (even though I named them the same).
IMAGE TWO: The "details" of the track are reflected while the song is playing in most audio playing applications (in this case "Groove Music"). The details are also reflected in the volume changing menu on the top left of the screen. This hyperlink links to a screenshot showing how the "details" are reflected while the track is playing.
The same "details" would be sent to a Bluetooth audio playback device (such as a car or speaker), and possibly displayed on the device's screen (if the device has that feature).
As of now, my Clip does not take any of the information from the properties of the .WAV Audio Files and doesn't pass them along to my operating system or any of my speakers that I have tested it on. They all play the music fine, they just don't display the information as I'd like.
Is there any way for me to use these ID3 tags while playing the audio?
I'd be fine with a solution where I'd have to manually set the song name and artist, or change a setting that automatically collects the information from the properties of the file.
CLARIFICATION (EDIT 2)
I already have the ID3 tags set up in my audio file, but I want to pass these tags to the operating system and speakers when playing using the Clip. I want my Clip to play in a way that uses the information as shown in image two. I want the ID3 Tags already set up previously to be used when playing the audio file; I want the tags to be passed to the speakers and operating system while playing.
I would prefer not to use an external library, but if I must, than I can settle for using one.
Is this possible, and if so, how?
The properties that you would like to read or modify are called ID3 tags.
A quick Google search gave me this library JAudiotagger. It can also be used to read or modify ID3 tags of several other formats too.
Usage
AudioFile file = AudioFileIO.read(new File("filename.wav"));
Tag tag = file.getTag();
tag.setField(FieldKey.ARTIST,"Kings of Leon");
AudioFileIO.write(file);
More examples can be viewed here.

change the writing language to arabic when text field is clicked

The default writing language on my PC is English. What should I add to my code, so when I press on the text field in j frame, I want the writing language to convert automatically into Arabic. And when I press on another text field, I want it to return into English.
How the writting language affect your application? For example, in firefox I can change the writting language by right click on any box and change the language.
If your app needs to keep track the current language you need to save the language configuration somewhere (on a global variable or file), and perhaps make a good first guess reading it from the LANG environment variable.

Is it possible to make a macro or similar to download all images from the metropolitan museum website

I was wondering if it's possible to make a macro to download every image from the metropolitan museum image collection http://www.metmuseum.org/collection/the-collection-online
I don't really have any idea how to program macros, but just wondering if anyone would be able to help. I want to create a backup database of the important artworks they have for download. They are all free to the public.
Any help would be appreciated.
Cheers
The macro below downloads all available images from the given page. Run it in cycle with the number of steps equal to number of images on this web-site page (by default 30). (For better automation one has to use iMacros Scripting Interface (e.g. JavaScript) but in this case the code will be larger.)
SET !EXTRACT_TEST_POPUP NO
SET !TIMEOUT_STEP 1
SET !ERRORIGNORE YES
' first page to download the images (as an example)
SET pageToDnl http://www.metmuseum.org/collection/the-collection-online/search?ft=john+la+farge&noqs=true
TAB T=1
URL GOTO={{pageToDnl}}
SET !LOOP 1
SET refPos EVAL(2*({{!LOOP}}-1)+1)
TAG POS={{refPos}} TYPE=A ATTR=HREF:*?rpp=30&pg=1&ft=john+la+farge&pos=* EXTRACT=HREF
TAB OPEN
TAB T=2
URL GOTO={{!EXTRACT}}
TAG POS=1 TYPE=IMG ATTR=HREF:http://images.metmuseum.org/CRDImages/*/web-large/*.jpg CONTENT=EVENT:SAVETARGETAS
TAB CLOSE

Android: XML Textview text Property

I had seen an Android Tutorial that allows a simple android:text just like the example bellow:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Application"
android:textColor="#ffffff" />
But in my eclipse,
it says:
[I18N] Hardcoded string "Android Application", should use #string resource
What should I do?
I need to insert a lot of Text just like,
Accounting has begun since time immemorial. Consider this truth: God said unto Noah; “and every living thing of all flesh, two of every sort shall thou bring into the ark, to keep them alive with thee; they shall be male and female. Of fowls after their kind, and of cattle after their kind, of every creeping thing of the earth after his kind, two of every sort shall come unto thee, to keep them alive. And take thou unto thee of all food that is eaten, and thou shall gather it to thee; and it shall be for food for thee, and for them.” The Bible – Genesis 6:19-20. “Of every clean beast thou shall take to thee by sevens, the male and his female: and of the beast that are not clean by two, the male and his female. Of fowls of the air by sevens, the male and the female; to keep seed alive upon the face of all earth.” The Bible – Genesis 7:2-3
Any suggestion or tell me what the better thing to do?
This is just a warning.
But by using a string resource, you can support multi-languages.
You have just to create a new string resource in the file strings.xml (res/values/strings.xml).
Then add the line :
<string name="your_name">Your text</string>
and just change :
android:text="Android Application" by android:text="#string/your_name"
Now if you want to add a new language to your application, let's say in french, you will have just to create a new folder in the res folder called values-fr and copy/paste the file strings.xml you already have and finally translate the strings you have defined (i.e <string name="your_name">Your text translated in french</string>)
You can have a look at this (problem resolved using screenshots).
You can use hardcoded strings in your layout (or in code), it is just a warning and eclipse won't fail on compilation.
But android best practice is the remove all strings and texts from your app and layout and put it in one place- so it will be much easier to translate later.
So what eclipse suggest you is to extract the "Android Application" text to strings.xml file (that should contain all your app's strings).
If it's just for the tutorial you can ignore it, or even better- just let eclipse extract the text to strings.xml using quick fix

How can i add some text (i.e. kind of "about" info) in Preferences in Android

I'd like to add a short text (2-3 sentences) to my preferences screen (which is created using xml with PreferenceScreen, etc), in order to provide some kind of short help/description for the user.
I tried using Preference, i.e. custom preference, but i cannot see more than 1 line in the title and more than 2 lines in the summary.
You can't do a lot of customization to a preference widgets.
Two options:
1) SMSpopup approach. Opening a new window with the information. Check the About preference.
Check the src code.
2) Softkeyboard approach. Using the normal preference but setting it disabled. Check the src code.

Categories