Fixed Bluetooth availability test in Settings

Added similar test for WiFi to be consistent.

Added null tests in BluetoothEnabler.

Change-Id: Ia6e7b150a1bc060c7ce0b4db12ab3f6c958af104
This commit is contained in:
Gilles Debunne
2011-06-21 16:16:06 -07:00
parent e78c187905
commit 2454f49c93
2 changed files with 16 additions and 9 deletions

View File

@@ -66,6 +66,7 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
public void resume() {
if (mLocalAdapter == null) {
mSwitch.setEnabled(false);
return;
}
@@ -91,11 +92,12 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
mSwitch = switch_;
mSwitch.setOnCheckedChangeListener(this);
final int bluetoothState = mLocalAdapter.getBluetoothState();
boolean isEnabled = bluetoothState == BluetoothAdapter.STATE_ON;
boolean isDisabled = bluetoothState == BluetoothAdapter.STATE_OFF;
mSwitch.setChecked(isEnabled);
mSwitch.setEnabled(isEnabled || isDisabled);
int bluetoothState = BluetoothAdapter.STATE_OFF;
if (mLocalAdapter != null) bluetoothState = mLocalAdapter.getBluetoothState();
boolean isOn = bluetoothState == BluetoothAdapter.STATE_ON;
boolean isOff = bluetoothState == BluetoothAdapter.STATE_OFF;
mSwitch.setChecked(isOn);
mSwitch.setEnabled(isOn || isOff);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -107,7 +109,9 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
buttonView.setChecked(false);
}
mLocalAdapter.setBluetoothEnabled(isChecked);
if (mLocalAdapter != null) {
mLocalAdapter.setBluetoothEnabled(isChecked);
}
mSwitch.setEnabled(false);
}