ConnectedDeviceDashboardFragment.java revision 762b4969d9c5efaed9241d66abc4417419ddd0e5
1/*
2 * Copyright (C) 2016 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 */
16package com.android.settings.connecteddevice;
17
18import android.content.Context;
19import android.provider.SearchIndexableResource;
20
21import com.android.settings.R;
22import com.android.settings.core.PreferenceController;
23import com.android.settings.dashboard.DashboardFragment;
24import com.android.settings.deviceinfo.UsbBackend;
25import com.android.settings.nfc.NfcPreferenceController;
26import com.android.settings.overlay.FeatureFactory;
27import com.android.settings.search.BaseSearchIndexProvider;
28import com.android.settings.search.Indexable;
29import com.android.settingslib.drawer.CategoryKey;
30
31import java.util.ArrayList;
32import java.util.Arrays;
33import java.util.List;
34
35public class ConnectedDeviceDashboardFragment extends DashboardFragment {
36
37    private static final String TAG = "ConnectedDeviceFrag";
38    private UsbModePreferenceController mUsbPrefController;
39
40    @Override
41    public int getMetricsCategory() {
42        return CONNECTED_DEVICE_CATEGORY_FRAGMENT;
43    }
44
45    @Override
46    protected String getCategoryKey() {
47        return CategoryKey.CATEGORY_DEVICE;
48    }
49
50    @Override
51    protected String getLogTag() {
52        return TAG;
53    }
54
55    @Override
56    protected int getPreferenceScreenResId() {
57        return R.xml.connected_devices;
58    }
59
60    @Override
61    protected List<PreferenceController> getPreferenceControllers(Context context) {
62        final List<PreferenceController> controllers = new ArrayList<>();
63        final NfcPreferenceController nfcPreferenceController =
64                new NfcPreferenceController(context);
65        getLifecycle().addObserver(nfcPreferenceController);
66        controllers.add(nfcPreferenceController);
67        mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context));
68        getLifecycle().addObserver(mUsbPrefController);
69        controllers.add(mUsbPrefController);
70        return controllers;
71    }
72
73    /**
74     * For Search.
75     */
76    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
77            new BaseSearchIndexProvider() {
78                @Override
79                public List<SearchIndexableResource> getXmlResourcesToIndex(
80                        Context context, boolean enabled) {
81                    if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
82                            .isEnabled()) {
83                        return null;
84                    }
85                    final SearchIndexableResource sir = new SearchIndexableResource(context);
86                    sir.xmlResId = R.xml.connected_devices;
87                    return Arrays.asList(sir);
88                }
89            };
90}