| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 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 | |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.support.v14.preference.PreferenceFragment; |
| 21 | import android.support.v7.preference.Preference; |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 22 | import android.os.UserHandle; |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 23 | |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 24 | import com.android.settings.SettingsActivity; |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 25 | import com.android.settings.core.PreferenceController; |
| 26 | import com.android.settings.R; |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * Controller that shows and updates the bluetooth device name |
| 31 | */ |
| 32 | public 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; |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 37 | private SettingsActivity mActivity; |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 38 | private Preference mPreference; |
| 39 | |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 40 | public BluetoothPairingPreferenceController(Context context, PreferenceFragment fragment, |
| 41 | SettingsActivity activity) { |
| 42 | super(context); |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 43 | mFragment = fragment; |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 44 | mActivity = activity; |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 45 | } |
| 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())) { |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 60 | mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(), |
| 61 | null, R.string.bluetooth_pairing_page_title, null, |
| 62 | new UserHandle(UserHandle.myUserId())); |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 63 | 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 | */ |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 74 | public Preference createBluetoothPairingPreference(int order) { |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 75 | mPreference = new Preference(mFragment.getPreferenceScreen().getContext()); |
| 76 | mPreference.setKey(KEY_PAIRING); |
| 77 | mPreference.setIcon(R.drawable.ic_add); |
| jackqdyulei | 52ccb49 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 78 | mPreference.setOrder(order); |
| jackqdyulei | 1b853c5 | 2017-05-10 14:57:16 -0700 | [diff] [blame] | 79 | mPreference.setTitle(R.string.bluetooth_pairing_pref_title); |
| 80 | |
| 81 | return mPreference; |
| 82 | } |
| 83 | |
| 84 | } |