BluetoothSettings
设置 选项中 蓝牙开关的按钮。在settings代码中。
代码路径(packages\apps\Settings\src\com\android\settings\bluetooth\)
BluetoothSettings
//android8.0\packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothSettings.java
public final class BluetoothSettings extends DeviceListPreferenceFragment implements Indexable {
...
}
这个类,是蓝牙设置中的主界面。
我们通过这个类来完善对settings中蓝牙相关代码以及类的认识。
蓝牙开关
我们分析一下蓝牙开关按钮都做了什么操作。
//android8.0\packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothSettings.java
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
/* Don't auto start scan if screen reconstructs due to frozen screen*/
mInitialScanStarted = (savedInstanceState != null);
mInitiateDiscoverable = true;
final SettingsActivity activity = (SettingsActivity) getActivity();
mSwitchBar = activity.getSwitchBar();
//打开开关
mBluetoothEnabler = new BluetoothEnabler(activity, new SwitchBarController(mSwitchBar),
mMetricsFeatureProvider, Utils.getLocalBtManager(activity),
MetricsEvent.ACTION_BLUETOOTH_TOGGLE);
mBluetoothEnabler.setupSwitchController();
}
BluetoothSettings.java是settings中蓝牙相对比较重要的类。在初始化(onActivityCreated)的时候,进行打开开关操作。
调用BluetoothEnabler来开启开关。
BluetoothEnabler构造方法
我们进入BluetoothEnabler的构造方法来看看都做了什么操作。
E:\android8.0\pa