b/2154978 Show only connectable profiles (Headset and& A2DP but not OPP) in Bluetooth Device Advance Options aka "Connect to..."

Change-Id: I34249a4828707bde491da4a82dca94ecf37cf490
This commit is contained in:
Michael Chan
2009-09-30 14:26:10 -07:00
parent e5cff2655c
commit e6531e253b
5 changed files with 101 additions and 108 deletions

View File

@@ -34,14 +34,14 @@ import android.util.Config;
* preference reflects the current state.
*/
public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
private static final boolean LOCAL_LOGD = Config.LOGD || false;
private static final String TAG = "BluetoothEnabler";
private final Context mContext;
private final Context mContext;
private final CheckBoxPreference mCheckBoxPreference;
private final CharSequence mOriginalSummary;
private final LocalBluetoothManager mLocalManager;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -55,10 +55,10 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
public BluetoothEnabler(Context context, CheckBoxPreference checkBoxPreference) {
mContext = context;
mCheckBoxPreference = checkBoxPreference;
mOriginalSummary = checkBoxPreference.getSummary();
checkBoxPreference.setPersistent(false);
mLocalManager = LocalBluetoothManager.getInstance(context);
if (mLocalManager == null) {
// Bluetooth not supported
@@ -70,32 +70,32 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
if (mLocalManager == null) {
return;
}
int state = mLocalManager.getBluetoothState();
// This is the widget enabled state, not the preference toggled state
mCheckBoxPreference.setEnabled(state == BluetoothAdapter.STATE_ON ||
state == BluetoothAdapter.STATE_OFF);
// BT state is not a sticky broadcast, so set it manually
handleStateChanged(state);
mContext.registerReceiver(mReceiver,
mContext.registerReceiver(mReceiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
mCheckBoxPreference.setOnPreferenceChangeListener(this);
}
public void pause() {
if (mLocalManager == null) {
return;
}
mContext.unregisterReceiver(mReceiver);
mCheckBoxPreference.setOnPreferenceChangeListener(null);
}
public boolean onPreferenceChange(Preference preference, Object value) {
// Turn on/off BT
setEnabled((Boolean) value);
// Don't update UI to opposite state until we're sure
return false;
}
@@ -103,10 +103,10 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
private void setEnabled(final boolean enable) {
// Disable preference
mCheckBoxPreference.setEnabled(false);
mLocalManager.setBluetoothEnabled(enable);
}
private void handleStateChanged(int state) {
if (state == BluetoothAdapter.STATE_OFF ||
@@ -125,13 +125,13 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
if (isEnabledByDependency()) {
mCheckBoxPreference.setEnabled(true);
}
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
state == BluetoothAdapter.STATE_TURNING_OFF) {
mCheckBoxPreference.setSummary(state == BluetoothAdapter.STATE_TURNING_ON
? R.string.wifi_starting
: R.string.wifi_stopping);
} else {
mCheckBoxPreference.setChecked(false);
mCheckBoxPreference.setSummary(R.string.wifi_error);
@@ -144,17 +144,17 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
if (dep == null) {
return true;
}
return !dep.shouldDisableDependents();
}
private Preference getDependencyPreference() {
String depKey = mCheckBoxPreference.getDependency();
if (TextUtils.isEmpty(depKey)) {
return null;
}
return mCheckBoxPreference.getPreferenceManager().findPreference(depKey);
}
}