1 /*
2  * Copyright (C) 2018 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.os.Bundle;
21 
22 import com.android.settings.R;
23 import com.android.settings.SettingsActivity;
24 import com.android.settings.bluetooth.BluetoothDeviceRenamePreferenceController;
25 import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settings.widget.SwitchBar;
29 import com.android.settings.widget.SwitchBarController;
30 import com.android.settingslib.core.lifecycle.Lifecycle;
31 import com.android.settingslib.search.SearchIndexable;
32 import com.android.settingslib.widget.FooterPreference;
33 
34 /**
35  * Dedicated screen for allowing the user to toggle bluetooth which displays relevant information to
36  * the user based on related settings such as bluetooth scanning.
37  */
38 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
39 public class BluetoothDashboardFragment extends DashboardFragment {
40 
41     private static final String TAG = "BluetoothDashboardFrag";
42     private static final String KEY_BLUETOOTH_SCREEN_FOOTER = "bluetooth_screen_footer";
43 
44     private FooterPreference mFooterPreference;
45     private SwitchBar mSwitchBar;
46     private BluetoothSwitchPreferenceController mController;
47 
48     @Override
getMetricsCategory()49     public int getMetricsCategory() {
50         return SettingsEnums.BLUETOOTH_FRAGMENT;
51     }
52 
53     @Override
getLogTag()54     protected String getLogTag() {
55         return TAG;
56     }
57 
58     @Override
getHelpResource()59     public int getHelpResource() {
60         return R.string.help_uri_bluetooth_screen;
61     }
62 
63     @Override
getPreferenceScreenResId()64     protected int getPreferenceScreenResId() {
65         return R.xml.bluetooth_screen;
66     }
67 
68     @Override
onCreate(Bundle icicle)69     public void onCreate(Bundle icicle) {
70         super.onCreate(icicle);
71         mFooterPreference = findPreference(KEY_BLUETOOTH_SCREEN_FOOTER);
72     }
73 
74     @Override
onAttach(Context context)75     public void onAttach(Context context) {
76         super.onAttach(context);
77         use(BluetoothDeviceRenamePreferenceController.class).setFragment(this);
78     }
79 
80     @Override
onActivityCreated(Bundle savedInstanceState)81     public void onActivityCreated(Bundle savedInstanceState) {
82         super.onActivityCreated(savedInstanceState);
83 
84         SettingsActivity activity = (SettingsActivity) getActivity();
85         mSwitchBar = activity.getSwitchBar();
86         mController = new BluetoothSwitchPreferenceController(activity,
87                 new SwitchBarController(mSwitchBar), mFooterPreference);
88         Lifecycle lifecycle = getSettingsLifecycle();
89         if (lifecycle != null) {
90             lifecycle.addObserver(mController);
91         }
92     }
93     /**
94      * For Search.
95      */
96     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
97             new BaseSearchIndexProvider(R.xml.bluetooth_screen);
98 }
99