1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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;
}
}
|