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:
@@ -32,15 +32,15 @@ public class BluetoothDevicePreference extends Preference implements CachedBluet
|
|||||||
private static final String TAG = "BluetoothDevicePreference";
|
private static final String TAG = "BluetoothDevicePreference";
|
||||||
|
|
||||||
private static int sDimAlpha = Integer.MIN_VALUE;
|
private static int sDimAlpha = Integer.MIN_VALUE;
|
||||||
|
|
||||||
private CachedBluetoothDevice mCachedDevice;
|
private CachedBluetoothDevice mCachedDevice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached local copy of whether the device is busy. This is only updated
|
* Cached local copy of whether the device is busy. This is only updated
|
||||||
* from {@link #onDeviceAttributesChanged(CachedBluetoothDevice)}.
|
* from {@link #onDeviceAttributesChanged(CachedBluetoothDevice)}.
|
||||||
*/
|
*/
|
||||||
private boolean mIsBusy;
|
private boolean mIsBusy;
|
||||||
|
|
||||||
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
|
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
@@ -49,16 +49,16 @@ public class BluetoothDevicePreference extends Preference implements CachedBluet
|
|||||||
context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
|
context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
|
||||||
sDimAlpha = (int) (outValue.getFloat() * 255);
|
sDimAlpha = (int) (outValue.getFloat() * 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
mCachedDevice = cachedDevice;
|
mCachedDevice = cachedDevice;
|
||||||
|
|
||||||
setLayoutResource(R.layout.preference_bluetooth);
|
setLayoutResource(R.layout.preference_bluetooth);
|
||||||
|
|
||||||
cachedDevice.registerCallback(this);
|
cachedDevice.registerCallback(this);
|
||||||
|
|
||||||
onDeviceAttributesChanged(cachedDevice);
|
onDeviceAttributesChanged(cachedDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedBluetoothDevice getCachedDevice() {
|
public CachedBluetoothDevice getCachedDevice() {
|
||||||
return mCachedDevice;
|
return mCachedDevice;
|
||||||
}
|
}
|
||||||
@@ -75,9 +75,9 @@ public class BluetoothDevicePreference extends Preference implements CachedBluet
|
|||||||
* The preference framework takes care of making sure the value has
|
* The preference framework takes care of making sure the value has
|
||||||
* changed before proceeding.
|
* changed before proceeding.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
setTitle(mCachedDevice.getName());
|
setTitle(mCachedDevice.getName());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Showed "Paired" even though it was "Connected". This may be
|
* TODO: Showed "Paired" even though it was "Connected". This may be
|
||||||
* related to BluetoothHeadset not bound to the actual
|
* related to BluetoothHeadset not bound to the actual
|
||||||
@@ -87,10 +87,10 @@ public class BluetoothDevicePreference extends Preference implements CachedBluet
|
|||||||
|
|
||||||
// Used to gray out the item
|
// Used to gray out the item
|
||||||
mIsBusy = mCachedDevice.isBusy();
|
mIsBusy = mCachedDevice.isBusy();
|
||||||
|
|
||||||
// Data has changed
|
// Data has changed
|
||||||
notifyChanged();
|
notifyChanged();
|
||||||
|
|
||||||
// This could affect ordering, so notify that also
|
// This could affect ordering, so notify that also
|
||||||
notifyHierarchyChanged();
|
notifyHierarchyChanged();
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ public class BluetoothDevicePreference extends Preference implements CachedBluet
|
|||||||
|
|
||||||
ImageView btClass = (ImageView) view.findViewById(R.id.btClass);
|
ImageView btClass = (ImageView) view.findViewById(R.id.btClass);
|
||||||
btClass.setImageResource(mCachedDevice.getBtClassDrawable());
|
btClass.setImageResource(mCachedDevice.getBtClassDrawable());
|
||||||
btClass.setAlpha(isEnabled() ? 255 : sDimAlpha);
|
btClass.setAlpha(isEnabled() ? 255 : sDimAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,8 +122,8 @@ public class BluetoothDevicePreference extends Preference implements CachedBluet
|
|||||||
// Put other preference types above us
|
// Put other preference types above us
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mCachedDevice.compareTo(((BluetoothDevicePreference) another).mCachedDevice);
|
return mCachedDevice.compareTo(((BluetoothDevicePreference) another).mCachedDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,14 +34,14 @@ import android.util.Config;
|
|||||||
* preference reflects the current state.
|
* preference reflects the current state.
|
||||||
*/
|
*/
|
||||||
public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final boolean LOCAL_LOGD = Config.LOGD || false;
|
private static final boolean LOCAL_LOGD = Config.LOGD || false;
|
||||||
private static final String TAG = "BluetoothEnabler";
|
private static final String TAG = "BluetoothEnabler";
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final CheckBoxPreference mCheckBoxPreference;
|
private final CheckBoxPreference mCheckBoxPreference;
|
||||||
private final CharSequence mOriginalSummary;
|
private final CharSequence mOriginalSummary;
|
||||||
|
|
||||||
private final LocalBluetoothManager mLocalManager;
|
private final LocalBluetoothManager mLocalManager;
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@@ -55,10 +55,10 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
public BluetoothEnabler(Context context, CheckBoxPreference checkBoxPreference) {
|
public BluetoothEnabler(Context context, CheckBoxPreference checkBoxPreference) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mCheckBoxPreference = checkBoxPreference;
|
mCheckBoxPreference = checkBoxPreference;
|
||||||
|
|
||||||
mOriginalSummary = checkBoxPreference.getSummary();
|
mOriginalSummary = checkBoxPreference.getSummary();
|
||||||
checkBoxPreference.setPersistent(false);
|
checkBoxPreference.setPersistent(false);
|
||||||
|
|
||||||
mLocalManager = LocalBluetoothManager.getInstance(context);
|
mLocalManager = LocalBluetoothManager.getInstance(context);
|
||||||
if (mLocalManager == null) {
|
if (mLocalManager == null) {
|
||||||
// Bluetooth not supported
|
// Bluetooth not supported
|
||||||
@@ -70,32 +70,32 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
if (mLocalManager == null) {
|
if (mLocalManager == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int state = mLocalManager.getBluetoothState();
|
int state = mLocalManager.getBluetoothState();
|
||||||
// This is the widget enabled state, not the preference toggled state
|
// This is the widget enabled state, not the preference toggled state
|
||||||
mCheckBoxPreference.setEnabled(state == BluetoothAdapter.STATE_ON ||
|
mCheckBoxPreference.setEnabled(state == BluetoothAdapter.STATE_ON ||
|
||||||
state == BluetoothAdapter.STATE_OFF);
|
state == BluetoothAdapter.STATE_OFF);
|
||||||
// BT state is not a sticky broadcast, so set it manually
|
// BT state is not a sticky broadcast, so set it manually
|
||||||
handleStateChanged(state);
|
handleStateChanged(state);
|
||||||
|
|
||||||
mContext.registerReceiver(mReceiver,
|
mContext.registerReceiver(mReceiver,
|
||||||
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||||
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (mLocalManager == null) {
|
if (mLocalManager == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mContext.unregisterReceiver(mReceiver);
|
mContext.unregisterReceiver(mReceiver);
|
||||||
mCheckBoxPreference.setOnPreferenceChangeListener(null);
|
mCheckBoxPreference.setOnPreferenceChangeListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
// Turn on/off BT
|
// Turn on/off BT
|
||||||
setEnabled((Boolean) value);
|
setEnabled((Boolean) value);
|
||||||
|
|
||||||
// Don't update UI to opposite state until we're sure
|
// Don't update UI to opposite state until we're sure
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -103,10 +103,10 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
private void setEnabled(final boolean enable) {
|
private void setEnabled(final boolean enable) {
|
||||||
// Disable preference
|
// Disable preference
|
||||||
mCheckBoxPreference.setEnabled(false);
|
mCheckBoxPreference.setEnabled(false);
|
||||||
|
|
||||||
mLocalManager.setBluetoothEnabled(enable);
|
mLocalManager.setBluetoothEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStateChanged(int state) {
|
private void handleStateChanged(int state) {
|
||||||
|
|
||||||
if (state == BluetoothAdapter.STATE_OFF ||
|
if (state == BluetoothAdapter.STATE_OFF ||
|
||||||
@@ -125,13 +125,13 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
if (isEnabledByDependency()) {
|
if (isEnabledByDependency()) {
|
||||||
mCheckBoxPreference.setEnabled(true);
|
mCheckBoxPreference.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
|
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
|
||||||
state == BluetoothAdapter.STATE_TURNING_OFF) {
|
state == BluetoothAdapter.STATE_TURNING_OFF) {
|
||||||
mCheckBoxPreference.setSummary(state == BluetoothAdapter.STATE_TURNING_ON
|
mCheckBoxPreference.setSummary(state == BluetoothAdapter.STATE_TURNING_ON
|
||||||
? R.string.wifi_starting
|
? R.string.wifi_starting
|
||||||
: R.string.wifi_stopping);
|
: R.string.wifi_stopping);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mCheckBoxPreference.setChecked(false);
|
mCheckBoxPreference.setChecked(false);
|
||||||
mCheckBoxPreference.setSummary(R.string.wifi_error);
|
mCheckBoxPreference.setSummary(R.string.wifi_error);
|
||||||
@@ -144,17 +144,17 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
if (dep == null) {
|
if (dep == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !dep.shouldDisableDependents();
|
return !dep.shouldDisableDependents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Preference getDependencyPreference() {
|
private Preference getDependencyPreference() {
|
||||||
String depKey = mCheckBoxPreference.getDependency();
|
String depKey = mCheckBoxPreference.getDependency();
|
||||||
if (TextUtils.isEmpty(depKey)) {
|
if (TextUtils.isEmpty(depKey)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mCheckBoxPreference.getPreferenceManager().findPreference(depKey);
|
return mCheckBoxPreference.getPreferenceManager().findPreference(depKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,11 +20,11 @@ import android.app.AlertDialog;
|
|||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.os.ParcelUuid;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.ParcelUuid;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -794,8 +794,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Profile> getProfiles() {
|
public List<Profile> getConnectableProfiles() {
|
||||||
return new ArrayList<Profile>(mProfiles);
|
ArrayList<Profile> connectableProfiles = new ArrayList<Profile>();
|
||||||
|
for (Profile profile : mProfiles) {
|
||||||
|
if (isConnectableProfile(profile)) {
|
||||||
|
connectableProfiles.add(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return connectableProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isConnectableProfile(Profile profile) {
|
||||||
|
return profile.equals(Profile.HEADSET) || profile.equals(Profile.A2DP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreateContextMenu(ContextMenu menu) {
|
public void onCreateContextMenu(ContextMenu menu) {
|
||||||
@@ -806,7 +816,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
|
|
||||||
int bondState = getBondState();
|
int bondState = getBondState();
|
||||||
boolean isConnected = isConnected();
|
boolean isConnected = isConnected();
|
||||||
boolean hasProfiles = mProfiles.size() > 0;
|
boolean hasConnectableProfiles = false;
|
||||||
|
|
||||||
|
for (Profile profile : mProfiles) {
|
||||||
|
if (isConnectableProfile(profile)) {
|
||||||
|
hasConnectableProfiles = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
menu.setHeaderTitle(getName());
|
menu.setHeaderTitle(getName());
|
||||||
|
|
||||||
@@ -819,14 +836,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
menu.add(0, CONTEXT_ITEM_UNPAIR, 0,
|
menu.add(0, CONTEXT_ITEM_UNPAIR, 0,
|
||||||
R.string.bluetooth_device_context_disconnect_unpair);
|
R.string.bluetooth_device_context_disconnect_unpair);
|
||||||
} else { // Paired but not connected
|
} else { // Paired but not connected
|
||||||
if (hasProfiles) {
|
if (hasConnectableProfiles) {
|
||||||
menu.add(0, CONTEXT_ITEM_CONNECT, 0, R.string.bluetooth_device_context_connect);
|
menu.add(0, CONTEXT_ITEM_CONNECT, 0, R.string.bluetooth_device_context_connect);
|
||||||
}
|
}
|
||||||
menu.add(0, CONTEXT_ITEM_UNPAIR, 0, R.string.bluetooth_device_context_unpair);
|
menu.add(0, CONTEXT_ITEM_UNPAIR, 0, R.string.bluetooth_device_context_unpair);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the connection options item
|
// Show the connection options item
|
||||||
if (hasProfiles) {
|
if (hasConnectableProfiles) {
|
||||||
menu.add(0, CONTEXT_ITEM_CONNECT_ADVANCED, 0,
|
menu.add(0, CONTEXT_ITEM_CONNECT_ADVANCED, 0,
|
||||||
R.string.bluetooth_device_context_connect_advanced);
|
R.string.bluetooth_device_context_connect_advanced);
|
||||||
}
|
}
|
||||||
|
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,7 +26,8 @@ import android.preference.PreferenceGroup;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConnectSpecificProfilesActivity presents the user with all of the profiles
|
* ConnectSpecificProfilesActivity presents the user with all of the profiles
|
||||||
@@ -46,12 +44,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
|
|
||||||
public static final String EXTRA_DEVICE = "device";
|
public static final String EXTRA_DEVICE = "device";
|
||||||
|
|
||||||
public static final String CLASS_NAME_OPP_PROFILE_MANAGER =
|
|
||||||
"com.android.settings.bluetooth.LocalBluetoothProfileManager$OppProfileManager";
|
|
||||||
|
|
||||||
private LocalBluetoothManager mManager;
|
private LocalBluetoothManager mManager;
|
||||||
private CachedBluetoothDevice mCachedDevice;
|
private CachedBluetoothDevice mCachedDevice;
|
||||||
|
|
||||||
private PreferenceGroup mProfileContainer;
|
private PreferenceGroup mProfileContainer;
|
||||||
private CheckBoxPreference mOnlineModePreference;
|
private CheckBoxPreference mOnlineModePreference;
|
||||||
|
|
||||||
@@ -63,11 +58,11 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
* profile.
|
* profile.
|
||||||
*/
|
*/
|
||||||
private boolean mOnlineMode;
|
private boolean mOnlineMode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
BluetoothDevice device;
|
BluetoothDevice device;
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
device = savedInstanceState.getParcelable(EXTRA_DEVICE);
|
device = savedInstanceState.getParcelable(EXTRA_DEVICE);
|
||||||
@@ -80,7 +75,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
Log.w(TAG, "Activity started without a remote blueototh device");
|
Log.w(TAG, "Activity started without a remote blueototh device");
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
mManager = LocalBluetoothManager.getInstance(this);
|
mManager = LocalBluetoothManager.getInstance(this);
|
||||||
mCachedDevice = mManager.getCachedDeviceManager().findDevice(device);
|
mCachedDevice = mManager.getCachedDeviceManager().findDevice(device);
|
||||||
if (mCachedDevice == null) {
|
if (mCachedDevice == null) {
|
||||||
@@ -90,7 +85,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
|
|
||||||
addPreferencesFromResource(R.xml.bluetooth_device_advanced);
|
addPreferencesFromResource(R.xml.bluetooth_device_advanced);
|
||||||
mProfileContainer = (PreferenceGroup) findPreference(KEY_PROFILE_CONTAINER);
|
mProfileContainer = (PreferenceGroup) findPreference(KEY_PROFILE_CONTAINER);
|
||||||
|
|
||||||
// Set the title of the screen
|
// Set the title of the screen
|
||||||
findPreference(KEY_TITLE).setTitle(
|
findPreference(KEY_TITLE).setTitle(
|
||||||
getString(R.string.bluetooth_device_advanced_title, mCachedDevice.getName()));
|
getString(R.string.bluetooth_device_advanced_title, mCachedDevice.getName()));
|
||||||
@@ -98,7 +93,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
// Listen for check/uncheck of the online mode checkbox
|
// Listen for check/uncheck of the online mode checkbox
|
||||||
mOnlineModePreference = (CheckBoxPreference) findPreference(KEY_ONLINE_MODE);
|
mOnlineModePreference = (CheckBoxPreference) findPreference(KEY_ONLINE_MODE);
|
||||||
mOnlineModePreference.setOnPreferenceChangeListener(this);
|
mOnlineModePreference.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
// Add a preference for each profile
|
// Add a preference for each profile
|
||||||
addPreferencesForProfiles();
|
addPreferencesForProfiles();
|
||||||
}
|
}
|
||||||
@@ -106,14 +101,14 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
outState.putParcelable(EXTRA_DEVICE, mCachedDevice.getDevice());
|
outState.putParcelable(EXTRA_DEVICE, mCachedDevice.getDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
mManager.setForegroundActivity(this);
|
mManager.setForegroundActivity(this);
|
||||||
mCachedDevice.registerCallback(this);
|
mCachedDevice.registerCallback(this);
|
||||||
|
|
||||||
@@ -123,13 +118,13 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
mCachedDevice.unregisterCallback(this);
|
mCachedDevice.unregisterCallback(this);
|
||||||
mManager.setForegroundActivity(null);
|
mManager.setForegroundActivity(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPreferencesForProfiles() {
|
private void addPreferencesForProfiles() {
|
||||||
for (Profile profile : mCachedDevice.getProfiles()) {
|
for (Profile profile : mCachedDevice.getConnectableProfiles()) {
|
||||||
Preference pref = createProfilePreference(profile);
|
Preference pref = createProfilePreference(profile);
|
||||||
mProfileContainer.addPreference(pref);
|
mProfileContainer.addPreference(pref);
|
||||||
}
|
}
|
||||||
@@ -138,7 +133,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
/**
|
/**
|
||||||
* Creates a checkbox preference for the particular profile. The key will be
|
* Creates a checkbox preference for the particular profile. The key will be
|
||||||
* the profile's name.
|
* the profile's name.
|
||||||
*
|
*
|
||||||
* @param profile The profile for which the preference controls.
|
* @param profile The profile for which the preference controls.
|
||||||
* @return A preference that allows the user to choose whether this profile
|
* @return A preference that allows the user to choose whether this profile
|
||||||
* will be connected to.
|
* will be connected to.
|
||||||
@@ -154,27 +149,22 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
.getProfileManager(mManager, profile);
|
.getProfileManager(mManager, profile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gray out checkbox while connecting and disconnecting or this is OPP
|
* Gray out checkbox while connecting and disconnecting
|
||||||
* profile
|
|
||||||
*/
|
*/
|
||||||
if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
|
pref.setEnabled(!mCachedDevice.isBusy());
|
||||||
pref.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
pref.setEnabled(!mCachedDevice.isBusy());
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshProfilePreference(pref, profile);
|
refreshProfilePreference(pref, profile);
|
||||||
|
|
||||||
return pref;
|
return pref;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
String key = preference.getKey();
|
String key = preference.getKey();
|
||||||
if (TextUtils.isEmpty(key) || newValue == null) return true;
|
if (TextUtils.isEmpty(key) || newValue == null) return true;
|
||||||
|
|
||||||
if (key.equals(KEY_ONLINE_MODE)) {
|
if (key.equals(KEY_ONLINE_MODE)) {
|
||||||
onOnlineModeCheckedStateChanged((Boolean) newValue);
|
onOnlineModeCheckedStateChanged((Boolean) newValue);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Profile profile = getProfileOf(preference);
|
Profile profile = getProfileOf(preference);
|
||||||
if (profile == null) return false;
|
if (profile == null) return false;
|
||||||
@@ -187,7 +177,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
private void onOnlineModeCheckedStateChanged(boolean checked) {
|
private void onOnlineModeCheckedStateChanged(boolean checked) {
|
||||||
setOnlineMode(checked, true);
|
setOnlineMode(checked, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onProfileCheckedStateChanged(Profile profile, boolean checked) {
|
private void onProfileCheckedStateChanged(Profile profile, boolean checked) {
|
||||||
if (mOnlineMode) {
|
if (mOnlineMode) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
@@ -196,12 +186,12 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
mCachedDevice.disconnect(profile);
|
mCachedDevice.disconnect(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
||||||
.getProfileManager(mManager, profile);
|
.getProfileManager(mManager, profile);
|
||||||
profileManager.setPreferred(mCachedDevice.getDevice(), checked);
|
profileManager.setPreferred(mCachedDevice.getDevice(), checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDeviceAttributesChanged(CachedBluetoothDevice cachedDevice) {
|
public void onDeviceAttributesChanged(CachedBluetoothDevice cachedDevice) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@@ -214,14 +204,14 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches between online/offline mode.
|
* Switches between online/offline mode.
|
||||||
*
|
*
|
||||||
* @param onlineMode Whether to be in online mode, or offline mode.
|
* @param onlineMode Whether to be in online mode, or offline mode.
|
||||||
* @param takeAction Whether to take action (i.e., connect or disconnect)
|
* @param takeAction Whether to take action (i.e., connect or disconnect)
|
||||||
* based on the new online mode.
|
* based on the new online mode.
|
||||||
*/
|
*/
|
||||||
private void setOnlineMode(boolean onlineMode, boolean takeAction) {
|
private void setOnlineMode(boolean onlineMode, boolean takeAction) {
|
||||||
mOnlineMode = onlineMode;
|
mOnlineMode = onlineMode;
|
||||||
|
|
||||||
if (takeAction) {
|
if (takeAction) {
|
||||||
if (onlineMode) {
|
if (onlineMode) {
|
||||||
mCachedDevice.connect();
|
mCachedDevice.connect();
|
||||||
@@ -229,22 +219,16 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
mCachedDevice.disconnect();
|
mCachedDevice.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshOnlineModePreference();
|
refreshOnlineModePreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshOnlineModePreference() {
|
private void refreshOnlineModePreference() {
|
||||||
mOnlineModePreference.setChecked(mOnlineMode);
|
mOnlineModePreference.setChecked(mOnlineMode);
|
||||||
|
|
||||||
/* Gray out checkbox while connecting and disconnecting */
|
/* Gray out checkbox while connecting and disconnecting */
|
||||||
mOnlineModePreference.setEnabled(!mCachedDevice.isBusy());
|
mOnlineModePreference.setEnabled(!mCachedDevice.isBusy());
|
||||||
|
|
||||||
List<Profile> profiles = mCachedDevice.getProfiles();
|
|
||||||
if ((profiles.size() == 1) && (profiles.get(0).name().equals("OPP"))) {
|
|
||||||
Log.w(TAG, "there is only one profile: Opp, disable the connect button.");
|
|
||||||
mOnlineModePreference.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the device is online, show status. Otherwise, show a summary that
|
* If the device is online, show status. Otherwise, show a summary that
|
||||||
* describes what the checkbox does.
|
* describes what the checkbox does.
|
||||||
@@ -252,9 +236,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
mOnlineModePreference.setSummary(mOnlineMode ? mCachedDevice.getSummary()
|
mOnlineModePreference.setSummary(mOnlineMode ? mCachedDevice.getSummary()
|
||||||
: R.string.bluetooth_device_advanced_online_mode_summary);
|
: R.string.bluetooth_device_advanced_online_mode_summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshProfiles() {
|
private void refreshProfiles() {
|
||||||
for (Profile profile : mCachedDevice.getProfiles()) {
|
for (Profile profile : mCachedDevice.getConnectableProfiles()) {
|
||||||
CheckBoxPreference profilePref =
|
CheckBoxPreference profilePref =
|
||||||
(CheckBoxPreference) findPreference(profile.toString());
|
(CheckBoxPreference) findPreference(profile.toString());
|
||||||
if (profilePref == null) {
|
if (profilePref == null) {
|
||||||
@@ -265,27 +249,21 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshProfilePreference(CheckBoxPreference profilePref, Profile profile) {
|
private void refreshProfilePreference(CheckBoxPreference profilePref, Profile profile) {
|
||||||
BluetoothDevice device = mCachedDevice.getDevice();
|
BluetoothDevice device = mCachedDevice.getDevice();
|
||||||
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
||||||
.getProfileManager(mManager, profile);
|
.getProfileManager(mManager, profile);
|
||||||
|
|
||||||
int connectionStatus = profileManager.getConnectionStatus(device);
|
int connectionStatus = profileManager.getConnectionStatus(device);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gray out checkbox while connecting and disconnecting or this is OPP
|
* Gray out checkbox while connecting and disconnecting
|
||||||
* profile
|
|
||||||
*/
|
*/
|
||||||
if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
|
profilePref.setEnabled(!mCachedDevice.isBusy());
|
||||||
Log.w(TAG, "this is Opp profile");
|
|
||||||
profilePref.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
profilePref.setEnabled(!mCachedDevice.isBusy());
|
|
||||||
}
|
|
||||||
profilePref.setSummary(getProfileSummary(profileManager, profile, device,
|
profilePref.setSummary(getProfileSummary(profileManager, profile, device,
|
||||||
connectionStatus, mOnlineMode));
|
connectionStatus, mOnlineMode));
|
||||||
|
|
||||||
profilePref.setChecked(profileManager.isPreferred(device));
|
profilePref.setChecked(profileManager.isPreferred(device));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +271,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
if (!(pref instanceof CheckBoxPreference)) return null;
|
if (!(pref instanceof CheckBoxPreference)) return null;
|
||||||
String key = pref.getKey();
|
String key = pref.getKey();
|
||||||
if (TextUtils.isEmpty(key)) return null;
|
if (TextUtils.isEmpty(key)) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Profile.valueOf(pref.getKey());
|
return Profile.valueOf(pref.getKey());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@@ -309,10 +287,10 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
return profileManager.getSummary(device);
|
return profileManager.getSummary(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the summary that describes when checked, it will become a preferred profile.
|
* Gets the summary that describes when checked, it will become a preferred profile.
|
||||||
*
|
*
|
||||||
* @param profile The profile to get the summary for.
|
* @param profile The profile to get the summary for.
|
||||||
* @return The summary.
|
* @return The summary.
|
||||||
*/
|
*/
|
||||||
@@ -322,11 +300,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
return R.string.bluetooth_a2dp_profile_summary_use_for;
|
return R.string.bluetooth_a2dp_profile_summary_use_for;
|
||||||
case HEADSET:
|
case HEADSET:
|
||||||
return R.string.bluetooth_headset_profile_summary_use_for;
|
return R.string.bluetooth_headset_profile_summary_use_for;
|
||||||
case OPP:
|
|
||||||
return R.string.bluetooth_opp_profile_summary_use_for;
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,9 +26,9 @@ import com.android.settings.R;
|
|||||||
*/
|
*/
|
||||||
public class SettingsBtStatus {
|
public class SettingsBtStatus {
|
||||||
private static final String TAG = "SettingsBtStatus";
|
private static final String TAG = "SettingsBtStatus";
|
||||||
|
|
||||||
// Connection status
|
// Connection status
|
||||||
|
|
||||||
public static final int CONNECTION_STATUS_UNKNOWN = 0;
|
public static final int CONNECTION_STATUS_UNKNOWN = 0;
|
||||||
public static final int CONNECTION_STATUS_ACTIVE = 1;
|
public static final int CONNECTION_STATUS_ACTIVE = 1;
|
||||||
/** Use {@link #isConnected} to check for the connected state */
|
/** Use {@link #isConnected} to check for the connected state */
|
||||||
@@ -55,17 +55,17 @@ public class SettingsBtStatus {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean isConnectionStatusConnected(int connectionStatus) {
|
public static final boolean isConnectionStatusConnected(int connectionStatus) {
|
||||||
return connectionStatus == CONNECTION_STATUS_ACTIVE
|
return connectionStatus == CONNECTION_STATUS_ACTIVE
|
||||||
|| connectionStatus == CONNECTION_STATUS_CONNECTED;
|
|| connectionStatus == CONNECTION_STATUS_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean isConnectionStatusBusy(int connectionStatus) {
|
public static final boolean isConnectionStatusBusy(int connectionStatus) {
|
||||||
return connectionStatus == CONNECTION_STATUS_CONNECTING
|
return connectionStatus == CONNECTION_STATUS_CONNECTING
|
||||||
|| connectionStatus == CONNECTION_STATUS_DISCONNECTING;
|
|| connectionStatus == CONNECTION_STATUS_DISCONNECTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int getPairingStatusSummary(int bondState) {
|
public static final int getPairingStatusSummary(int bondState) {
|
||||||
switch (bondState) {
|
switch (bondState) {
|
||||||
case BluetoothDevice.BOND_BONDED:
|
case BluetoothDevice.BOND_BONDED:
|
||||||
|
Reference in New Issue
Block a user