blob: d3d59fa26055abeb1965387d4e4f61fb4170d963 [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 Trivi6dde8962009-08-11 09:06:58 -070095 setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
96
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -070097 mEnableDemo = false;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -070098 initClickers();
Jean-Michel Trivied29a652009-06-05 18:37:29 -070099 initDefaultSettings();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700100 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700101
102
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700103 @Override
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700104 protected void onStart() {
105 super.onStart();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700106 // whenever we return to this screen, we don't know the state of the
107 // 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 -0700108 // 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 -0700109 initClickers();
110 updateWidgetState();
111 checkVoiceData();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700112 }
113
114
115 @Override
116 protected void onDestroy() {
117 super.onDestroy();
118 if (mTts != null) {
119 mTts.shutdown();
120 }
121 }
122
123
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700124 private void initClickers() {
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700125 mPlayExample = findPreference(KEY_TTS_PLAY_EXAMPLE);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700126 mPlayExample.setOnPreferenceClickListener(this);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700127
128 mInstallData = findPreference(KEY_TTS_INSTALL_DATA);
129 mInstallData.setOnPreferenceClickListener(this);
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700130 }
131
132
133 private void initDefaultSettings() {
134 ContentResolver resolver = getContentResolver();
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700135 int intVal = 0;
136
137 // Find the default TTS values in the settings, initialize and store the
138 // settings if they are not found.
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700139
140 // "Use Defaults"
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700141 mUseDefaultPref = (CheckBoxPreference) findPreference(KEY_TTS_USE_DEFAULT);
142 try {
143 intVal = Settings.Secure.getInt(resolver, TTS_USE_DEFAULTS);
144 } catch (SettingNotFoundException e) {
145 // "use default" setting not found, initialize it
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700146 intVal = TextToSpeech.Engine.USE_DEFAULTS;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700147 Settings.Secure.putInt(resolver, TTS_USE_DEFAULTS, intVal);
148 }
149 mUseDefaultPref.setChecked(intVal == 1);
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700150 mUseDefaultPref.setOnPreferenceChangeListener(this);
151
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700152 // Default engine
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700153 String engine = Settings.Secure.getString(resolver, TTS_DEFAULT_SYNTH);
154 if (engine == null) {
155 // TODO move FALLBACK_TTS_DEFAULT_SYNTH to TextToSpeech
156 engine = FALLBACK_TTS_DEFAULT_SYNTH;
157 Settings.Secure.putString(resolver, TTS_DEFAULT_SYNTH, engine);
158 }
159 mDefaultEng = engine;
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700160
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700161 // Default rate
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700162 mDefaultRatePref = (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE);
163 try {
164 intVal = Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
165 } catch (SettingNotFoundException e) {
166 // default rate setting not found, initialize it
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700167 intVal = TextToSpeech.Engine.DEFAULT_RATE;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700168 Settings.Secure.putInt(resolver, TTS_DEFAULT_RATE, intVal);
169 }
170 mDefaultRatePref.setValue(String.valueOf(intVal));
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700171 mDefaultRatePref.setOnPreferenceChangeListener(this);
172
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700173 // Default language / country / variant : these three values map to a single ListPref
174 // representing the matching Locale
175 String language = null;
176 String country = null;
177 String variant = null;
178 mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700179 language = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG);
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700180 if (language == null) {
181 // the default language property isn't set, use that of the current locale
182 Locale currentLocale = Locale.getDefault();
183 language = currentLocale.getISO3Language();
184 country = currentLocale.getISO3Country();
185 variant = currentLocale.getVariant();
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700186 Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, language);
187 Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country);
188 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
Jean-Michel Trivi80368622009-06-09 19:29:27 -0700189 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700190 mDefaultLanguage = language;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700191 if (country == null) {
192 // country wasn't initialized yet because a default language was found
193 country = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_COUNTRY);
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700194 if (country == null) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700195 // default country setting not found, initialize it, as well as the variant;
Jean-Michel Trivi00d4fbf2009-07-07 17:08:32 -0700196 Locale currentLocale = Locale.getDefault();
197 country = currentLocale.getISO3Country();
198 variant = currentLocale.getVariant();
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700199 Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country);
200 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700201 }
202 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700203 mDefaultCountry = country;
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700204 if (variant == null) {
205 // variant wasn't initialized yet because a default country was found
206 variant = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_VARIANT);
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700207 if (variant == null) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700208 // default variant setting not found, initialize it
Jean-Michel Trivi00d4fbf2009-07-07 17:08:32 -0700209 Locale currentLocale = Locale.getDefault();
210 variant = currentLocale.getVariant();
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700211 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700212 }
213 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700214 mDefaultLocVariant = variant;
215
216 setDefaultLocalePref(language, country, variant);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700217 mDefaultLocPref.setOnPreferenceChangeListener(this);
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700218 }
219
220
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700221 /**
222 * Ask the current default engine to launch the matching CHECK_TTS_DATA activity
223 * to check the required TTS files are properly installed.
224 */
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700225 private void checkVoiceData() {
226 PackageManager pm = getPackageManager();
227 Intent intent = new Intent();
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700228 intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700229 List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
230 // query only the package that matches that of the default engine
231 for (int i = 0; i < resolveInfos.size(); i++) {
232 ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
233 if (mDefaultEng.equals(currentActivityInfo.packageName)) {
234 intent.setClassName(mDefaultEng, currentActivityInfo.name);
235 this.startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
236 }
237 }
238 }
239
240
241 /**
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700242 * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity
243 * so the required TTS files are properly installed.
244 */
245 private void installVoiceData() {
246 PackageManager pm = getPackageManager();
247 Intent intent = new Intent();
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700248 intent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700249 List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
250 // query only the package that matches that of the default engine
251 for (int i = 0; i < resolveInfos.size(); i++) {
252 ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
253 if (mDefaultEng.equals(currentActivityInfo.packageName)) {
254 intent.setClassName(mDefaultEng, currentActivityInfo.name);
255 this.startActivityForResult(intent, VOICE_DATA_INSTALLATION);
256 }
257 }
258 }
259
260
261 /**
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700262 * Called when the TTS engine is initialized.
263 */
264 public void onInit(int status) {
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700265 if (status == TextToSpeech.SUCCESS) {
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700266 Log.v(TAG, "TTS engine for settings screen initialized.");
267 mEnableDemo = true;
268 } else {
269 Log.v(TAG, "TTS engine for settings screen failed to initialize successfully.");
270 mEnableDemo = false;
271 }
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700272 updateWidgetState();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700273 }
274
275
276 /**
277 * Called when voice data integrity check returns
278 */
279 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
280 if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
281 if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
282 Log.v(TAG, "Voice data check passed");
283 if (mTts == null) {
284 mTts = new TextToSpeech(this, this);
Jean-Michel Trivi628431d2009-07-17 16:52:54 -0700285 mTts.setLanguage(Locale.getDefault());
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700286 }
287 } else {
288 Log.v(TAG, "Voice data check failed");
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700289 mEnableDemo = false;
290 updateWidgetState();
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700291 }
292 }
293 }
294
295
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700296 public boolean onPreferenceChange(Preference preference, Object objValue) {
297 if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) {
298 // "Use Defaults"
299 int value = (Boolean)objValue ? 1 : 0;
Jean-Michel Trivi80368622009-06-09 19:29:27 -0700300 Settings.Secure.putInt(getContentResolver(), TTS_USE_DEFAULTS,
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700301 value);
302 Log.i(TAG, "TTS use default settings is "+objValue.toString());
303 } else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) {
304 // Default rate
305 int value = Integer.parseInt((String) objValue);
306 try {
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700307 Settings.Secure.putInt(getContentResolver(),
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700308 TTS_DEFAULT_RATE, value);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700309 if (mTts != null) {
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700310 mTts.setSpeechRate((float)(value/100.0f));
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700311 }
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700312 Log.i(TAG, "TTS default rate is "+value);
313 } catch (NumberFormatException e) {
314 Log.e(TAG, "could not persist default TTS rate setting", e);
315 }
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700316 } else if (KEY_TTS_DEFAULT_LANG.equals(preference.getKey())) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700317 // Default locale
318 ContentResolver resolver = getContentResolver();
319 parseLocaleInfo((String) objValue);
320 Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, mDefaultLanguage);
321 Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, mDefaultCountry);
322 Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, mDefaultLocVariant);
323 Log.v(TAG, "TTS default lang/country/variant set to "
324 + mDefaultLanguage + "/" + mDefaultCountry + "/" + mDefaultLocVariant);
Jean-Michel Trivi628431d2009-07-17 16:52:54 -0700325 if (mTts != null) {
326 mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry));
327 }
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700328 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700329
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700330 return true;
331 }
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700332
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700333
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700334 /**
335 * Called when mPlayExample or mInstallData is clicked
336 */
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700337 public boolean onPreferenceClick(Preference preference) {
338 if (preference == mPlayExample) {
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700339 // Play example
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700340 if (mTts != null) {
341 mTts.speak(getResources().getString(R.string.tts_demo),
Jean-Michel Trivi387dc0c2009-07-28 15:13:35 -0700342 TextToSpeech.QUEUE_FLUSH, null);
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700343 }
344 return true;
345 }
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700346 if (preference == mInstallData) {
Jean-Michel Trivi2acc02e2009-06-25 10:03:43 -0700347 installVoiceData();
348 // quit this activity so it needs to be restarted after installation of the voice data
349 finish();
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700350 return true;
351 }
Jean-Michel Trivi74e565d2009-06-18 18:44:52 -0700352 return false;
353 }
354
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700355
356 private void updateWidgetState() {
357 mPlayExample.setEnabled(mEnableDemo);
358 mUseDefaultPref.setEnabled(mEnableDemo);
359 mDefaultRatePref.setEnabled(mEnableDemo);
Jean-Michel Trivi1e6a45a2009-06-22 16:03:40 -0700360 mDefaultLocPref.setEnabled(mEnableDemo);
361
362 mInstallData.setEnabled(!mEnableDemo);
363 }
364
365
366 private void parseLocaleInfo(String locale) {
367 StringTokenizer tokenizer = new StringTokenizer(locale, LOCALE_DELIMITER);
368 mDefaultLanguage = "";
369 mDefaultCountry = "";
370 mDefaultLocVariant = "";
371 if (tokenizer.hasMoreTokens()) {
372 mDefaultLanguage = tokenizer.nextToken().trim();
373 }
374 if (tokenizer.hasMoreTokens()) {
375 mDefaultCountry = tokenizer.nextToken().trim();
376 }
377 if (tokenizer.hasMoreTokens()) {
378 mDefaultLocVariant = tokenizer.nextToken().trim();
379 }
380 }
381
382
Jean-Michel Trivi44fbbea2009-07-06 14:04:54 -0700383 private void setDefaultLocalePref(String language, String country, String variant) {
384 // build a string from the default lang/country/variant trio,
385 String localeString = new String(language);
386 if (country.compareTo("") != 0) {
387 localeString += LOCALE_DELIMITER + country;
388 } else {
389 localeString += LOCALE_DELIMITER + " ";
390 }
391 if (variant.compareTo("") != 0) {
392 localeString += LOCALE_DELIMITER + variant;
393 }
394
395 if (mDefaultLocPref.findIndexOfValue(localeString) > -1) {
396 mDefaultLocPref.setValue(localeString);
397 } else {
398 mDefaultLocPref.setValueIndex(0);
399 }
400
401 Log.v(TAG, "In initDefaultSettings: localeString=" + localeString);
402 }
403
Jean-Michel Trivied29a652009-06-05 18:37:29 -0700404}