blob: a264d5018e01a7680a1b20822434735ae5b39329 [file] [log] [blame]
Mike LeBeau92c33522010-01-25 18:18:45 -05001/*
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
17package com.android.settings;
18
Mike LeBeau92c33522010-01-25 18:18:45 -050019import android.preference.Preference;
Mike LeBeau766a19b2010-02-11 22:57:12 -080020import android.preference.PreferenceCategory;
Mike LeBeau92c33522010-01-25 18:18:45 -050021import android.preference.PreferenceGroup;
Narayan Kamathe247cb82011-10-05 12:26:31 +010022import android.speech.tts.TtsEngines;
Mike LeBeau92c33522010-01-25 18:18:45 -050023
Dianne Hackbornff795ff2014-07-18 19:20:11 -070024import com.android.settings.voice.VoiceInputHelper;
Amith Yamasanib44161f2010-12-10 13:17:34 -080025
Mike LeBeau92c33522010-01-25 18:18:45 -050026/**
27 * Settings screen for voice input/output.
28 */
Dianne Hackbornff795ff2014-07-18 19:20:11 -070029public class VoiceInputOutputSettings {
Amith Yamasanib44161f2010-12-10 13:17:34 -080030
Mike LeBeau766a19b2010-02-11 22:57:12 -080031 private static final String TAG = "VoiceInputOutputSettings";
Amith Yamasanib44161f2010-12-10 13:17:34 -080032
Jean Chalard8ba5c422011-08-31 21:40:43 +090033 private static final String KEY_VOICE_CATEGORY = "voice_category";
Narayan Kamathe247cb82011-10-05 12:26:31 +010034 private static final String KEY_TTS_SETTINGS = "tts_settings";
35
Mike LeBeau766a19b2010-02-11 22:57:12 -080036 private PreferenceGroup mParent;
Jean Chalard8ba5c422011-08-31 21:40:43 +090037 private PreferenceCategory mVoiceCategory;
Dianne Hackbornff795ff2014-07-18 19:20:11 -070038 private Preference mVoiceInputSettingsPref;
Narayan Kamathe247cb82011-10-05 12:26:31 +010039 private Preference mTtsSettingsPref;
Narayan Kamathe247cb82011-10-05 12:26:31 +010040 private final SettingsPreferenceFragment mFragment;
41 private final TtsEngines mTtsEngines;
Amith Yamasanib44161f2010-12-10 13:17:34 -080042
Amith Yamasanib44161f2010-12-10 13:17:34 -080043 public VoiceInputOutputSettings(SettingsPreferenceFragment fragment) {
44 mFragment = fragment;
Narayan Kamathe247cb82011-10-05 12:26:31 +010045 mTtsEngines = new TtsEngines(fragment.getPreferenceScreen().getContext());
Amith Yamasanib44161f2010-12-10 13:17:34 -080046 }
Mike LeBeau766a19b2010-02-11 22:57:12 -080047
Amith Yamasanib44161f2010-12-10 13:17:34 -080048 public void onCreate() {
Narayan Kamathe247cb82011-10-05 12:26:31 +010049 mParent = mFragment.getPreferenceScreen();
Jean Chalard8ba5c422011-08-31 21:40:43 +090050 mVoiceCategory = (PreferenceCategory) mParent.findPreference(KEY_VOICE_CATEGORY);
Dianne Hackborndf7e99b2014-04-17 18:35:29 -070051 mTtsSettingsPref = mVoiceCategory.findPreference(KEY_TTS_SETTINGS);
Amith Yamasanib44161f2010-12-10 13:17:34 -080052
Narayan Kamathe247cb82011-10-05 12:26:31 +010053 populateOrRemovePreferences();
Mike LeBeau92c33522010-01-25 18:18:45 -050054 }
Amith Yamasanib44161f2010-12-10 13:17:34 -080055
Narayan Kamathe247cb82011-10-05 12:26:31 +010056 private void populateOrRemovePreferences() {
Narayan Kamathe247cb82011-10-05 12:26:31 +010057 boolean hasTtsPrefs = populateOrRemoveTtsPrefs();
Xiyuan Xia86a55402015-06-02 14:55:32 -070058 if (!hasTtsPrefs) {
Narayan Kamathe247cb82011-10-05 12:26:31 +010059 // 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
Narayan Kamathe247cb82011-10-05 12:26:31 +010066 private boolean populateOrRemoveTtsPrefs() {
67 if (mTtsEngines.getEngines().isEmpty()) {
68 mVoiceCategory.removePreference(mTtsSettingsPref);
69 return false;
70 }
71
72 return true;
Mike LeBeau766a19b2010-02-11 22:57:12 -080073 }
Mike LeBeau92c33522010-01-25 18:18:45 -050074}