upload android base code part7
This commit is contained in:
parent
4e516ec6ed
commit
841ae54672
25229 changed files with 1709508 additions and 0 deletions
11
android/development/apps/CustomLocale/Android.mk
Normal file
11
android/development/apps/CustomLocale/Android.mk
Normal file
|
@ -0,0 +1,11 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_PACKAGE_NAME := CustomLocale
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
include $(BUILD_PACKAGE)
|
52
android/development/apps/CustomLocale/AndroidManifest.xml
Normal file
52
android/development/apps/CustomLocale/AndroidManifest.xml
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"
|
||||
package="com.android.customlocale2"
|
||||
>
|
||||
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" >
|
||||
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name="CustomLocaleActivity" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
android:name="NewLocaleDialog" />
|
||||
|
||||
<receiver android:name="CustomLocaleReceiver" >
|
||||
<intent-filter>
|
||||
<action android:name="com.android.intent.action.SET_LOCALE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
190
android/development/apps/CustomLocale/NOTICE
Normal file
190
android/development/apps/CustomLocale/NOTICE
Normal file
|
@ -0,0 +1,190 @@
|
|||
|
||||
Copyright (c) 2005-2008, The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
BIN
android/development/apps/CustomLocale/res/drawable-hdpi/icon.png
Executable file
BIN
android/development/apps/CustomLocale/res/drawable-hdpi/icon.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 5 KiB |
BIN
android/development/apps/CustomLocale/res/drawable-mdpi/icon.png
Normal file
BIN
android/development/apps/CustomLocale/res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
102
android/development/apps/CustomLocale/res/layout/main.xml
Normal file
102
android/development/apps/CustomLocale/res/layout/main.xml
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/header_current_locale"
|
||||
android:textAppearance="@style/TextAppearance.header"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="@color/header_background"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/current_locale"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:padding="5dip"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/header_locale_list"
|
||||
android:textAppearance="@style/TextAppearance.header"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="@color/header_background"
|
||||
/>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
>
|
||||
<ListView
|
||||
android:id="@id/android:list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fastScrollEnabled="true"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:padding="8dip"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@id/android:empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/no_data_label"
|
||||
android:gravity="center"
|
||||
/>
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
>
|
||||
<Button
|
||||
android:id="@+id/select_locale_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.9"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/select_locale_button"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/add_new_locale_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/add_new_locale_button"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/remove_locale_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/remove_locale_button"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="8dip"
|
||||
android:paddingRight="8dip">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_locale_label" />
|
||||
<EditText
|
||||
android:id="@+id/value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/locale_default" android:inputType="text"/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:id="@+id/add"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/add_button" android:layout_gravity="center_vertical"/>
|
||||
<Button
|
||||
android:id="@+id/add_and_select"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/add_select_button" android:layout_gravity="center_vertical"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<string name="app_name">Locales Personalisées</string>
|
||||
|
||||
<!-- Top labels in CustomLocaleActivity -->
|
||||
|
||||
<string name="header_current_locale">Locale courrante</string>
|
||||
<string name="header_locale_list">Liste des locales</string>
|
||||
<string name="no_data_label">Aucune locale</string>
|
||||
|
||||
<!-- Buttons in CustomLocaleActivity -->
|
||||
|
||||
<string name="select_locale_button">Choisir</string>
|
||||
<string name="select_locale_1s_button">Choisir \'%1$s\'</string>
|
||||
<string name="add_new_locale_button">Ajouter\u2026</string>
|
||||
<string name="remove_locale_button">Retirer\u2026</string>
|
||||
|
||||
<!-- Toast status in CustomLocaleActivity -->
|
||||
|
||||
<string name="removed_custom_locale_1s">Locale supprimée: %1$s</string>
|
||||
<string name="select_locale_1s">Locale choisie: %1$s</string>
|
||||
<string name="added_custom_locale_1s">Locale ajoutée: %1$s</string>
|
||||
|
||||
<!-- NewLocaleDialog -->
|
||||
|
||||
<string name="new_locale_label">Code de la nouvelle locale:</string>
|
||||
<string name="add_button">Ajouter</string>
|
||||
<string name="add_select_button">Ajouter et choisir</string>
|
||||
|
||||
<string name="confirm_remove_locale_1s">Voulez-vous supprimer la locale personalisée \'%1$s\' ?</string>
|
||||
<string name="confirm_remove_locale_yes">Oui</string>
|
||||
<string name="confirm_remove_locale_no">Non</string>
|
||||
|
||||
</resources>
|
18
android/development/apps/CustomLocale/res/values/colors.xml
Normal file
18
android/development/apps/CustomLocale/res/values/colors.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<color name="header_background">#888</color>
|
||||
</resources>
|
51
android/development/apps/CustomLocale/res/values/strings.xml
Normal file
51
android/development/apps/CustomLocale/res/values/strings.xml
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<string name="app_name">Custom Locale</string>
|
||||
|
||||
<!-- Top labels in CustomLocaleActivity -->
|
||||
|
||||
<string name="header_current_locale">Current Locale</string>
|
||||
<string name="header_locale_list">Locale List</string>
|
||||
<string name="no_data_label">No data</string>
|
||||
|
||||
<!-- Buttons in CustomLocaleActivity -->
|
||||
|
||||
<string name="select_locale_button">Select</string>
|
||||
<string name="select_locale_1s_button">Select \'%1$s\'</string>
|
||||
<string name="add_new_locale_button">Add New\u2026</string>
|
||||
<string name="remove_locale_button">Remove\u2026</string>
|
||||
|
||||
<!-- Toast status in CustomLocaleActivity -->
|
||||
|
||||
<string name="removed_custom_locale_1s">Removed custom locale: %1$s</string>
|
||||
<string name="select_locale_1s">Select locale: %1$s</string>
|
||||
<string name="added_custom_locale_1s">Added custom locale: %1$s</string>
|
||||
|
||||
<!-- NewLocaleDialog -->
|
||||
|
||||
<string name="new_locale_label">New locale code:</string>
|
||||
<string name="add_button">Add</string>
|
||||
<string name="add_select_button">Add and Select</string>
|
||||
|
||||
<string name="confirm_remove_locale_1s">Do you want to remove the custom locale \'%1$s\'?</string>
|
||||
<string name="confirm_remove_locale_yes">Yes</string>
|
||||
<string name="confirm_remove_locale_no">No</string>
|
||||
|
||||
<!-- Locale hint in textfield. Not translated -->
|
||||
<string name="locale_default">ex_EX</string>
|
||||
|
||||
</resources>
|
25
android/development/apps/CustomLocale/res/values/styles.xml
Normal file
25
android/development/apps/CustomLocale/res/values/styles.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<style name="TextAppearance"
|
||||
parent="android:TextAppearance" />
|
||||
|
||||
<style name="TextAppearance.header">
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.customlocale2;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.IActivityManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Helper class to change the system locale.
|
||||
*/
|
||||
public final class ChangeLocale {
|
||||
|
||||
private static final String TAG = ChangeLocale.class.getSimpleName();
|
||||
private static final boolean DEBUG = true;
|
||||
|
||||
/**
|
||||
* Sets the system locale to the new one specified.
|
||||
*
|
||||
* @param locale A locale name in the form "ab_AB". Must not be null or empty.
|
||||
* @return True if the locale was succesfully changed.
|
||||
*/
|
||||
public static boolean changeSystemLocale(String locale) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Change locale to: " + locale);
|
||||
}
|
||||
|
||||
try {
|
||||
IActivityManager am = ActivityManager.getService();
|
||||
Configuration config = am.getConfiguration();
|
||||
|
||||
Locale loc = null;
|
||||
|
||||
String[] langCountry = locale.split("_");
|
||||
if (langCountry.length == 2) {
|
||||
loc = new Locale(langCountry[0], langCountry[1]);
|
||||
} else {
|
||||
loc = new Locale(locale);
|
||||
}
|
||||
|
||||
config.locale = loc;
|
||||
|
||||
// indicate this isn't some passing default - the user wants this
|
||||
// remembered
|
||||
config.userSetLocale = true;
|
||||
|
||||
am.updateConfiguration(config);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (RemoteException e) {
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "Change locale failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,454 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.customlocale2;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.ListActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.View;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
|
||||
/**
|
||||
* Displays the list of system locales as well as maintain a custom list of user
|
||||
* locales. The user can select a locale and apply it or it can create or remove
|
||||
* a custom locale.
|
||||
*/
|
||||
public class CustomLocaleActivity extends ListActivity {
|
||||
|
||||
private static final String TAG = "CustomLocale";
|
||||
private static final boolean DEBUG = true;
|
||||
|
||||
private static final int DLG_REMOVE_ID = 0;
|
||||
|
||||
private static final String CUSTOM_LOCALES_SEP = " ";
|
||||
private static final String CUSTOM_LOCALES = "custom_locales";
|
||||
|
||||
/** Request code returned when the NewLocaleDialog activity finishes. */
|
||||
private static final int UPDATE_LIST = 42;
|
||||
/** Menu item id for applying a locale */
|
||||
private static final int MENU_APPLY = 43;
|
||||
/** Menu item id for removing a custom locale */
|
||||
private static final int MENU_REMOVE = 44;
|
||||
|
||||
/** List view displaying system and custom locales. */
|
||||
private ListView mListView;
|
||||
/** Textview used to display current locale */
|
||||
private TextView mCurrentLocaleTextView;
|
||||
/** Private shared preferences of this activity. */
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
private Button mRemoveLocaleButton;
|
||||
private Button mSelectLocaleButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
mPrefs = getPreferences(MODE_PRIVATE);
|
||||
|
||||
Button addLocaleButton = (Button) findViewById(R.id.add_new_locale_button);
|
||||
mRemoveLocaleButton = (Button) findViewById(R.id.remove_locale_button);
|
||||
mSelectLocaleButton = (Button) findViewById(R.id.select_locale_button);
|
||||
|
||||
addLocaleButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
onAddNewLocale();
|
||||
}
|
||||
});
|
||||
|
||||
mRemoveLocaleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog(DLG_REMOVE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
mSelectLocaleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onSelectLocale();
|
||||
}
|
||||
});
|
||||
|
||||
mListView = (ListView) findViewById(android.R.id.list);
|
||||
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
mListView.setItemsCanFocus(false);
|
||||
mListView.setFocusable(true);
|
||||
mListView.setFocusableInTouchMode(true);
|
||||
mListView.requestFocus();
|
||||
setupLocaleList();
|
||||
|
||||
mCurrentLocaleTextView = (TextView) findViewById(R.id.current_locale);
|
||||
displayCurrentLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
updateLocaleButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == UPDATE_LIST && resultCode == RESULT_OK && data != null) {
|
||||
String locale = data.getExtras().getString(NewLocaleDialog.INTENT_EXTRA_LOCALE);
|
||||
if (locale != null && locale.length() > 0) {
|
||||
// Get current custom locale list
|
||||
String customLocales = mPrefs.getString(CUSTOM_LOCALES, null);
|
||||
|
||||
// Update
|
||||
if (customLocales == null) {
|
||||
customLocales = locale;
|
||||
} else {
|
||||
customLocales += CUSTOM_LOCALES_SEP + locale;
|
||||
}
|
||||
|
||||
// Save prefs
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "add/customLocales: " + customLocales);
|
||||
}
|
||||
mPrefs.edit().putString(CUSTOM_LOCALES, customLocales).commit();
|
||||
|
||||
Toast.makeText(this,
|
||||
getString(R.string.added_custom_locale_1s, locale),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
|
||||
// Update list view
|
||||
setupLocaleList();
|
||||
|
||||
// Find the item to select it in the list view
|
||||
checkLocaleInList(locale);
|
||||
|
||||
if (data.getExtras().getBoolean(NewLocaleDialog.INTENT_EXTRA_SELECT)) {
|
||||
changeSystemLocale(locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
updateLocaleButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
||||
if (menuInfo instanceof AdapterContextMenuInfo) {
|
||||
int position = ((AdapterContextMenuInfo) menuInfo).position;
|
||||
Object o = mListView.getItemAtPosition(position);
|
||||
if (o instanceof LocaleInfo) {
|
||||
if (((LocaleInfo) o).isCustom()) {
|
||||
menu.setHeaderTitle("System Locale");
|
||||
menu.add(0, MENU_APPLY, 0, "Apply");
|
||||
} else {
|
||||
menu.setHeaderTitle("Custom Locale");
|
||||
menu.add(0, MENU_APPLY, 0, "Apply");
|
||||
menu.add(0, MENU_REMOVE, 0, "Remove");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
if (id == DLG_REMOVE_ID) {
|
||||
return createRemoveLocaleDialog();
|
||||
}
|
||||
return super.onCreateDialog(id);
|
||||
}
|
||||
|
||||
//--- private parts ---
|
||||
|
||||
private void setupLocaleList() {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Update locate list");
|
||||
}
|
||||
|
||||
ArrayList<LocaleInfo> data = new ArrayList<LocaleInfo>();
|
||||
|
||||
// Insert all system locales
|
||||
String[] locales = getAssets().getLocales();
|
||||
for (String locale : locales) {
|
||||
if (locale != null && locale.length() > 0) {
|
||||
Locale loc = new Locale(locale);
|
||||
data.add(new LocaleInfo(locale, loc.getDisplayName()));
|
||||
}
|
||||
}
|
||||
locales = null;
|
||||
|
||||
// Insert all custom locales
|
||||
String customLocales = mPrefs.getString(CUSTOM_LOCALES, "");
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "customLocales: " + customLocales);
|
||||
}
|
||||
for (String locale : customLocales.split(CUSTOM_LOCALES_SEP)) {
|
||||
if (locale != null && locale.length() > 0) {
|
||||
Locale loc = new Locale(locale);
|
||||
data.add(new LocaleInfo(
|
||||
locale,
|
||||
loc.getDisplayName(),
|
||||
true /*custom*/));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort all locales by code
|
||||
Collections.sort(data, new Comparator<LocaleInfo>() {
|
||||
public int compare(LocaleInfo lhs, LocaleInfo rhs) {
|
||||
return lhs.getLocale().compareTo(rhs.getLocale());
|
||||
}
|
||||
});
|
||||
|
||||
// Update the list view adapter
|
||||
mListView.setAdapter(new ArrayAdapter<LocaleInfo>(
|
||||
this,
|
||||
android.R.layout.simple_list_item_single_choice,
|
||||
data));
|
||||
updateLocaleButtons();
|
||||
}
|
||||
|
||||
private void changeSystemLocale(String locale) {
|
||||
if (ChangeLocale.changeSystemLocale(locale)) {
|
||||
Toast.makeText(this,
|
||||
getString(R.string.select_locale_1s, locale),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void displayCurrentLocale() {
|
||||
try {
|
||||
IActivityManager am = ActivityManager.getService();
|
||||
Configuration config = am.getConfiguration();
|
||||
|
||||
if (config.locale != null) {
|
||||
String text = String.format("%1$s - %2$s",
|
||||
config.locale.toString(),
|
||||
config.locale.getDisplayName());
|
||||
mCurrentLocaleTextView.setText(text);
|
||||
|
||||
checkLocaleInList(config.locale.toString());
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "get current locale failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Find the locale by code to select it in the list view */
|
||||
private void checkLocaleInList(String locale) {
|
||||
ListAdapter a = mListView.getAdapter();
|
||||
for (int i = 0; i < a.getCount(); i++) {
|
||||
Object o = a.getItem(i);
|
||||
if (o instanceof LocaleInfo) {
|
||||
String code = ((LocaleInfo) o).getLocale();
|
||||
if (code != null && code.equals(locale)) {
|
||||
mListView.setSelection(i);
|
||||
mListView.clearChoices();
|
||||
mListView.setItemChecked(i, true);
|
||||
updateLocaleButtons();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LocaleInfo getCheckedLocale() {
|
||||
int pos = mListView.getCheckedItemPosition();
|
||||
ListAdapter a = mListView.getAdapter();
|
||||
int n = a.getCount();
|
||||
if (pos >= 0 && pos < n) {
|
||||
Object o = a.getItem(pos);
|
||||
if (o instanceof LocaleInfo) {
|
||||
return (LocaleInfo) o;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Update the Select/Remove buttons based on the currently checked locale. */
|
||||
private void updateLocaleButtons() {
|
||||
LocaleInfo info = getCheckedLocale();
|
||||
if (info != null) {
|
||||
// Enable it
|
||||
mSelectLocaleButton.setEnabled(true);
|
||||
mSelectLocaleButton.setText(
|
||||
getString(R.string.select_locale_1s_button, info.getLocale()));
|
||||
|
||||
// Enable the remove button only for custom locales and set the tag to the locale
|
||||
mRemoveLocaleButton.setEnabled(info.isCustom());
|
||||
} else {
|
||||
// If nothing is selected, disable the buttons
|
||||
mSelectLocaleButton.setEnabled(false);
|
||||
mSelectLocaleButton.setText(R.string.select_locale_button);
|
||||
|
||||
mRemoveLocaleButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/** Invoked by the button "Add new..." */
|
||||
private void onAddNewLocale() {
|
||||
Intent i = new Intent(CustomLocaleActivity.this, NewLocaleDialog.class);
|
||||
startActivityForResult(i, UPDATE_LIST);
|
||||
}
|
||||
|
||||
/** Invoked by the button Select / mSelectLocaleButton */
|
||||
private void onSelectLocale() {
|
||||
LocaleInfo info = getCheckedLocale();
|
||||
if (info != null) {
|
||||
changeSystemLocale(info.getLocale());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked by the button Remove / mRemoveLocaleButton.
|
||||
* Creates a dialog to ask for confirmation before actually remove the custom locale.
|
||||
*/
|
||||
private Dialog createRemoveLocaleDialog() {
|
||||
|
||||
LocaleInfo info = getCheckedLocale();
|
||||
final String localeToRemove = info == null ? "<error>" : info.getLocale();
|
||||
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||
b.setMessage(getString(R.string.confirm_remove_locale_1s, localeToRemove));
|
||||
b.setCancelable(false);
|
||||
b.setPositiveButton(R.string.confirm_remove_locale_yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
removeCustomLocale(localeToRemove);
|
||||
dismissDialog(DLG_REMOVE_ID);
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(R.string.confirm_remove_locale_no,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismissDialog(DLG_REMOVE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
return b.create();
|
||||
}
|
||||
|
||||
private void removeCustomLocale(String localeToRemove) {
|
||||
// Get current custom locale list
|
||||
String oldLocales = mPrefs.getString(CUSTOM_LOCALES, "");
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Remove " + localeToRemove + " from custom locales: " + oldLocales);
|
||||
}
|
||||
|
||||
// Update
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String locale : oldLocales.split(CUSTOM_LOCALES_SEP)) {
|
||||
if (locale != null && locale.length() > 0 && !locale.equals(localeToRemove)) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(CUSTOM_LOCALES_SEP);
|
||||
}
|
||||
sb.append(locale);
|
||||
}
|
||||
}
|
||||
|
||||
String newLocales = sb.toString();
|
||||
if (!newLocales.equals(oldLocales)) {
|
||||
// Save prefs
|
||||
boolean ok = mPrefs.edit().putString(CUSTOM_LOCALES, newLocales).commit();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Prefs commit:" + Boolean.toString(ok) + ". Saved: " + newLocales);
|
||||
}
|
||||
|
||||
Toast.makeText(this,
|
||||
getString(R.string.removed_custom_locale_1s, localeToRemove),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
|
||||
// Update list view
|
||||
setupLocaleList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Immutable structure that holds the information displayed by a list view item.
|
||||
*/
|
||||
private static class LocaleInfo {
|
||||
private final String mLocale;
|
||||
private final String mDisplayName;
|
||||
private final boolean mIsCustom;
|
||||
|
||||
public LocaleInfo(String locale, String displayName, boolean isCustom) {
|
||||
mLocale = locale;
|
||||
mDisplayName = displayName;
|
||||
mIsCustom = isCustom;
|
||||
}
|
||||
|
||||
public LocaleInfo(String locale, String displayName) {
|
||||
this(locale, displayName, false /*custom*/);
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return mLocale;
|
||||
}
|
||||
|
||||
public boolean isCustom() {
|
||||
return mIsCustom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(mLocale)
|
||||
.append(" - ")
|
||||
.append(mDisplayName);
|
||||
if (mIsCustom) {
|
||||
sb.append(" [Custom]");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.customlocale2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
//-----------------------------------------------
|
||||
|
||||
/**
|
||||
* Broadcast receiver that can change the system's locale.
|
||||
* <p/>
|
||||
* This allows an external script such as an automated testing framework
|
||||
* to easily trigger a locale change on an emulator as such:
|
||||
* <pre>
|
||||
* $ adb shell am broadcast -a com.android.intent.action.SET_LOCALE \
|
||||
* --es com.android.intent.extra.LOCALE en_US
|
||||
* </pre>
|
||||
*/
|
||||
public class CustomLocaleReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = CustomLocaleReceiver.class.getSimpleName();
|
||||
private static final boolean DEBUG = true;
|
||||
|
||||
/** Intent action that triggers this receiver. */
|
||||
public static final String ACTION_SET_LOCALE = "com.android.intent.action.SET_LOCALE";
|
||||
/** An extra String that specifies the locale to set, in the form "en_US". */
|
||||
public static final String EXTRA_LOCALE = "com.android.intent.extra.LOCALE";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
setResult(Activity.RESULT_CANCELED, null, null);
|
||||
if (intent == null || ! ACTION_SET_LOCALE.equals(intent.getAction())) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Invalid intent: " + (intent == null ? "null" : intent.toString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String locale = intent.getStringExtra(EXTRA_LOCALE);
|
||||
|
||||
// Enforce the locale string is either in the form "ab" or "ab_cd"
|
||||
boolean is_ok = locale != null;
|
||||
is_ok = is_ok && (locale.length() == 2 || locale.length() == 5);
|
||||
if (is_ok && locale.length() >= 2) {
|
||||
is_ok = Character.isLetter(locale.charAt(0)) &&
|
||||
Character.isLetter(locale.charAt(1));
|
||||
}
|
||||
if (is_ok && locale.length() == 5) {
|
||||
is_ok = locale.charAt(2) == '_' &&
|
||||
Character.isLetter(locale.charAt(3)) &&
|
||||
Character.isLetter(locale.charAt(4));
|
||||
}
|
||||
|
||||
if (!is_ok && DEBUG) {
|
||||
Log.e(TAG, "Invalid locale: expected ab_CD but got " + locale);
|
||||
} else if (is_ok) {
|
||||
ChangeLocale.changeSystemLocale(locale);
|
||||
setResult(Activity.RESULT_OK, locale, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.customlocale2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* Dialog to ask the user for a new locale. <p/> Returns the locale code (e.g.
|
||||
* "en_US") via an intent with a "locale" extra string and a "select" extra
|
||||
* boolean.
|
||||
*/
|
||||
public class NewLocaleDialog extends Activity implements View.OnClickListener {
|
||||
|
||||
public static final String INTENT_EXTRA_LOCALE = "locale";
|
||||
public static final String INTENT_EXTRA_SELECT = "select";
|
||||
|
||||
private static final String TAG = "NewLocale";
|
||||
private static final boolean DEBUG = true;
|
||||
private Button mButtonAdd;
|
||||
private Button mButtonAddSelect;
|
||||
private EditText mEditText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.new_locale);
|
||||
|
||||
mEditText = (EditText) findViewById(R.id.value);
|
||||
|
||||
mButtonAdd = (Button) findViewById(R.id.add);
|
||||
mButtonAdd.setOnClickListener(this);
|
||||
|
||||
mButtonAddSelect = (Button) findViewById(R.id.add_and_select);
|
||||
mButtonAddSelect.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
String locale = mEditText.getText().toString();
|
||||
boolean select = v == mButtonAddSelect;
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "New Locale: " + locale + (select ? " + select" : ""));
|
||||
}
|
||||
|
||||
Intent data = new Intent(NewLocaleDialog.this, NewLocaleDialog.class);
|
||||
data.putExtra(INTENT_EXTRA_LOCALE, locale);
|
||||
data.putExtra(INTENT_EXTRA_SELECT, select);
|
||||
setResult(RESULT_OK, data);
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue