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

@@ -20,11 +20,11 @@ import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.os.ParcelUuid;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.ParcelUuid;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
@@ -794,8 +794,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
}
}
public List<Profile> getProfiles() {
return new ArrayList<Profile>(mProfiles);
public List<Profile> getConnectableProfiles() {
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) {
@@ -806,7 +816,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
int bondState = getBondState();
boolean isConnected = isConnected();
boolean hasProfiles = mProfiles.size() > 0;
boolean hasConnectableProfiles = false;
for (Profile profile : mProfiles) {
if (isConnectableProfile(profile)) {
hasConnectableProfiles = true;
break;
}
}
menu.setHeaderTitle(getName());
@@ -819,14 +836,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
menu.add(0, CONTEXT_ITEM_UNPAIR, 0,
R.string.bluetooth_device_context_disconnect_unpair);
} 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_UNPAIR, 0, R.string.bluetooth_device_context_unpair);
}
// Show the connection options item
if (hasProfiles) {
if (hasConnectableProfiles) {
menu.add(0, CONTEXT_ITEM_CONNECT_ADVANCED, 0,
R.string.bluetooth_device_context_connect_advanced);
}

View File

@@ -16,9 +16,6 @@
package com.android.settings.bluetooth;
import com.android.settings.R;
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
@@ -29,7 +26,8 @@ import android.preference.PreferenceGroup;
import android.text.TextUtils;
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
@@ -46,9 +44,6 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
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 CachedBluetoothDevice mCachedDevice;
@@ -129,7 +124,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
}
private void addPreferencesForProfiles() {
for (Profile profile : mCachedDevice.getProfiles()) {
for (Profile profile : mCachedDevice.getConnectableProfiles()) {
Preference pref = createProfilePreference(profile);
mProfileContainer.addPreference(pref);
}
@@ -154,14 +149,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
.getProfileManager(mManager, profile);
/**
* Gray out checkbox while connecting and disconnecting or this is OPP
* profile
* Gray out checkbox while connecting and disconnecting
*/
if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
pref.setEnabled(false);
} else {
pref.setEnabled(!mCachedDevice.isBusy());
}
refreshProfilePreference(pref, profile);
@@ -239,12 +229,6 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
/* Gray out checkbox while connecting and disconnecting */
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
* describes what the checkbox does.
@@ -254,7 +238,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
}
private void refreshProfiles() {
for (Profile profile : mCachedDevice.getProfiles()) {
for (Profile profile : mCachedDevice.getConnectableProfiles()) {
CheckBoxPreference profilePref =
(CheckBoxPreference) findPreference(profile.toString());
if (profilePref == null) {
@@ -274,15 +258,9 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
int connectionStatus = profileManager.getConnectionStatus(device);
/*
* Gray out checkbox while connecting and disconnecting or this is OPP
* profile
* Gray out checkbox while connecting and disconnecting
*/
if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
Log.w(TAG, "this is Opp profile");
profilePref.setEnabled(false);
} else {
profilePref.setEnabled(!mCachedDevice.isBusy());
}
profilePref.setSummary(getProfileSummary(profileManager, profile, device,
connectionStatus, mOnlineMode));
@@ -322,8 +300,6 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
return R.string.bluetooth_a2dp_profile_summary_use_for;
case HEADSET:
return R.string.bluetooth_headset_profile_summary_use_for;
case OPP:
return R.string.bluetooth_opp_profile_summary_use_for;
default:
return 0;
}