• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 
17 package com.android.settings;
18 
19 import android.preference.Preference;
20 import android.preference.PreferenceCategory;
21 import android.preference.PreferenceGroup;
22 import android.speech.tts.TtsEngines;
23 
24 import com.android.settings.voice.VoiceInputHelper;
25 
26 /**
27  * Settings screen for voice input/output.
28  */
29 public class VoiceInputOutputSettings {
30 
31     private static final String TAG = "VoiceInputOutputSettings";
32 
33     private static final String KEY_VOICE_CATEGORY = "voice_category";
34     private static final String KEY_TTS_SETTINGS = "tts_settings";
35 
36     private PreferenceGroup mParent;
37     private PreferenceCategory mVoiceCategory;
38     private Preference mVoiceInputSettingsPref;
39     private Preference mTtsSettingsPref;
40     private final SettingsPreferenceFragment mFragment;
41     private final TtsEngines mTtsEngines;
42 
VoiceInputOutputSettings(SettingsPreferenceFragment fragment)43     public VoiceInputOutputSettings(SettingsPreferenceFragment fragment) {
44         mFragment = fragment;
45         mTtsEngines = new TtsEngines(fragment.getPreferenceScreen().getContext());
46     }
47 
onCreate()48     public void onCreate() {
49         mParent = mFragment.getPreferenceScreen();
50         mVoiceCategory = (PreferenceCategory) mParent.findPreference(KEY_VOICE_CATEGORY);
51         mTtsSettingsPref = mVoiceCategory.findPreference(KEY_TTS_SETTINGS);
52 
53         populateOrRemovePreferences();
54     }
55 
populateOrRemovePreferences()56     private void populateOrRemovePreferences() {
57         boolean hasTtsPrefs = populateOrRemoveTtsPrefs();
58         if (!hasTtsPrefs) {
59             // There were no TTS settings and no recognizer settings,
60             // so it should be safe to hide the preference category
61             // entirely.
62             mFragment.getPreferenceScreen().removePreference(mVoiceCategory);
63         }
64     }
65 
populateOrRemoveTtsPrefs()66     private boolean populateOrRemoveTtsPrefs() {
67         if (mTtsEngines.getEngines().isEmpty()) {
68             mVoiceCategory.removePreference(mTtsSettingsPref);
69             return false;
70         }
71 
72         return true;
73     }
74 }
75