diff options
-rw-r--r-- | AndroidManifest.xml | 7 | ||||
-rw-r--r-- | res/values/arrays.xml | 36 | ||||
-rw-r--r-- | res/values/strings.xml | 24 | ||||
-rw-r--r-- | res/xml/settings.xml | 11 | ||||
-rw-r--r-- | res/xml/tts_settings.xml | 48 | ||||
-rw-r--r-- | src/com/android/settings/TextToSpeechSettings.java | 122 |
6 files changed, 248 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 150e27d..f9758f3 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -259,6 +259,13 @@ </intent-filter> </activity> + <activity android:name="TextToSpeechSettings" android:label="@string/tts_settings"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <action android:name="com.android.settings.TTS_SETTINGS" /> + </intent-filter> + </activity> + <!-- Second and third-level settings --> <activity android:name="ConfirmLockPattern"/> diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 72f56e7..1c480a8 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -81,6 +81,42 @@ <item>-1</item> </string-array> + <!-- TTS settings --> + + <!-- Default speech rate choices --> + <string-array name="tts_rate_entries"> + <item>Very slow</item> + <item>Slow</item> + <item>Normal</item> + <item>Fast</item> + <item>Very fast</item> + </string-array> + <!-- Do not translate. --> + <string-array name="tts_rate_values"> + <item>60</item> + <item>100</item> + <item>140</item> + <item>180</item> + <item>220</item> + </string-array> + + <!-- Default pitch choices --> + <string-array name="tts_pitch_entries"> + <item>Very low</item> + <item>Low</item> + <item>Normal</item> + <item>High</item> + <item>Very high</item> + </string-array> + <!-- Do not translate. --> + <string-array name="tts_pitch_values"> + <item>50</item> + <item>80</item> + <item>100</item> + <item>120</item> + <item>150</item> + </string-array> + <!-- Wi-Fi settings --> <!-- Match this with code. --> <skip /> diff --git a/res/values/strings.xml b/res/values/strings.xml index 07bfe2f..9119edc 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1673,6 +1673,30 @@ found in the list of installed applications.</string> <string name="menu_stats_total">Usage totals</string> <!-- Menu label for refreshing with latest usage numbers --> <string name="menu_stats_refresh">Refresh</string> + + <!-- Text-To-Speech (TTS) settings --><skip /> + <!-- Title of setting on main settings screen. This item will take the user to the screen to tweak settings related to the text-to-speech functionality --> + <string name="tts_settings">Speech synthesis</string> + <!-- Summary of setting on main settings screen. This item will take the user to the screen to tweak settings related to the text-to-speech functionality --> + <string name="tts_settings_summary">Set text-to-speech options</string> + <!-- Main TTS Settings screen title --> + <string name="tts_settings_title">Speech synthesizer controls</string> + <!-- On main TTS Settings screen, title for toggle used to force use of default TTS settings --> + <string name="use_default_tts_settings_title">Always use my settings</string> + <!-- On main TTS Settings screen, summary for toggle used to force use of default TTS settings --> + <string name="use_default_tts_settings_summary">Default settings below override application settings</string> + <!-- On main TTS Settings screen, section header for default TTS settings --> + <string name="tts_default_settings_section">Default settings</string> + <!-- On main TTS Settings screen, in default settings section, setting default speech rate for synthesized voice --> + <string name="tts_default_rate_title">Speech rate</string> + <!-- On main TTS Settings screen, summary for default speech rate for synthesized voice --> + <string name="tts_default_rate_summary">Speed at which the text is spoken</string> + <!-- On main TTS Settings screen, in default settings section, setting default pitch for synthesized voice --> + <string name="tts_default_pitch_title">Pitch</string> + <!-- On main TTS Settings screen, summary for default pitch for synthesized voice --> + <string name="tts_default_pitch_summary">Affects the tone of the spoken text</string> + <!-- On main TTS Settings screen, section header for list of available speech synthesizers --> + <string name="tts_available_synths_section">Available speech synthesizers</string> <!-- Power Control Widget --> <string name="gadget_title">Power Control</string> diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 10712eb..9ca581a 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -141,6 +141,17 @@ android:targetClass="com.android.settings.AccessibilitySettings" /> </PreferenceScreen> + <!-- Text-To-Speech --> + + <PreferenceScreen + android:title="@string/tts_settings" + android:summary="@string/tts_settings_summary"> + <intent + android:action="android.intent.action.MAIN" + android:targetPackage="com.android.settings" + android:targetClass="com.android.settings.TextToSpeechSettings" /> + </PreferenceScreen> + <!-- About Device --> <PreferenceScreen diff --git a/res/xml/tts_settings.xml b/res/xml/tts_settings.xml new file mode 100644 index 0000000..413e1cc --- /dev/null +++ b/res/xml/tts_settings.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2009 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + android:title="@string/tts_settings_title"> + + <CheckBoxPreference + android:key="toggle_use_default_tts_settings" + android:title="@string/use_default_tts_settings_title" + android:summary="@string/use_default_tts_settings_summary" + android:persistent="false" /> + + <PreferenceCategory + android:title="@string/tts_default_settings_section"> + + <ListPreference + android:key="tts_default_rate" + android:title="@string/tts_default_rate_title" + android:summary="@string/tts_default_rate_summary" + android:persistent="false" + android:entries="@array/tts_rate_entries" + android:entryValues="@array/tts_rate_values" /> + + <ListPreference + android:key="tts_default_pitch" + android:title="@string/tts_default_pitch_title" + android:summary="@string/tts_default_pitch_summary" + android:persistent="false" + android:entries="@array/tts_pitch_entries" + android:entryValues="@array/tts_pitch_values" /> + + </PreferenceCategory> + + +</PreferenceScreen> diff --git a/src/com/android/settings/TextToSpeechSettings.java b/src/com/android/settings/TextToSpeechSettings.java new file mode 100644 index 0000000..02fc06d --- /dev/null +++ b/src/com/android/settings/TextToSpeechSettings.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings; + +import static android.provider.Settings.Secure.TTS_USE_DEFAULTS; +import static android.provider.Settings.Secure.TTS_DEFAULT_RATE; +import static android.provider.Settings.Secure.TTS_DEFAULT_PITCH; + +import android.content.ContentResolver; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.CheckBoxPreference; +import android.provider.Settings; +import android.util.Log; + +public class TextToSpeechSettings extends PreferenceActivity implements + Preference.OnPreferenceChangeListener { + + private static final String TAG = "TextToSpeechSettings"; + + /** If there is no setting in the provider, use this. */ + 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 = 1; + + private static final String KEY_TTS_USE_DEFAULT = + "toggle_use_default_tts_settings"; + private static final String KEY_TTS_DEFAULT_RATE = "tts_default_rate"; + private static final String KEY_TTS_DEFAULT_PITCH = "tts_default_pitch"; + + private CheckBoxPreference mUseDefaultPref = null; + private ListPreference mDefaultRatePref = null; + private ListPreference mDefaultPitchPref = null; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.tts_settings); + + initDefaultSettings(); + } + + + private void initDefaultSettings() { + ContentResolver resolver = getContentResolver(); + + // "Use Defaults" + mUseDefaultPref = + (CheckBoxPreference) findPreference(KEY_TTS_USE_DEFAULT); + mUseDefaultPref.setChecked(Settings.System.getInt(resolver, + TTS_USE_DEFAULTS, + FALLBACK_TTS_USE_DEFAULTS) == 1 ? true : false); + mUseDefaultPref.setOnPreferenceChangeListener(this); + + // Default rate + mDefaultRatePref = + (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE); + mDefaultRatePref.setValue(String.valueOf(Settings.System.getInt( + resolver, TTS_DEFAULT_RATE, FALLBACK_TTS_DEFAULT_RATE))); + mDefaultRatePref.setOnPreferenceChangeListener(this); + + // Default pitch + mDefaultPitchPref = + (ListPreference) findPreference(KEY_TTS_DEFAULT_PITCH); + mDefaultPitchPref.setValue(String.valueOf(Settings.System.getInt( + resolver, TTS_DEFAULT_PITCH, FALLBACK_TTS_DEFAULT_PITCH))); + mDefaultPitchPref.setOnPreferenceChangeListener(this); + + } + + + public boolean onPreferenceChange(Preference preference, Object objValue) { + if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) { + // "Use Defaults" + int value = (Boolean)objValue ? 1 : 0; + Settings.System.putInt(getContentResolver(), TTS_USE_DEFAULTS, + value); + Log.i(TAG, "TTS use default settings is "+objValue.toString()); + } else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) { + // Default rate + int value = Integer.parseInt((String) objValue); + try { + Settings.System.putInt(getContentResolver(), + TTS_DEFAULT_RATE, value); + Log.i(TAG, "TTS default rate is "+value); + } catch (NumberFormatException e) { + Log.e(TAG, "could not persist default TTS rate setting", e); + } + } else if (KEY_TTS_DEFAULT_PITCH.equals(preference.getKey())) { + // Default pitch + int value = Integer.parseInt((String) objValue); + try { + Settings.System.putInt(getContentResolver(), + TTS_DEFAULT_PITCH, value); + Log.i(TAG, "TTS default pitch is "+value); + } catch (NumberFormatException e) { + Log.e(TAG, "could not persist default TTS pitch setting", e); + } + } + + return true; + } + +} |