am 837bb033: am 283dce21: Merge "Allow disconnected BT profiles to be unchecked in Settings." into jb-mr1-dev

* commit '837bb033200ccd988586af7a0b6032ee9d6b9673':
  Allow disconnected BT profiles to be unchecked in Settings.
This commit is contained in:
Jake Hamby
2012-10-08 12:18:10 -07:00
committed by Android Git Automerger
2 changed files with 12 additions and 9 deletions

View File

@@ -241,7 +241,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mCachedDevice.setName((String) newValue); mCachedDevice.setName((String) newValue);
} else if (preference instanceof CheckBoxPreference) { } else if (preference instanceof CheckBoxPreference) {
LocalBluetoothProfile prof = getProfileOf(preference); LocalBluetoothProfile prof = getProfileOf(preference);
onProfileClicked(prof); onProfileClicked(prof, (CheckBoxPreference) preference);
return false; // checkbox will update from onDeviceAttributesChanged() callback return false; // checkbox will update from onDeviceAttributesChanged() callback
} else { } else {
return false; return false;
@@ -250,7 +250,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
return true; return true;
} }
private void onProfileClicked(LocalBluetoothProfile profile) { private void onProfileClicked(LocalBluetoothProfile profile, CheckBoxPreference profilePref) {
BluetoothDevice device = mCachedDevice.getDevice(); BluetoothDevice device = mCachedDevice.getDevice();
int status = profile.getConnectionStatus(device); int status = profile.getConnectionStatus(device);
@@ -260,8 +260,14 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
if (isConnected) { if (isConnected) {
askDisconnect(getActivity(), profile); askDisconnect(getActivity(), profile);
} else { } else {
profile.setPreferred(device, true); if (profile.isPreferred(device)) {
mCachedDevice.connectProfile(profile); // profile is preferred but not connected: disable auto-connect
profile.setPreferred(device, false);
refreshProfilePreference(profilePref, profile);
} else {
profile.setPreferred(device, true);
mCachedDevice.connectProfile(profile);
}
} }
} }
@@ -357,8 +363,4 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private void unpairDevice() { private void unpairDevice() {
mCachedDevice.unpair(); mCachedDevice.unpair();
} }
private boolean getAutoConnect(LocalBluetoothProfile prof) {
return prof.isPreferred(mCachedDevice.getDevice());
}
} }

View File

@@ -106,7 +106,8 @@ final class PanProfile implements LocalBluetoothProfile {
} }
public boolean isPreferred(BluetoothDevice device) { public boolean isPreferred(BluetoothDevice device) {
return true; // return current connection status so profile checkbox is set correctly
return getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED;
} }
public int getPreferred(BluetoothDevice device) { public int getPreferred(BluetoothDevice device) {