1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.view.View;
import com.android.settings.R;
/**
* BluetoothSettings is the Settings screen for Bluetooth configuration and
* connection management.
*/
public final class BluetoothSettings extends DeviceListPreferenceFragment {
private static final String TAG = "BluetoothSettings";
private static final String KEY_BT_CHECKBOX = "bt_checkbox";
private static final String KEY_BT_DISCOVERABLE = "bt_discoverable";
private static final String KEY_BT_DISCOVERABLE_TIMEOUT = "bt_discoverable_timeout";
private static final String KEY_BT_NAME = "bt_name";
private static final String KEY_BT_SHOW_RECEIVED = "bt_show_received_files";
private BluetoothEnabler mEnabler;
private BluetoothDiscoverableEnabler mDiscoverableEnabler;
private BluetoothNamePreference mNamePreference;
/* Private intent to show the list of received files */
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
/** Initialize the filter to show bonded devices only. */
public BluetoothSettings() {
super(BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
}
@Override
void addPreferencesForActivity() {
addPreferencesFromResource(R.xml.bluetooth_settings);
mEnabler = new BluetoothEnabler(getActivity(), mLocalAdapter,
(CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
mLocalAdapter,
(CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE),
(ListPreference) findPreference(KEY_BT_DISCOVERABLE_TIMEOUT));
mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME);
}
@Override
public void onResume() {
super.onResume();
// Repopulate (which isn't too bad since it's cached in the settings
// bluetooth manager)
addDevices();
mEnabler.resume();
mDiscoverableEnabler.resume();
mNamePreference.resume();
}
@Override
public void onPause() {
super.onPause();
mNamePreference.pause();
mDiscoverableEnabler.pause();
mEnabler.pause();
}
private final View.OnClickListener mListener = new View.OnClickListener() {
public void onClick(View v) {
// User clicked on advanced options icon for a device in the list
if (v.getTag() instanceof CachedBluetoothDevice) {
CachedBluetoothDevice
device = (CachedBluetoothDevice) v.getTag();
Preference pref = new Preference(getActivity());
pref.setTitle(device.getName());
pref.setFragment(DeviceProfilesSettings.class.getName());
pref.getExtras().putParcelable(DeviceProfilesSettings.EXTRA_DEVICE,
device.getDevice());
((PreferenceActivity) getActivity())
.onPreferenceStartFragment(BluetoothSettings.this,
pref);
} else {
Log.w(TAG, "onClick() called for other View: " + v);
}
}
};
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (KEY_BT_SHOW_RECEIVED.equals(preference.getKey())) {
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
getActivity().sendBroadcast(intent);
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice,
int bondState) {
if (bondState == BluetoothDevice.BOND_BONDED) {
// add to "Paired devices" list after remote-initiated pairing
if (mDevicePreferenceMap.get(cachedDevice) == null) {
createDevicePreference(cachedDevice);
}
} else if (bondState == BluetoothDevice.BOND_NONE) {
// remove unpaired device from paired devices list
onDeviceDeleted(cachedDevice);
}
}
/**
* Add a listener, which enables the advanced settings icon.
* @param preference the newly added preference
*/
@Override
void initDevicePreference(BluetoothDevicePreference preference) {
preference.setOnSettingsClickListener(mListener);
}
}
|