diff options
| author | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-07 18:59:28 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-07 18:59:28 -0700 |
| commit | d6fe243c1c6d5e994cacede8110eef736767bd7f (patch) | |
| tree | 1ea1e79ce0d7a59c16c6e685f586bf79909b0d02 /packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java | |
| parent | a83bef597430e9336566ca38330cc0f4e793abe1 (diff) | |
| parent | 8823c0a8c68fe669c21c539eef9fc6541f0c7494 (diff) | |
| download | frameworks_base-d6fe243c1c6d5e994cacede8110eef736767bd7f.zip frameworks_base-d6fe243c1c6d5e994cacede8110eef736767bd7f.tar.gz frameworks_base-d6fe243c1c6d5e994cacede8110eef736767bd7f.tar.bz2 | |
Merge change 6437 into donut
* changes:
Backup / Restore locale preference.
Diffstat (limited to 'packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java')
| -rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java index 5f3fba8..2c5775a 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java @@ -16,16 +16,22 @@ package com.android.providers.settings; +import java.util.Locale; + +import android.app.ActivityManagerNative; +import android.app.IActivityManager; import android.backup.BackupDataInput; import android.content.ContentResolver; import android.content.Context; import android.content.IContentService; +import android.content.res.Configuration; import android.location.LocationManager; import android.media.AudioManager; import android.os.IHardwareService; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; +import android.text.TextUtils; import android.util.Log; public class SettingsHelper { @@ -110,7 +116,6 @@ public class SettingsHelper { } } - /* TODO: Get a list of all sync providers and save/restore the settings */ byte[] getSyncProviders() { byte[] sync = new byte[1 + PROVIDERS.length]; try { @@ -141,4 +146,53 @@ public class SettingsHelper { Log.w(TAG, "Unable to read sync settings"); } } + + byte[] getLocaleData() { + Configuration conf = mContext.getResources().getConfiguration(); + final Locale loc = conf.locale; + String localeString = loc.getLanguage(); + String country = loc.getCountry(); + if (!TextUtils.isEmpty(country)) { + localeString += "_" + country; + } + return localeString.getBytes(); + } + + /** + * Sets the locale specified. Input data is the equivalent of "ll_cc".getBytes(), where + * "ll" is the language code and "cc" is the country code. + * @param data the locale string in bytes. + */ + void setLocaleData(byte[] data) { + // Check if locale was set by the user: + Configuration conf = mContext.getResources().getConfiguration(); + Locale loc = conf.locale; + if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard + + final String[] availableLocales = mContext.getAssets().getLocales(); + String localeCode = new String(data); + String language = new String(data, 0, 2); + String country = data.length > 4 ? new String(data, 3, 2) : ""; + loc = null; + for (int i = 0; i < availableLocales.length; i++) { + if (availableLocales[i].equals(localeCode)) { + loc = new Locale(language, country); + break; + } + } + if (loc == null) return; // Couldn't find the saved locale in this version of the software + + try { + IActivityManager am = ActivityManagerNative.getDefault(); + Configuration config = am.getConfiguration(); + config.locale = loc; + // indicate this isn't some passing default - the user wants this remembered + config.userSetLocale = true; + + am.updateConfiguration(config); + } catch (RemoteException e) { + // Intentionally left blank + } + + } } |
