diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-18 08:53:58 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-18 08:53:58 -0700 |
commit | e748161ca89867e8c57d4e71c780486d4de8039c (patch) | |
tree | 8cef1a3cab15bb2909934d62c3816cb3e1005ae2 | |
parent | 36c153f84f2728ffc67b7f30a1f326a7731c2088 (diff) | |
parent | 605a66bd56f01713f240ee8bc1435512500498e0 (diff) | |
download | frameworks_base-e748161ca89867e8c57d4e71c780486d4de8039c.zip frameworks_base-e748161ca89867e8c57d4e71c780486d4de8039c.tar.gz frameworks_base-e748161ca89867e8c57d4e71c780486d4de8039c.tar.bz2 |
Merge change 4529 into donut
* changes:
In the TTS service, read the default TTS settings from Settings.Secure.
-rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index f7dd0e8..b50add6 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -19,6 +19,7 @@ import android.speech.tts.ITts.Stub; import android.speech.tts.ITtsCallback; import android.app.Service; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -92,6 +93,10 @@ public class TtsService extends Service implements OnCompletionListener { private static final String CATEGORY = "android.intent.category.TTS"; private static final String PKGNAME = "android.tts"; + private static final int FALLBACK_TTS_DEFAULT_RATE = 100; // 1x + private static final int FALLBACK_TTS_DEFAULT_PITCH = 100;// 1x + private static final int FALLBACK_TTS_USE_DEFAULTS = 0; + final RemoteCallbackList<android.speech.tts.ITtsCallback> mCallbacks = new RemoteCallbackList<ITtsCallback>(); private Boolean mIsSpeaking; @@ -101,7 +106,7 @@ public class TtsService extends Service implements OnCompletionListener { private MediaPlayer mPlayer; private TtsService mSelf; - private SharedPreferences prefs; + private ContentResolver mResolver; private final ReentrantLock speechQueueLock = new ReentrantLock(); private final ReentrantLock synthesizerLock = new ReentrantLock(); @@ -113,9 +118,7 @@ public class TtsService extends Service implements OnCompletionListener { super.onCreate(); Log.i("TTS", "TTS starting"); - // TODO: Make this work when the settings are done in the main Settings - // app. - prefs = PreferenceManager.getDefaultSharedPreferences(this); + mResolver = getContentResolver(); String soLibPath = "/system/lib/libttspico.so"; nativeSynth = new SynthProxy(soLibPath); @@ -129,10 +132,7 @@ public class TtsService extends Service implements OnCompletionListener { mSpeechQueue = new ArrayList<SpeechItem>(); mPlayer = null; - // TODO set default settings - //setLanguage(prefs.getString("lang_pref", "en-rUS")); - setLanguage("eng", "USA", ""); - setSpeechRate(Integer.parseInt(prefs.getString("rate_pref", "140"))); + setDefaultSettings(); } @Override @@ -147,26 +147,48 @@ public class TtsService extends Service implements OnCompletionListener { mCallbacks.kill(); } + + private void setDefaultSettings() { + + // TODO handle default language + setLanguage("eng", "USA", ""); + + // speech rate + setSpeechRate(getDefaultRate()); + + // TODO handle default pitch + } + + + private boolean isDefaultEnforced() { + return (android.provider.Settings.Secure.getInt(mResolver, + android.provider.Settings.Secure.TTS_USE_DEFAULTS, FALLBACK_TTS_USE_DEFAULTS) + == 1 ); + } + + + private int getDefaultRate() { + return android.provider.Settings.Secure.getInt(mResolver, + android.provider.Settings.Secure.TTS_DEFAULT_RATE, FALLBACK_TTS_DEFAULT_RATE); + } + + private void setSpeechRate(int rate) { - if (prefs.getBoolean("override_pref", false)) { - // This is set to the default here so that the preview in the prefs - // activity will show the change without a restart, even if apps are - // not allowed to change the defaults. - rate = Integer.parseInt(prefs.getString("rate_pref", "140")); + if (isDefaultEnforced()) { + nativeSynth.setSpeechRate(getDefaultRate()); + } else { + nativeSynth.setSpeechRate(rate); } - nativeSynth.setSpeechRate(rate); } private void setLanguage(String lang, String country, String variant) { - if (prefs.getBoolean("override_pref", false)) { - // This is set to the default here so that the preview in the prefs - // activity will show the change without a restart, even if apps are - // not - // allowed to change the defaults. - lang = prefs.getString("lang_pref", "en-rUS"); - } Log.v("TTS", "TtsService.setLanguage("+lang+", "+country+", "+variant+")"); - nativeSynth.setLanguage(lang, country, variant); + if (isDefaultEnforced()) { + nativeSynth.setLanguage(lang, country, variant); + } else { + // TODO handle default language + nativeSynth.setLanguage("eng", "USA", ""); + } } /** |