summaryrefslogtreecommitdiffstats
path: root/apps/CustomLocale
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:29:09 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:29:09 -0800
commit52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98 (patch)
tree2eb01432fa3da41550dd622d29fb672509122b51 /apps/CustomLocale
parentd4aee0c0caa00aa02d4c50ed28151591ac0456b5 (diff)
downloadandroid_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.tar.gz
android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.tar.bz2
android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.zip
auto import from //depot/cupcake/@135843
Diffstat (limited to 'apps/CustomLocale')
-rw-r--r--apps/CustomLocale/Android.mk11
-rw-r--r--apps/CustomLocale/AndroidManifest.xml37
-rw-r--r--apps/CustomLocale/res/drawable/icon.pngbin0 -> 3133 bytes
-rw-r--r--apps/CustomLocale/res/layout/list_item.xml35
-rw-r--r--apps/CustomLocale/res/layout/main.xml62
-rw-r--r--apps/CustomLocale/res/layout/new_locale.xml49
-rw-r--r--apps/CustomLocale/res/values-fr/strings.xml25
-rw-r--r--apps/CustomLocale/res/values/colors.xml18
-rw-r--r--apps/CustomLocale/res/values/strings.xml26
-rw-r--r--apps/CustomLocale/res/values/styles.xml25
-rw-r--r--apps/CustomLocale/src/com/android/customlocale/CustomLocaleActivity.java326
-rw-r--r--apps/CustomLocale/src/com/android/customlocale/NewLocaleDialog.java93
12 files changed, 707 insertions, 0 deletions
diff --git a/apps/CustomLocale/Android.mk b/apps/CustomLocale/Android.mk
new file mode 100644
index 000000000..275207f29
--- /dev/null
+++ b/apps/CustomLocale/Android.mk
@@ -0,0 +1,11 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := CustomLocale
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
diff --git a/apps/CustomLocale/AndroidManifest.xml b/apps/CustomLocale/AndroidManifest.xml
new file mode 100644
index 000000000..9dfa89630
--- /dev/null
+++ b/apps/CustomLocale/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?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.customlocale">
+ <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:name="NewLocaleDialog"
+ android:theme="@android:style/Theme.Dialog" />
+ </application>
+ <uses-sdk android:minSdkVersion="3" />
+ <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+ <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
+</manifest>
diff --git a/apps/CustomLocale/res/drawable/icon.png b/apps/CustomLocale/res/drawable/icon.png
new file mode 100644
index 000000000..cb40a1988
--- /dev/null
+++ b/apps/CustomLocale/res/drawable/icon.png
Binary files differ
diff --git a/apps/CustomLocale/res/layout/list_item.xml b/apps/CustomLocale/res/layout/list_item.xml
new file mode 100644
index 000000000..8c59f92c7
--- /dev/null
+++ b/apps/CustomLocale/res/layout/list_item.xml
@@ -0,0 +1,35 @@
+<?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:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="5dip">
+ <TextView
+ android:id="@+id/locale_code"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:textAppearanceLarge"
+ android:layout_weight="1"
+ android:text="@string/locale_default" />
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/locale_name"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:textAppearance"
+ android:layout_weight="1" />
+</LinearLayout> \ No newline at end of file
diff --git a/apps/CustomLocale/res/layout/main.xml b/apps/CustomLocale/res/layout/main.xml
new file mode 100644
index 000000000..b1eaa51ba
--- /dev/null
+++ b/apps/CustomLocale/res/layout/main.xml
@@ -0,0 +1,62 @@
+<?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="fill_parent"
+ android:layout_height="fill_parent">
+ <TextView
+ android:layout_width="fill_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="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:padding="5dip" />
+ <TextView
+ android:layout_width="fill_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" />
+ <ListView
+ android:id="@id/android:list"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:padding="8dip" />
+ <TextView
+ android:id="@id/android:empty"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:text="@string/no_data_label" />
+ <Button
+ android:id="@+id/new_locale"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:paddingLeft="8dip"
+ android:paddingRight="8dip"
+ android:text="@string/add_new_locale_button" />
+</LinearLayout>
diff --git a/apps/CustomLocale/res/layout/new_locale.xml b/apps/CustomLocale/res/layout/new_locale.xml
new file mode 100644
index 000000000..d0d9d6c38
--- /dev/null
+++ b/apps/CustomLocale/res/layout/new_locale.xml
@@ -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="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="8dip"
+ android:paddingRight="8dip">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/new_locale_label" />
+ <EditText
+ android:id="@+id/value"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/locale_default" android:inputType="text"/>
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+ <Button
+ android:id="@+id/add"
+ android:layout_width="fill_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="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/add_select_button" android:layout_gravity="center_vertical"/>
+ </LinearLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/apps/CustomLocale/res/values-fr/strings.xml b/apps/CustomLocale/res/values-fr/strings.xml
new file mode 100644
index 000000000..8852a9aaa
--- /dev/null
+++ b/apps/CustomLocale/res/values-fr/strings.xml
@@ -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>
+ <string name="app_name">Locales Personalisées</string>
+ <string name="add_new_locale_button">Ajouter une nouvelle locale</string>
+ <string name="new_locale_label">Code de la nouvelle locale:</string>
+ <string name="add_button">Ajouter</string>
+ <string name="no_data_label">Aucune locale</string>
+ <string name="header_current_locale">Locale courrante</string>
+ <string name="header_locale_list">Liste des locales</string>
+ <string name="add_select_button">Ajouter et sélectionner</string>
+</resources>
diff --git a/apps/CustomLocale/res/values/colors.xml b/apps/CustomLocale/res/values/colors.xml
new file mode 100644
index 000000000..b9b5ad26f
--- /dev/null
+++ b/apps/CustomLocale/res/values/colors.xml
@@ -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>
diff --git a/apps/CustomLocale/res/values/strings.xml b/apps/CustomLocale/res/values/strings.xml
new file mode 100644
index 000000000..313fb87e4
--- /dev/null
+++ b/apps/CustomLocale/res/values/strings.xml
@@ -0,0 +1,26 @@
+<?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>
+ <string name="locale_default">ex_EX</string>
+ <string name="add_new_locale_button">Add New Locale</string>
+ <string name="new_locale_label">New locale code:</string>
+ <string name="add_button">Add</string>
+ <string name="no_data_label">No data</string>
+ <string name="header_current_locale">Current Locale</string>
+ <string name="header_locale_list">Locale List</string>
+ <string name="add_select_button">Add and Select</string>
+</resources>
diff --git a/apps/CustomLocale/res/values/styles.xml b/apps/CustomLocale/res/values/styles.xml
new file mode 100644
index 000000000..8ccc11cdf
--- /dev/null
+++ b/apps/CustomLocale/res/values/styles.xml
@@ -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>
diff --git a/apps/CustomLocale/src/com/android/customlocale/CustomLocaleActivity.java b/apps/CustomLocale/src/com/android/customlocale/CustomLocaleActivity.java
new file mode 100644
index 000000000..768f9105f
--- /dev/null
+++ b/apps/CustomLocale/src/com/android/customlocale/CustomLocaleActivity.java
@@ -0,0 +1,326 @@
+/*
+ * 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.customlocale;
+
+
+import android.app.ActivityManagerNative;
+import android.app.IActivityManager;
+import android.app.ListActivity;
+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.MenuItem;
+import android.view.View;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.widget.Button;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.SimpleAdapter;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.AdapterView.AdapterContextMenuInfo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * 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 CUSTOM_LOCALES_SEP = " ";
+ private static final String CUSTOM_LOCALES = "custom_locales";
+ private static final String KEY_CUSTOM = "custom";
+ private static final String KEY_NAME = "name";
+ private static final String KEY_CODE = "code";
+
+ private static final String TAG = "LocaleSetup";
+ private static final boolean DEBUG = true;
+
+ /** 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;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ mPrefs = getPreferences(MODE_PRIVATE);
+
+ Button newLocaleButton = (Button) findViewById(R.id.new_locale);
+
+ newLocaleButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ Intent i = new Intent(CustomLocaleActivity.this, NewLocaleDialog.class);
+ startActivityForResult(i, UPDATE_LIST);
+ }
+ });
+
+ mListView = (ListView) findViewById(android.R.id.list);
+ mListView.setFocusable(true);
+ mListView.setFocusableInTouchMode(true);
+ mListView.requestFocus();
+ registerForContextMenu(mListView);
+ setupLocaleList();
+
+ mCurrentLocaleTextView = (TextView) findViewById(R.id.current_locale);
+ displayCurrentLocale();
+ }
+
+ @SuppressWarnings("unchecked")
+ @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, "Added custom locale: " + locale, Toast.LENGTH_SHORT).show();
+
+ // Update list view
+ setupLocaleList();
+
+ // Find the item to select it in the list view
+ ListAdapter a = mListView.getAdapter();
+ for (int i = 0; i < a.getCount(); i++) {
+ Object o = a.getItem(i);
+ if (o instanceof Map<?, ?>) {
+ String code = ((Map<String, String>) o).get(KEY_CODE);
+ if (code != null && code.equals(locale)) {
+ mListView.setSelection(i);
+ break;
+ }
+ }
+ }
+
+ if (data.getExtras().getBoolean(NewLocaleDialog.INTENT_EXTRA_SELECT)) {
+ selectLocale(locale);
+ }
+ }
+ }
+ }
+
+ private void setupLocaleList() {
+ if (DEBUG) {
+ Log.d(TAG, "Update locate list");
+ }
+
+ ArrayList<Map<String, String>> data = new ArrayList<Map<String, String>>();
+
+ // Insert all system locales
+ String[] locales = getAssets().getLocales();
+ for (String locale : locales) {
+ Locale loc = new Locale(locale);
+
+ Map<String, String> map = new HashMap<String, String>(1);
+ map.put(KEY_CODE, locale);
+ map.put(KEY_NAME, loc.getDisplayName());
+ data.add(map);
+ }
+ 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);
+
+ Map<String, String> map = new HashMap<String, String>(1);
+ map.put(KEY_CODE, locale);
+ map.put(KEY_NAME, loc.getDisplayName() + " [Custom]");
+ // the presence of the "custom" key marks it as custom.
+ map.put(KEY_CUSTOM, "");
+ data.add(map);
+ }
+ }
+
+ // Sort all locales by code
+ Collections.sort(data, new Comparator<Map<String, String>>() {
+ public int compare(Map<String, String> lhs, Map<String, String> rhs) {
+ return lhs.get(KEY_CODE).compareTo(rhs.get(KEY_CODE));
+ }
+ });
+
+ // Update the list view adapter
+ mListView.setAdapter(new SimpleAdapter(this, data, R.layout.list_item, new String[] {
+ KEY_CODE, KEY_NAME}, new int[] {R.id.locale_code, R.id.locale_name}));
+ }
+
+ @SuppressWarnings("unchecked")
+ @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 Map<?, ?>) {
+ String locale = ((Map<String, String>) o).get(KEY_CODE);
+ String custom = ((Map<String, String>) o).get(KEY_CUSTOM);
+
+ if (custom == null) {
+ 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");
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+
+ String pendingLocale = null;
+ boolean is_custom = false;
+
+ ContextMenuInfo menuInfo = item.getMenuInfo();
+ if (menuInfo instanceof AdapterContextMenuInfo) {
+ int position = ((AdapterContextMenuInfo) menuInfo).position;
+ Object o = mListView.getItemAtPosition(position);
+ if (o instanceof Map<?, ?>) {
+ pendingLocale = ((Map<String, String>) o).get(KEY_CODE);
+ is_custom = ((Map<String, String>) o).get(KEY_CUSTOM) != null;
+ }
+ }
+
+ if (pendingLocale == null) {
+ // should never happen
+ return super.onContextItemSelected(item);
+ }
+
+ if (item.getItemId() == MENU_REMOVE) {
+ // Get current custom locale list
+ String customLocales = mPrefs.getString(CUSTOM_LOCALES, "");
+
+ if (DEBUG) {
+ Log.d(TAG, "Remove " + pendingLocale + " from custom locales: " + customLocales);
+ }
+
+ // Update
+ StringBuilder sb = new StringBuilder();
+ for (String locale : customLocales.split(CUSTOM_LOCALES_SEP)) {
+ if (locale != null && locale.length() > 0 && !locale.equals(pendingLocale)) {
+ if (sb.length() > 0) {
+ sb.append(CUSTOM_LOCALES_SEP);
+ }
+ sb.append(locale);
+ }
+ }
+ String newLocales = sb.toString();
+ if (!newLocales.equals(customLocales)) {
+ // Save prefs
+ mPrefs.edit().putString(CUSTOM_LOCALES, customLocales).commit();
+
+ Toast.makeText(this, "Removed custom locale: " + pendingLocale, Toast.LENGTH_SHORT)
+ .show();
+ }
+
+ } else if (item.getItemId() == MENU_APPLY) {
+ selectLocale(pendingLocale);
+ }
+
+ return super.onContextItemSelected(item);
+ }
+
+ private void selectLocale(String locale) {
+ if (DEBUG) {
+ Log.d(TAG, "Select locale " + locale);
+ }
+
+ try {
+ IActivityManager am = ActivityManagerNative.getDefault();
+ Configuration config = am.getConfiguration();
+
+ Locale 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);
+
+ Toast.makeText(this, "Select locale: " + locale, Toast.LENGTH_SHORT).show();
+ } catch (RemoteException e) {
+ if (DEBUG) {
+ Log.e(TAG, "Select locale failed", e);
+ }
+ }
+ }
+
+ private void displayCurrentLocale() {
+ try {
+ IActivityManager am = ActivityManagerNative.getDefault();
+ Configuration config = am.getConfiguration();
+
+ if (config.locale != null) {
+ String text = String.format("%s - %s",
+ config.locale.toString(),
+ config.locale.getDisplayName());
+ mCurrentLocaleTextView.setText(text);
+ }
+ } catch (RemoteException e) {
+ if (DEBUG) {
+ Log.e(TAG, "get current locale failed", e);
+ }
+ }
+ }
+}
diff --git a/apps/CustomLocale/src/com/android/customlocale/NewLocaleDialog.java b/apps/CustomLocale/src/com/android/customlocale/NewLocaleDialog.java
new file mode 100644
index 000000000..3626f7398
--- /dev/null
+++ b/apps/CustomLocale/src/com/android/customlocale/NewLocaleDialog.java
@@ -0,0 +1,93 @@
+/*
+ * 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.customlocale;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.KeyEvent;
+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, View.OnKeyListener {
+
+ 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;
+ private boolean mWasEmpty;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.new_locale);
+
+ mEditText = (EditText) findViewById(R.id.value);
+ mWasEmpty = true;
+
+ mButtonAdd = (Button) findViewById(R.id.add);
+ mButtonAdd.setOnClickListener(this);
+ mButtonAdd.setEnabled(false);
+
+ mButtonAddSelect = (Button) findViewById(R.id.add_and_select);
+ mButtonAddSelect.setOnClickListener(this);
+ mButtonAddSelect.setEnabled(false);
+
+ mEditText.setOnKeyListener(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();
+ }
+
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ boolean isEmpty = TextUtils.isEmpty(mEditText.getText());
+ if (isEmpty != mWasEmpty) {
+ mWasEmpty = isEmpty;
+
+ mButtonAdd.setEnabled(!isEmpty);
+ mButtonAddSelect.setEnabled(!isEmpty);
+ }
+ return false;
+ }
+}