blob: e17a6d6ec851f98915fed58c1d101daa9ebda59b [file] [log] [blame]
Jean-Michel Trivied29a652009-06-05 18:37:29 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
19import static android.provider.Settings.Secure.TTS_USE_DEFAULTS;
20import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
Jean-Michel Trivi80368622009-06-09 19:29:27 -070021import static android.provider.Settings.Secure.TTS_DEFAULT_LANG;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070022import static android.provider.Settings.Secure.TTS_DEFAULT_COUNTRY;
23import static android.provider.Settings.Secure.TTS_DEFAULT_VARIANT;
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -070024import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
Jean-Michel Trivied29a652009-06-05 18:37:29 -070025
26import android.content.ContentResolver;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070027import android.content.Intent;
28import android.content.pm.ActivityInfo;
29import android.content.pm.PackageManager;
30import android.content.pm.ResolveInfo;
Jean-Michel Trivied29a652009-06-05 18:37:29 -070031import android.os.Bundle;
32import android.preference.ListPreference;
33import android.preference.Preference;
34import android.preference.PreferenceActivity;
35import android.preference.CheckBoxPreference;
36import android.provider.Settings;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070037import android.provider.Settings.SettingNotFoundException;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070038import android.speech.tts.TextToSpeech;
Jean-Michel Trivied29a652009-06-05 18:37:29 -070039import android.util.Log;
40
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070041import java.util.List;
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -070042import java.util.Locale;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070043import java.util.StringTokenizer;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070044
Jean-Michel Trivied29a652009-06-05 18:37:29 -070045public class TextToSpeechSettings extends PreferenceActivity implements
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070046 Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
47 TextToSpeech.OnInitListener {
Jean-Michel Trivied29a652009-06-05 18:37:29 -070048
49 private static final String TAG = "TextToSpeechSettings";
Jean-Michel Trivied29a652009-06-05 18:37:29 -070050
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070051 private static final String KEY_TTS_PLAY_EXAMPLE = "tts_play_example";
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070052 private static final String KEY_TTS_INSTALL_DATA = "tts_install_data";
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070053 private static final String KEY_TTS_USE_DEFAULT = "toggle_use_default_tts_settings";
Jean-Michel Trivied29a652009-06-05 18:37:29 -070054 private static final String KEY_TTS_DEFAULT_RATE = "tts_default_rate";
Jean-Michel Trivi80368622009-06-09 19:29:27 -070055 private static final String KEY_TTS_DEFAULT_LANG = "tts_default_lang";
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070056 private static final String KEY_TTS_DEFAULT_COUNTRY = "tts_default_country";
57 private static final String KEY_TTS_DEFAULT_VARIANT = "tts_default_variant";
58
59 private static final String LOCALE_DELIMITER = "-";
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070060
Jean-Michel Trivi628431d2009-07-17 16:52:54 -070061 private static final String FALLBACK_TTS_DEFAULT_SYNTH =
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -070062 TextToSpeech.Engine.DEFAULT_SYNTH;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070063
64 private Preference mPlayExample = null;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070065 private Preference mInstallData = null;
Jean-Michel Trivied29a652009-06-05 18:37:29 -070066 private CheckBoxPreference mUseDefaultPref = null;
67 private ListPreference mDefaultRatePref = null;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070068 private ListPreference mDefaultLocPref = null;
69 private String mDefaultLanguage = null;
70 private String mDefaultCountry = null;
71 private String mDefaultLocVariant = null;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070072 private String mDefaultEng = "";
73
74 private boolean mEnableDemo = false;
75
76 private TextToSpeech mTts = null;
77
78 /**
79 * Request code (arbitrary value) for voice data check through
80 * startActivityForResult.
81 */
82 private static final int VOICE_DATA_INTEGRITY_CHECK = 1977;
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -070083 /**
84 * Request code (arbitrary value) for voice data installation through
85 * startActivityForResult.
86 */
87 private static final int VOICE_DATA_INSTALLATION = 1980;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070088
Jean-Michel Trivied29a652009-06-05 18:37:29 -070089 @Override
90 protected void onCreate(Bundle savedInstanceState) {
91 super.onCreate(savedInstanceState);
92
93 addPreferencesFromResource(R.xml.tts_settings);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070094
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -070095 mEnableDemo = false;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070096 initClickers();
Jean-Michel Trivied29a652009-06-05 18:37:29 -070097 initDefaultSettings();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -070098 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -070099
100
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700101 @Override
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700102 protected void onStart() {
103 super.onStart();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700104 // whenever we return to this screen, we don't know the state of the
105 // system, so we have to recheck that we can play the demo, or it must be disabled.
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700106 // TODO make the TTS service listen to "changes in the system", i.e. sd card un/mount
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700107 initClickers();
108 updateWidgetState();
109 checkVoiceData();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700110 }
111
112
113 @Override
114 protected void onDestroy() {
115 super.onDestroy();
116 if (mTts != null) {
117 mTts.shutdown();
118 }
119 }
120
121
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700122 private void initClickers() {
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700123 mPlayExample = findPreference(KEY_TTS_PLAY_EXAMPLE);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700124 mPlayExample.setOnPreferenceClickListener(this);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700125
126 mInstallData = findPreference(KEY_TTS_INSTALL_DATA);
127 mInstallData.setOnPreferenceClickListener(this);
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700128 }
129
130
131 private void initDefaultSettings() {
132 ContentResolver resolver = getContentResolver();
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700133 int intVal = 0;
134
135 // Find the default TTS values in the settings, initialize and store the
136 // settings if they are not found.
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700137
138 // "Use Defaults"
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700139 mUseDefaultPref = (CheckBoxPreference) findPreference(KEY_TTS_USE_DEFAULT);
140 try {
141 intVal = Settings.Secure.getInt(resolver, TTS_USE_DEFAULTS);
142 } catch (SettingNotFoundException e) {
143 // "use default" setting not found, initialize it
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700144 intVal = TextToSpeech.Engine.USE_DEFAULTS;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700145 Settings.Secure.putInt(resolver, TTS_USE_DEFAULTS, intVal);
146 }
147 mUseDefaultPref.setChecked(intVal == 1);
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700148 mUseDefaultPref.setOnPreferenceChangeListener(this);
149
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700150 // Default engine
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700151 String engine = Settings.Secure.getString(resolver, TTS_DEFAULT_SYNTH);
152 if (engine == null) {
153 // TODO move FALLBACK_TTS_DEFAULT_SYNTH to TextToSpeech
154 engine = FALLBACK_TTS_DEFAULT_SYNTH;
155 Settings.Secure.putString(resolver, TTS_DEFAULT_SYNTH, engine);
156 }
157 mDefaultEng = engine;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700158
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700159 // Default rate
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700160 mDefaultRatePref = (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE);
161 try {
162 intVal = Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
163 } catch (SettingNotFoundException e) {
164 // default rate setting not found, initialize it
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700165 intVal = TextToSpeech.Engine.DEFAULT_RATE;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700166 Settings.Secure.putInt(resolver, TTS_DEFAULT_RATE, intVal);
167 }
168 mDefaultRatePref.setValue(String.valueOf(intVal));
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700169 mDefaultRatePref.setOnPreferenceChangeListener(this);
170
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700171 // Default language / country / variant : these three values map to a single ListPref
172 // representing the matching Locale
173 String language = null;
174 String country = null;
175 String variant = null;
176 mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700177 language = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG);
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700178 if (language == null) {
179 // the default language property isn't set, use that of the current locale
180 Locale currentLocale = Locale.getDefault();
181 language = currentLocale.getISO3Language();
182 country = currentLocale.getISO3Country();
183 variant = currentLocale.getVariant();
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700184 Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, language);
185 Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country);
186 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
Jean-Michel Trivi80368622009-06-09 19:29:27 -0700187 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700188 mDefaultLanguage = language;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700189 if (country == null) {
190 // country wasn't initialized yet because a default language was found
191 country = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_COUNTRY);
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700192 if (country == null) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700193 // default country setting not found, initialize it, as well as the variant;
Jean-Michel Trivi00d4fbf2009-07-07 17:08:32 -0700194 Locale currentLocale = Locale.getDefault();
195 country = currentLocale.getISO3Country();
196 variant = currentLocale.getVariant();
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700197 Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country);
198 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700199 }
200 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700201 mDefaultCountry = country;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700202 if (variant == null) {
203 // variant wasn't initialized yet because a default country was found
204 variant = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_VARIANT);
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700205 if (variant == null) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700206 // default variant setting not found, initialize it
Jean-Michel Trivi00d4fbf2009-07-07 17:08:32 -0700207 Locale currentLocale = Locale.getDefault();
208 variant = currentLocale.getVariant();
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700209 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700210 }
211 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700212 mDefaultLocVariant = variant;
213
214 setDefaultLocalePref(language, country, variant);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700215 mDefaultLocPref.setOnPreferenceChangeListener(this);
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700216 }
217
218
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700219 /**
220 * Ask the current default engine to launch the matching CHECK_TTS_DATA activity
221 * to check the required TTS files are properly installed.
222 */
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700223 private void checkVoiceData() {
224 PackageManager pm = getPackageManager();
225 Intent intent = new Intent();
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700226 intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700227 List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
228 // query only the package that matches that of the default engine
229 for (int i = 0; i < resolveInfos.size(); i++) {
230 ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
231 if (mDefaultEng.equals(currentActivityInfo.packageName)) {
232 intent.setClassName(mDefaultEng, currentActivityInfo.name);
233 this.startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
234 }
235 }
236 }
237
238
239 /**
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700240 * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity
241 * so the required TTS files are properly installed.
242 */
243 private void installVoiceData() {
244 PackageManager pm = getPackageManager();
245 Intent intent = new Intent();
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700246 intent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700247 List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
248 // query only the package that matches that of the default engine
249 for (int i = 0; i < resolveInfos.size(); i++) {
250 ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
251 if (mDefaultEng.equals(currentActivityInfo.packageName)) {
252 intent.setClassName(mDefaultEng, currentActivityInfo.name);
253 this.startActivityForResult(intent, VOICE_DATA_INSTALLATION);
254 }
255 }
256 }
257
258
259 /**
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700260 * Called when the TTS engine is initialized.
261 */
262 public void onInit(int status) {
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700263 if (status == TextToSpeech.SUCCESS) {
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700264 Log.v(TAG, "TTS engine for settings screen initialized.");
265 mEnableDemo = true;
266 } else {
267 Log.v(TAG, "TTS engine for settings screen failed to initialize successfully.");
268 mEnableDemo = false;
269 }
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700270 updateWidgetState();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700271 }
272
273
274 /**
275 * Called when voice data integrity check returns
276 */
277 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
278 if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
279 if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
280 Log.v(TAG, "Voice data check passed");
281 if (mTts == null) {
282 mTts = new TextToSpeech(this, this);
Jean-Michel Trivi628431d2009-07-17 16:52:54 -0700283 mTts.setLanguage(Locale.getDefault());
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700284 }
285 } else {
286 Log.v(TAG, "Voice data check failed");
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700287 mEnableDemo = false;
288 updateWidgetState();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700289 }
290 }
291 }
292
293
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700294 public boolean onPreferenceChange(Preference preference, Object objValue) {
295 if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) {
296 // "Use Defaults"
297 int value = (Boolean)objValue ? 1 : 0;
Jean-Michel Trivi80368622009-06-09 19:29:27 -0700298 Settings.Secure.putInt(getContentResolver(), TTS_USE_DEFAULTS,
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700299 value);
300 Log.i(TAG, "TTS use default settings is "+objValue.toString());
301 } else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) {
302 // Default rate
303 int value = Integer.parseInt((String) objValue);
304 try {
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700305 Settings.Secure.putInt(getContentResolver(),
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700306 TTS_DEFAULT_RATE, value);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700307 if (mTts != null) {
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700308 mTts.setSpeechRate((float)(value/100.0f));
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700309 }
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700310 Log.i(TAG, "TTS default rate is "+value);
311 } catch (NumberFormatException e) {
312 Log.e(TAG, "could not persist default TTS rate setting", e);
313 }
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700314 } else if (KEY_TTS_DEFAULT_LANG.equals(preference.getKey())) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700315 // Default locale
316 ContentResolver resolver = getContentResolver();
317 parseLocaleInfo((String) objValue);
318 Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, mDefaultLanguage);
319 Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, mDefaultCountry);
320 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, mDefaultLocVariant);
321 Log.v(TAG, "TTS default lang/country/variant set to "
322 + mDefaultLanguage + "/" + mDefaultCountry + "/" + mDefaultLocVariant);
Jean-Michel Trivi628431d2009-07-17 16:52:54 -0700323 if (mTts != null) {
324 mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry));
325 }
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700326 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700327
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700328 return true;
329 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700330
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700331
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700332 /**
333 * Called when mPlayExample or mInstallData is clicked
334 */
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700335 public boolean onPreferenceClick(Preference preference) {
336 if (preference == mPlayExample) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700337 // Play example
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700338 if (mTts != null) {
339 mTts.speak(getResources().getString(R.string.tts_demo),
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700340 TextToSpeech.QUEUE_FLUSH, null);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700341 }
342 return true;
343 }
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700344 if (preference == mInstallData) {
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700345 installVoiceData();
346 // quit this activity so it needs to be restarted after installation of the voice data
347 finish();
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700348 return true;
349 }
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700350 return false;
351 }
352
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700353
354 private void updateWidgetState() {
355 mPlayExample.setEnabled(mEnableDemo);
356 mUseDefaultPref.setEnabled(mEnableDemo);
357 mDefaultRatePref.setEnabled(mEnableDemo);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700358 mDefaultLocPref.setEnabled(mEnableDemo);
359
360 mInstallData.setEnabled(!mEnableDemo);
361 }
362
363
364 private void parseLocaleInfo(String locale) {
365 StringTokenizer tokenizer = new StringTokenizer(locale, LOCALE_DELIMITER);
366 mDefaultLanguage = "";
367 mDefaultCountry = "";
368 mDefaultLocVariant = "";
369 if (tokenizer.hasMoreTokens()) {
370 mDefaultLanguage = tokenizer.nextToken().trim();
371 }
372 if (tokenizer.hasMoreTokens()) {
373 mDefaultCountry = tokenizer.nextToken().trim();
374 }
375 if (tokenizer.hasMoreTokens()) {
376 mDefaultLocVariant = tokenizer.nextToken().trim();
377 }
378 }
379
380
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700381 private void setDefaultLocalePref(String language, String country, String variant) {
382 // build a string from the default lang/country/variant trio,
383 String localeString = new String(language);
384 if (country.compareTo("") != 0) {
385 localeString += LOCALE_DELIMITER + country;
386 } else {
387 localeString += LOCALE_DELIMITER + " ";
388 }
389 if (variant.compareTo("") != 0) {
390 localeString += LOCALE_DELIMITER + variant;
391 }
392
393 if (mDefaultLocPref.findIndexOfValue(localeString) > -1) {
394 mDefaultLocPref.setValue(localeString);
395 } else {
396 mDefaultLocPref.setValueIndex(0);
397 }
398
399 Log.v(TAG, "In initDefaultSettings: localeString=" + localeString);
400 }
401
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700402}