• 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 
17 package com.android.settings.bluetooth;
18 
19 import android.content.Context;
20 
21 import androidx.preference.Preference;
22 
23 import com.android.settings.R;
24 import com.android.settings.core.PreferenceControllerMixin;
25 import com.android.settings.core.SubSettingLauncher;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 
29 
30 /**
31  * Controller that shows and updates the bluetooth device name
32  */
33 public class BluetoothPairingPreferenceController extends AbstractPreferenceController
34         implements PreferenceControllerMixin {
35     private static final String TAG = "BluetoothPairingPrefCtrl";
36 
37     public static final String KEY_PAIRING = "pref_bt_pairing";
38     private DashboardFragment mFragment;
39     private Preference mPreference;
40 
BluetoothPairingPreferenceController(Context context, DashboardFragment fragment)41     public BluetoothPairingPreferenceController(Context context, DashboardFragment fragment) {
42         super(context);
43         mFragment = fragment;
44     }
45 
46     @Override
isAvailable()47     public boolean isAvailable() {
48         return true;
49     }
50 
51     @Override
getPreferenceKey()52     public String getPreferenceKey() {
53         return KEY_PAIRING;
54     }
55 
56     @Override
handlePreferenceTreeClick(Preference preference)57     public boolean handlePreferenceTreeClick(Preference preference) {
58         if (KEY_PAIRING.equals(preference.getKey())) {
59             new SubSettingLauncher(mContext)
60                     .setDestination(BluetoothPairingDetail.class.getName())
61                     .setTitleRes(R.string.bluetooth_pairing_page_title)
62                     .setSourceMetricsCategory(mFragment.getMetricsCategory())
63                     .launch();
64 
65             return true;
66         }
67 
68         return false;
69     }
70 
71     /**
72      * Create pairing preference to jump to pairing page
73      *
74      * @return bluetooth preference that created in this method
75      */
createBluetoothPairingPreference(int order)76     public Preference createBluetoothPairingPreference(int order) {
77         mPreference = new Preference(mFragment.getPreferenceScreen().getContext());
78         mPreference.setKey(KEY_PAIRING);
79         mPreference.setIcon(R.drawable.ic_add_24dp);
80         mPreference.setOrder(order);
81         mPreference.setTitle(R.string.bluetooth_pairing_pref_title);
82 
83         return mPreference;
84     }
85 
86 }
87