• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.settings.connecteddevice;
17 
18 import android.app.settings.SettingsEnums;
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 import android.provider.SearchIndexableResource;
22 
23 import com.android.settings.R;
24 import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
25 import com.android.settings.dashboard.DashboardFragment;
26 import com.android.settings.nfc.AndroidBeamPreferenceController;
27 import com.android.settings.print.PrintSettingPreferenceController;
28 import com.android.settings.search.BaseSearchIndexProvider;
29 import com.android.settingslib.core.AbstractPreferenceController;
30 import com.android.settingslib.core.lifecycle.Lifecycle;
31 import com.android.settingslib.search.SearchIndexable;
32 
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 
37 /**
38  * This fragment contains all the advanced connection preferences(i.e, Bluetooth, NFC, USB..)
39  */
40 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
41 public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment {
42 
43     private static final String TAG = "AdvancedConnectedDeviceFrag";
44 
45     static final String KEY_BLUETOOTH = "bluetooth_settings";
46 
47     @Override
getMetricsCategory()48     public int getMetricsCategory() {
49         return SettingsEnums.CONNECTION_DEVICE_ADVANCED;
50     }
51 
52     @Override
getLogTag()53     protected String getLogTag() {
54         return TAG;
55     }
56 
57     @Override
getHelpResource()58     public int getHelpResource() {
59         return R.string.help_url_connected_devices;
60     }
61 
62     @Override
getPreferenceScreenResId()63     protected int getPreferenceScreenResId() {
64         return R.xml.connected_devices_advanced;
65     }
66 
67     @Override
createPreferenceControllers(Context context)68     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
69         return buildControllers(context, getSettingsLifecycle());
70     }
71 
buildControllers(Context context, Lifecycle lifecycle)72     private static List<AbstractPreferenceController> buildControllers(Context context,
73             Lifecycle lifecycle) {
74         final List<AbstractPreferenceController> controllers = new ArrayList<>();
75 
76         controllers.add(new BluetoothFilesPreferenceController(context));
77 
78         final PrintSettingPreferenceController printerController =
79                 new PrintSettingPreferenceController(context);
80 
81         if (lifecycle != null) {
82             lifecycle.addObserver(printerController);
83         }
84         controllers.add(printerController);
85 
86         return controllers;
87     }
88 
89     /**
90      * For Search.
91      */
92     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
93             new BaseSearchIndexProvider() {
94                 @Override
95                 public List<SearchIndexableResource> getXmlResourcesToIndex(
96                         Context context, boolean enabled) {
97                     final SearchIndexableResource sir = new SearchIndexableResource(context);
98                     sir.xmlResId = R.xml.connected_devices_advanced;
99                     return Arrays.asList(sir);
100                 }
101 
102                 @Override
103                 public List<String> getNonIndexableKeys(Context context) {
104                     final List<String> keys = super.getNonIndexableKeys(context);
105                     PackageManager pm = context.getPackageManager();
106                     if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
107                         keys.add(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
108                     }
109 
110                     return keys;
111                 }
112 
113                 @Override
114                 public List<AbstractPreferenceController> createPreferenceControllers(
115                         Context context) {
116                     return buildControllers(context, null /* lifecycle */);
117                 }
118             };
119 }
120