blob: ab99aad73c1418891d5cfeeb93fe227680b4aefc [file] [log] [blame]
jackqdyulei1b853c52017-05-10 14:57:16 -07001/*
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
17package com.android.settings.bluetooth;
18
jackqdyulei1b853c52017-05-10 14:57:16 -070019import android.content.Context;
20import android.support.v14.preference.PreferenceFragment;
21import android.support.v7.preference.Preference;
jackqdyulei52ccb492017-05-10 14:57:16 -070022import android.os.UserHandle;
jackqdyulei1b853c52017-05-10 14:57:16 -070023
jackqdyulei52ccb492017-05-10 14:57:16 -070024import com.android.settings.SettingsActivity;
jackqdyulei1b853c52017-05-10 14:57:16 -070025import com.android.settings.core.PreferenceController;
26import com.android.settings.R;
27
28
29/**
30 * Controller that shows and updates the bluetooth device name
31 */
32public class BluetoothPairingPreferenceController extends PreferenceController {
33 private static final String TAG = "BluetoothPairingPrefCtrl";
34
35 public static final String KEY_PAIRING = "pref_bt_pairing";
36 private PreferenceFragment mFragment;
jackqdyulei52ccb492017-05-10 14:57:16 -070037 private SettingsActivity mActivity;
jackqdyulei1b853c52017-05-10 14:57:16 -070038 private Preference mPreference;
39
jackqdyulei52ccb492017-05-10 14:57:16 -070040 public BluetoothPairingPreferenceController(Context context, PreferenceFragment fragment,
41 SettingsActivity activity) {
42 super(context);
jackqdyulei1b853c52017-05-10 14:57:16 -070043 mFragment = fragment;
jackqdyulei52ccb492017-05-10 14:57:16 -070044 mActivity = activity;
jackqdyulei1b853c52017-05-10 14:57:16 -070045 }
46
47 @Override
48 public boolean isAvailable() {
49 return true;
50 }
51
52 @Override
53 public String getPreferenceKey() {
54 return KEY_PAIRING;
55 }
56
57 @Override
58 public boolean handlePreferenceTreeClick(Preference preference) {
59 if (KEY_PAIRING.equals(preference.getKey())) {
jackqdyulei52ccb492017-05-10 14:57:16 -070060 mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(),
61 null, R.string.bluetooth_pairing_page_title, null,
62 new UserHandle(UserHandle.myUserId()));
jackqdyulei1b853c52017-05-10 14:57:16 -070063 return true;
64 }
65
66 return false;
67 }
68
69 /**
70 * Create pairing preference to jump to pairing page
71 *
72 * @return bluetooth preference that created in this method
73 */
jackqdyulei52ccb492017-05-10 14:57:16 -070074 public Preference createBluetoothPairingPreference(int order) {
jackqdyulei1b853c52017-05-10 14:57:16 -070075 mPreference = new Preference(mFragment.getPreferenceScreen().getContext());
76 mPreference.setKey(KEY_PAIRING);
77 mPreference.setIcon(R.drawable.ic_add);
jackqdyulei52ccb492017-05-10 14:57:16 -070078 mPreference.setOrder(order);
jackqdyulei1b853c52017-05-10 14:57:16 -070079 mPreference.setTitle(R.string.bluetooth_pairing_pref_title);
80
81 return mPreference;
82 }
83
84}