Android language settings

Source: Internet
Author: User

Http://zhmeup.iteye.com/blog/1075642

The android source version corresponding to the Code involved in this article is 2.3.3, codenamed gingerbread.

In the past two days, we have investigated the language settings in the setting program of the Android system. The specific locations are as follows:

1) set the Display language: settings-> Language & keyboard-> Select language

2) set the input language: settings-> Language & keyboard-> Android keyboard [settings]-> input languages ages

In the Settings Project, the Java code and preference layout corresponding to the settings-> Language & keyboard interface are as follows:

<Android_root>/packages/apps/settings/src/COM/Android/settings/languagesettings. Java

<Android_root>/packages/apps/settings/RES/XML/language_settings.xml

1. settings-> Language & keyboard-> Select language

In <android_root>/packages/apps/settings/RES/XML/language_settings.xml, the preference layout of this module is:

View plaincopy to clipboardprint?

1. <preferencescreen
2. Android: Key = "phone_language"
3. Android: Title = "@ string/phone_language">
4. <intent Android: Action = "android. Intent. Action. Main"
5. Android: targetpackage = "com. Android. Settings"
6. Android: targetclass = "com. Android. settings. localepicker"/>
7. </preferencescreen>

<Preferencescreen Android: Key = "phone_language" Android: Title = "@ string/phone_language"> <intent Android: Action = "android. intent. action. main "Android: targetpackage =" com. android. settings "Android: targetclass =" com. android. settings. localepicker "/> </preferencescreen>

Therefore, when you click "Settings-> Language & keyboard-> Select language", the activity of "com. Android. settings. localepicker" is started. The source code is:

<Android_root>/packages/apps/settings/src/COM/Android/settings/localepicker. Java

Localepicker activity inherits from listactivity. In its oncreate () callback, the following statement is called:

String [] locales = getassets (). getlocales ();

Localepicker activity processes the obtained locale string, creates an arrayadapter <loc> adapter, and binds it to the listactivity listview. When you click the item on the listview, set the selected Locale information to the Android system.

View plaincopy to clipboardprint?

1. @ override
2. Protected void onlistitemclick (listview L, view V, int position, long ID ){
3. Try {
4. iactivitymanager AM = activitymanagernative. getdefault ();
5. Configuration Config = aM. getconfiguration ();
6. Loc loc = mlocales [position];
7. config. locale = LOC. locale;
8. // indicate this isn' t some passing default-the user wants this remembered
9. config. usersetlocale = true;
10. Am. updateconfiguration (config );
11. // trigger the dirty bit for the settings provider.
12. backupmanager. datachanged ("com. Android. providers. Settings ");
13.} catch (RemoteException e ){
14. // intentionally left blank
15 .}
16. Finish ();
17 .}

@ Override protected void onlistitemclick (listview L, view V, int position, long ID) {try {iactivitymanager AM = activitymanagernative. getdefault (); configuration Config = aM. getconfiguration (); loc = mlocales [position]; config. locale = loc. locale ;//
Indicate this isn' t some passing default-the user wants this remembered config. usersetlocale = true; AM. updateconfiguration (config); // trigger the dirty bit for the settings provider. backupmanager. datachanged ("com. android. providers. settings ");} catch
(RemoteException e) {// intentionally Left Blank} finish ();}

2. settings-> Language & keyboard-> Android keyboard [settings]-> input versions

In <android_root>/packages/apps/settings/RES/XML/language_settings.xml, the layout content related to the input method cannot be found. However, you can go to <android_root>/packages/apps/settings/src/COM/Android/settings/languagesettings. java finds an oncreateimm () function, which is called in the oncreate () callback. It is used through the getinputmethodlist () of the inputmethodmanager class ()
API to obtain the list of input methods installed in the current system, dynamically generate a preference layout one by one, and append it to the setting interface.

In fact, gingerbread has three Default Input Methods: English, Chinese, and Japanese. The corresponding project code path is:

<Android_root>/packages/inputmethods/latinime/

<Android_root>/packages/inputmethods/openwnn/

<Android_root>/packages/inputmethods/pinyinime/

Log shows that when you click the menu item Android keyboard [settings], an activity: COM. android. inputmethod. latin/COM. android. inputmethod. latin. latinimesettings. Therefore, we can conclude that <android_root>/packages/inputmethods/latinime/is the source code project of the android keyboard [settings] input method we are looking.

You can find the activity and layout in <android_root>/packages/inputmethods/latinime/Java/androidmanifest. xml:

<Android_root>/packages/inputmethods/latinime/Java/src/COM/Android/inputmethod/Latin/latinimesettings. Java

<Android_root>/packages/inputmethods/latinime/Java/RES/XML/prefs. xml

Finally, we can determine that the code corresponding to settings-> Language & keyboard-> Android keyboard [settings]-> input ages is:

<Android_root>/packages/inputmethods/latinime/Java/src/.../Latin/input1_ageselection. Java

Inputequalageselection is inherited from preferenceactivity. It has a getuniquelocales () function. In this function, it is like <android_root>/packages/apps/settings/src/COM/Android/settings/localepicker. like java, the following statement is called:

String [] locales = getassets (). getlocales ();

Then, inputshortageselection activity processes the obtained locale string, loops through the final locale list, and dynamically generates checkboxpreference for each language one by one to load it to the inputshortageselection screen. When you select a language and exit the inputmediaageselection activity, these selected languages will be saved to sharedpreferences.

At this point, we can see that the above two practices use the getassets () method of activity to obtain the assetmanager instance, and then call the getlocales () function of assetmanager to obtain the language supported by the system. After some filtering methods, they are displayed on the UI.

The code used by phone to set the language is in (setsystemlocale method)
/Work/updatecode/androidx86-froyo/frameworks/base/telephony/Java/COM/Android/Internal/telephony/phonebase. Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.