summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/TextToSpeechSettings.java
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2009-06-05 18:37:29 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2009-06-09 10:48:22 -0700
commited29a6583578a094350596246cb43c2876fd93b4 (patch)
tree4bd923c76c234baf4c8566f2c2c5618b0d774125 /src/com/android/settings/TextToSpeechSettings.java
parent0c1f89857a730f9f75312fce39ff65c2f01e7d22 (diff)
downloadpackages_apps_Settings-ed29a6583578a094350596246cb43c2876fd93b4.zip
packages_apps_Settings-ed29a6583578a094350596246cb43c2876fd93b4.tar.gz
packages_apps_Settings-ed29a6583578a094350596246cb43c2876fd93b4.tar.bz2
Adding Text-To-Speech default settings in the Settings application.
Diffstat (limited to 'src/com/android/settings/TextToSpeechSettings.java')
-rw-r--r--src/com/android/settings/TextToSpeechSettings.java122
1 files changed, 122 insertions, 0 deletions
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;
+ }
+
+}