blob: 3a8f1a52e1ce819f8c8f81250dc4375daf3c785e [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
Narayan Kamathe247cb82011-10-05 12:26:31 +010019import android.speech.tts.TtsEngines;
Jason Monk39b46742015-09-10 15:52:51 -040020import android.support.v7.preference.Preference;
21import android.support.v7.preference.PreferenceCategory;
22import android.support.v7.preference.PreferenceGroup;
Amith Yamasanib44161f2010-12-10 13:17:34 -080023
Mike LeBeau92c33522010-01-25 18:18:45 -050024/**
25 * Settings screen for voice input/output.
26 */
Dianne Hackbornff795ff2014-07-18 19:20:11 -070027public class VoiceInputOutputSettings {
Amith Yamasanib44161f2010-12-10 13:17:34 -080028
Mike LeBeau766a19b2010-02-11 22:57:12 -080029 private static final String TAG = "VoiceInputOutputSettings";
Amith Yamasanib44161f2010-12-10 13:17:34 -080030
Jean Chalard8ba5c422011-08-31 21:40:43 +090031 private static final String KEY_VOICE_CATEGORY = "voice_category";
Narayan Kamathe247cb82011-10-05 12:26:31 +010032 private static final String KEY_TTS_SETTINGS = "tts_settings";
33
Mike LeBeau766a19b2010-02-11 22:57:12 -080034 private PreferenceGroup mParent;
Jean Chalard8ba5c422011-08-31 21:40:43 +090035 private PreferenceCategory mVoiceCategory;
Dianne Hackbornff795ff2014-07-18 19:20:11 -070036 private Preference mVoiceInputSettingsPref;
Narayan Kamathe247cb82011-10-05 12:26:31 +010037 private Preference mTtsSettingsPref;
Narayan Kamathe247cb82011-10-05 12:26:31 +010038 private final SettingsPreferenceFragment mFragment;
39 private final TtsEngines mTtsEngines;
Amith Yamasanib44161f2010-12-10 13:17:34 -080040
Amith Yamasanib44161f2010-12-10 13:17:34 -080041 public VoiceInputOutputSettings(SettingsPreferenceFragment fragment) {
42 mFragment = fragment;
Narayan Kamathe247cb82011-10-05 12:26:31 +010043 mTtsEngines = new TtsEngines(fragment.getPreferenceScreen().getContext());
Amith Yamasanib44161f2010-12-10 13:17:34 -080044 }
Mike LeBeau766a19b2010-02-11 22:57:12 -080045
Amith Yamasanib44161f2010-12-10 13:17:34 -080046 public void onCreate() {
Narayan Kamathe247cb82011-10-05 12:26:31 +010047 mParent = mFragment.getPreferenceScreen();
Jean Chalard8ba5c422011-08-31 21:40:43 +090048 mVoiceCategory = (PreferenceCategory) mParent.findPreference(KEY_VOICE_CATEGORY);
Dianne Hackborndf7e99b2014-04-17 18:35:29 -070049 mTtsSettingsPref = mVoiceCategory.findPreference(KEY_TTS_SETTINGS);
Amith Yamasanib44161f2010-12-10 13:17:34 -080050
Narayan Kamathe247cb82011-10-05 12:26:31 +010051 populateOrRemovePreferences();
Mike LeBeau92c33522010-01-25 18:18:45 -050052 }
Amith Yamasanib44161f2010-12-10 13:17:34 -080053
Narayan Kamathe247cb82011-10-05 12:26:31 +010054 private void populateOrRemovePreferences() {
Narayan Kamathe247cb82011-10-05 12:26:31 +010055 boolean hasTtsPrefs = populateOrRemoveTtsPrefs();
Xiyuan Xia86a55402015-06-02 14:55:32 -070056 if (!hasTtsPrefs) {
Narayan Kamathe247cb82011-10-05 12:26:31 +010057 // There were no TTS settings and no recognizer settings,
58 // so it should be safe to hide the preference category
59 // entirely.
60 mFragment.getPreferenceScreen().removePreference(mVoiceCategory);
61 }
62 }
63
Narayan Kamathe247cb82011-10-05 12:26:31 +010064 private boolean populateOrRemoveTtsPrefs() {
65 if (mTtsEngines.getEngines().isEmpty()) {
66 mVoiceCategory.removePreference(mTtsSettingsPref);
67 return false;
68 }
69
70 return true;
Mike LeBeau766a19b2010-02-11 22:57:12 -080071 }
Mike LeBeau92c33522010-01-25 18:18:45 -050072}