blob: 7586bd06e87ae6e5093c3941acf753dbdc26d6bf [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
19import android.content.Context;
20import android.content.Intent;
21import android.content.pm.PackageManager;
22import android.os.Bundle;
23import android.preference.Preference;
24import android.preference.PreferenceActivity;
25import android.preference.PreferenceGroup;
26
27import java.util.List;
28
29/**
30 * Settings screen for voice input/output.
31 */
32public class VoiceInputOutputSettings extends PreferenceActivity {
33
34 private static final String KEY_PARENT = "parent";
35 private static final String KEY_VOICE_SEARCH_SETTINGS = "voice_search_settings";
36 private static final String KEY_KEYBOARD_SETTINGS = "keyboard_settings";
37
38 @Override
39 protected void onCreate(Bundle icicle) {
40 super.onCreate(icicle);
41
42 addPreferencesFromResource(R.xml.voice_input_output_settings);
43
44 removePreferenceIfNecessary(KEY_VOICE_SEARCH_SETTINGS);
45 removePreferenceIfNecessary(KEY_KEYBOARD_SETTINGS);
46 }
47
48 /**
49 * Removes a preference if there is no activity to handle its intent.
50 */
51 private void removePreferenceIfNecessary(String preferenceKey) {
52 PreferenceGroup parent = (PreferenceGroup) findPreference(KEY_PARENT);
53
54 Preference preference = parent.findPreference(preferenceKey);
55 if (preference == null) {
56 return;
57 }
58
59 Intent intent = preference.getIntent();
60 if (intent != null) {
61 PackageManager pm = getPackageManager();
62 if (!pm.queryIntentActivities(intent, 0).isEmpty()) {
63 return;
64 }
65 }
66
67 // Did not find a matching activity, so remove the preference.
68 parent.removePreference(preference);
69 }
70}