summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/LocalePicker.java
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2010-08-12 13:04:43 -0700
committerDaisuke Miyakawa <dmiyakawa@google.com>2010-08-13 13:36:51 -0700
commitc81adf598f27fb13f6043cea3b1c4f0839c337dd (patch)
tree1f05d3e901e80d2c8028c900c7f0675646285774 /src/com/android/settings/LocalePicker.java
parent6a3e48c0359b780947b3c05f3fdd2493d6a79eb9 (diff)
downloadpackages_apps_Settings-c81adf598f27fb13f6043cea3b1c4f0839c337dd.zip
packages_apps_Settings-c81adf598f27fb13f6043cea3b1c4f0839c337dd.tar.gz
packages_apps_Settings-c81adf598f27fb13f6043cea3b1c4f0839c337dd.tar.bz2
Create LocalePickerFragment for fragmentizing LocalePicker Activity.
Need to add proguard.flag, as the Activity crashes without it. Change-Id: Icbc75be4a4183920ed472ac64cc509115260f865
Diffstat (limited to 'src/com/android/settings/LocalePicker.java')
-rw-r--r--src/com/android/settings/LocalePicker.java170
1 files changed, 5 insertions, 165 deletions
diff --git a/src/com/android/settings/LocalePicker.java b/src/com/android/settings/LocalePicker.java
index c8548fb..f669712 100644
--- a/src/com/android/settings/LocalePicker.java
+++ b/src/com/android/settings/LocalePicker.java
@@ -16,173 +16,13 @@
package com.android.settings;
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import android.app.ListActivity;
-import android.app.backup.BackupManager;
-import android.content.res.Configuration;
+import android.app.Activity;
import android.os.Bundle;
-import android.os.RemoteException;
-import android.util.Log;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-import java.text.Collator;
-import java.util.Arrays;
-import java.util.Locale;
-
-public class LocalePicker extends ListActivity {
- private static final String TAG = "LocalePicker";
- private static final boolean DEBUG = false;
-
- Loc[] mLocales;
- String[] mSpecialLocaleCodes;
- String[] mSpecialLocaleNames;
-
- private static class Loc implements Comparable {
- static Collator sCollator = Collator.getInstance();
-
- String label;
- Locale locale;
-
- public Loc(String label, Locale locale) {
- this.label = label;
- this.locale = locale;
- }
-
- @Override
- public String toString() {
- return this.label;
- }
-
- public int compareTo(Object o) {
- return sCollator.compare(this.label, ((Loc) o).label);
- }
- }
-
- int getContentView() {
- return R.layout.locale_picker;
- }
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(getContentView());
-
- mSpecialLocaleCodes = getResources().getStringArray(R.array.special_locale_codes);
- mSpecialLocaleNames = getResources().getStringArray(R.array.special_locale_names);
-
- String[] locales = getAssets().getLocales();
- Arrays.sort(locales);
-
- final int origSize = locales.length;
- Loc[] preprocess = new Loc[origSize];
- int finalSize = 0;
- for (int i = 0 ; i < origSize; i++ ) {
- String s = locales[i];
- int len = s.length();
- if (len == 5) {
- String language = s.substring(0, 2);
- String country = s.substring(3, 5);
- Locale l = new Locale(language, country);
-
- if (finalSize == 0) {
- if (DEBUG) {
- Log.v(TAG, "adding initial "+ toTitleCase(l.getDisplayLanguage(l)));
- }
- preprocess[finalSize++] =
- new Loc(toTitleCase(l.getDisplayLanguage(l)), l);
- } else {
- // check previous entry:
- // same lang and a country -> upgrade to full name and
- // insert ours with full name
- // diff lang -> insert ours with lang-only name
- if (preprocess[finalSize-1].locale.getLanguage().equals(
- language)) {
- if (DEBUG) {
- Log.v(TAG, "backing up and fixing "+
- preprocess[finalSize-1].label+" to "+
- getDisplayName(preprocess[finalSize-1].locale));
- }
- preprocess[finalSize-1].label = toTitleCase(
- getDisplayName(preprocess[finalSize-1].locale));
- if (DEBUG) {
- Log.v(TAG, " and adding "+ toTitleCase(getDisplayName(l)));
- }
- preprocess[finalSize++] =
- new Loc(toTitleCase(getDisplayName(l)), l);
- } else {
- String displayName;
- if (s.equals("zz_ZZ")) {
- displayName = "Pseudo...";
- } else {
- displayName = toTitleCase(l.getDisplayLanguage(l));
- }
- if (DEBUG) {
- Log.v(TAG, "adding "+displayName);
- }
- preprocess[finalSize++] = new Loc(displayName, l);
- }
- }
- }
- }
- mLocales = new Loc[finalSize];
- for (int i = 0; i < finalSize ; i++) {
- mLocales[i] = preprocess[i];
- }
- Arrays.sort(mLocales);
- int layoutId = R.layout.locale_picker_item;
- int fieldId = R.id.locale;
- ArrayAdapter<Loc> adapter =
- new ArrayAdapter<Loc>(this, layoutId, fieldId, mLocales);
- getListView().setAdapter(adapter);
- }
-
- private static String toTitleCase(String s) {
- if (s.length() == 0) {
- return s;
- }
-
- return Character.toUpperCase(s.charAt(0)) + s.substring(1);
- }
-
- private String getDisplayName(Locale l) {
- String code = l.toString();
-
- for (int i = 0; i < mSpecialLocaleCodes.length; i++) {
- if (mSpecialLocaleCodes[i].equals(code)) {
- return mSpecialLocaleNames[i];
- }
- }
-
- return l.getDisplayName(l);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- getListView().requestFocus();
- }
+public class LocalePicker extends Activity {
@Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- try {
- IActivityManager am = ActivityManagerNative.getDefault();
- Configuration config = am.getConfiguration();
-
- Loc 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();
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.locale_picker);
}
}