Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 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 | |
Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 19 | import android.preference.Preference; |
Mike LeBeau | 766a19b | 2010-02-11 22:57:12 -0800 | [diff] [blame] | 20 | import android.preference.PreferenceCategory; |
Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 21 | import android.preference.PreferenceGroup; |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 22 | import android.speech.tts.TtsEngines; |
Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 23 | |
Dianne Hackborn | ff795ff | 2014-07-18 19:20:11 -0700 | [diff] [blame] | 24 | import com.android.settings.voice.VoiceInputHelper; |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 25 | |
Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 26 | /** |
| 27 | * Settings screen for voice input/output. |
| 28 | */ |
Dianne Hackborn | ff795ff | 2014-07-18 19:20:11 -0700 | [diff] [blame] | 29 | public class VoiceInputOutputSettings { |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 30 | |
Mike LeBeau | 766a19b | 2010-02-11 22:57:12 -0800 | [diff] [blame] | 31 | private static final String TAG = "VoiceInputOutputSettings"; |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 32 | |
Jean Chalard | 8ba5c42 | 2011-08-31 21:40:43 +0900 | [diff] [blame] | 33 | private static final String KEY_VOICE_CATEGORY = "voice_category"; |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 34 | private static final String KEY_TTS_SETTINGS = "tts_settings"; |
| 35 | |
Mike LeBeau | 766a19b | 2010-02-11 22:57:12 -0800 | [diff] [blame] | 36 | private PreferenceGroup mParent; |
Jean Chalard | 8ba5c42 | 2011-08-31 21:40:43 +0900 | [diff] [blame] | 37 | private PreferenceCategory mVoiceCategory; |
Dianne Hackborn | ff795ff | 2014-07-18 19:20:11 -0700 | [diff] [blame] | 38 | private Preference mVoiceInputSettingsPref; |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 39 | private Preference mTtsSettingsPref; |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 40 | private final SettingsPreferenceFragment mFragment; |
| 41 | private final TtsEngines mTtsEngines; |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 42 | |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 43 | public VoiceInputOutputSettings(SettingsPreferenceFragment fragment) { |
| 44 | mFragment = fragment; |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 45 | mTtsEngines = new TtsEngines(fragment.getPreferenceScreen().getContext()); |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 46 | } |
Mike LeBeau | 766a19b | 2010-02-11 22:57:12 -0800 | [diff] [blame] | 47 | |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 48 | public void onCreate() { |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 49 | mParent = mFragment.getPreferenceScreen(); |
Jean Chalard | 8ba5c42 | 2011-08-31 21:40:43 +0900 | [diff] [blame] | 50 | mVoiceCategory = (PreferenceCategory) mParent.findPreference(KEY_VOICE_CATEGORY); |
Dianne Hackborn | df7e99b | 2014-04-17 18:35:29 -0700 | [diff] [blame] | 51 | mTtsSettingsPref = mVoiceCategory.findPreference(KEY_TTS_SETTINGS); |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 52 | |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 53 | populateOrRemovePreferences(); |
Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 54 | } |
Amith Yamasani | b44161f | 2010-12-10 13:17:34 -0800 | [diff] [blame] | 55 | |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 56 | private void populateOrRemovePreferences() { |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 57 | boolean hasTtsPrefs = populateOrRemoveTtsPrefs(); |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 58 | if (!hasTtsPrefs) { |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 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 | |
Narayan Kamath | e247cb8 | 2011-10-05 12:26:31 +0100 | [diff] [blame] | 66 | private boolean populateOrRemoveTtsPrefs() { |
| 67 | if (mTtsEngines.getEngines().isEmpty()) { |
| 68 | mVoiceCategory.removePreference(mTtsSettingsPref); |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | return true; |
Mike LeBeau | 766a19b | 2010-02-11 22:57:12 -0800 | [diff] [blame] | 73 | } |
Mike LeBeau | 92c3352 | 2010-01-25 18:18:45 -0500 | [diff] [blame] | 74 | } |