diff --git a/res/layout/preference_bluetooth.xml b/res/layout/preference_bluetooth.xml
index bd437a9a5c7..e10c65fb7f2 100644
--- a/res/layout/preference_bluetooth.xml
+++ b/res/layout/preference_bluetooth.xml
@@ -19,13 +19,6 @@
android:layout_height="wrap_content"
android:gravity="center_vertical">
-
-
- - 2 Minutes
- - 5 Minutes
- - 1 Hour
- - Never
+ - 2 minutes
+ - 5 minutes
+ - 1 hour
+ - Never time out
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 638f4c1040c..4f6b2c46fec 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -230,10 +230,20 @@
Disconnect?
This will end your connection with:<br><b>%1$s</b>
-
- "%1$s will be disconnected."
-
+
+
+ Disable profile?
+
+ This will disable:<br><b>%1$s</b><br><br>From:<br><b>%2$s</b>
+
+
Connected
+
+ Connected (no phone)
+
+ Connected (no media)
+
+ Connected (no phone or media)
Disconnected
@@ -242,12 +252,8 @@
Connecting\u2026
-
- Pair with this device
Pairing\u2026
-
- Paired but not connected
Unnamed Bluetooth device
@@ -1011,15 +1017,17 @@
Connect to\u2026
- Media
+ Media audio
- Handsfree
+ Phone audio
- Transfer
+ File transfer
- Input Device
-
+ Input device
+
Internet access
+
+ Internet connection sharing
%1$s will be disconnected from media audio.
@@ -1034,10 +1042,8 @@
%1$s will be disconnected from sharing this phone\'s Internet connection.
-
- %1$s options
-
- Device actions
+
+ Paired Bluetooth device
Connect
@@ -1045,7 +1051,7 @@
Profiles
- Rename device
+ Rename
Allow incoming file transfers
diff --git a/res/xml/bluetooth_device_advanced.xml b/res/xml/bluetooth_device_advanced.xml
index 6610a69d580..8d2261c45b1 100644
--- a/res/xml/bluetooth_device_advanced.xml
+++ b/res/xml/bluetooth_device_advanced.xml
@@ -15,12 +15,8 @@
-->
-
-
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/bluetooth_device_advanced_title">
mCachedDevices =
new ArrayList();
@@ -35,20 +34,9 @@ final class CachedBluetoothDeviceManager {
return new ArrayList(mCachedDevices);
}
- public boolean onDeviceDisappeared(CachedBluetoothDevice cachedDevice) {
+ public static boolean onDeviceDisappeared(CachedBluetoothDevice cachedDevice) {
cachedDevice.setVisible(false);
- return checkForDeviceRemoval(cachedDevice);
- }
-
- private boolean checkForDeviceRemoval(
- CachedBluetoothDevice cachedDevice) {
- if (cachedDevice.getBondState() == BluetoothDevice.BOND_NONE &&
- !cachedDevice.isVisible()) {
- // If device isn't paired, remove it altogether
- mCachedDevices.remove(cachedDevice);
- return true; // dispatch device deleted
- }
- return false;
+ return cachedDevice.getBondState() == BluetoothDevice.BOND_NONE;
}
public void onDeviceNameUpdated(BluetoothDevice device) {
@@ -120,7 +108,6 @@ final class CachedBluetoothDeviceManager {
for (int i = mCachedDevices.size() - 1; i >= 0; i--) {
CachedBluetoothDevice cachedDevice = mCachedDevices.get(i);
cachedDevice.setVisible(false);
- checkForDeviceRemoval(cachedDevice);
}
}
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index 53bd33cdb1f..061f2c96bf3 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -128,7 +128,6 @@ public abstract class DeviceListPreferenceFragment extends
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
-
if (KEY_BT_SCAN.equals(preference.getKey())) {
mLocalAdapter.startScanning(true);
return true;
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index cee2a53141f..a840982288f 100755
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
+import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -46,15 +47,12 @@ import java.util.HashMap;
* (or disconnected).
*/
public final class DeviceProfilesSettings extends SettingsPreferenceFragment
- implements CachedBluetoothDevice.Callback, Preference.OnPreferenceChangeListener,
- View.OnClickListener {
+ implements CachedBluetoothDevice.Callback, Preference.OnPreferenceChangeListener {
private static final String TAG = "DeviceProfilesSettings";
- private static final String KEY_TITLE = "title";
private static final String KEY_RENAME_DEVICE = "rename_device";
private static final String KEY_PROFILE_CONTAINER = "profile_container";
private static final String KEY_UNPAIR = "unpair";
- //private static final String KEY_ALLOW_INCOMING = "allow_incoming";
public static final String EXTRA_DEVICE = "device";
private RenameEditTextPreference mRenameDeviceNamePref;
@@ -69,6 +67,8 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
= new HashMap();
private AlertDialog mDisconnectDialog;
+ private boolean mProfileGroupIsRemoved;
+
private class RenameEditTextPreference implements TextWatcher{
public void afterTextChanged(Editable s) {
Dialog d = mDeviceNamePref.getDialog();
@@ -87,6 +87,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
// not used
}
}
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -126,11 +127,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mDeviceNamePref.setText(deviceName);
mDeviceNamePref.setOnPreferenceChangeListener(this);
- // Set the title of the screen
- findPreference(KEY_TITLE).setTitle(
- getString(R.string.bluetooth_device_advanced_title,
- deviceName));
-
// Add a preference for each profile
addPreferencesForProfiles();
}
@@ -183,6 +179,18 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
Preference pref = createProfilePreference(profile);
mProfileContainer.addPreference(pref);
}
+ showOrHideProfileGroup();
+ }
+
+ private void showOrHideProfileGroup() {
+ int numProfiles = mProfileContainer.getPreferenceCount();
+ if (!mProfileGroupIsRemoved && numProfiles == 0) {
+ getPreferenceScreen().removePreference(mProfileContainer);
+ mProfileGroupIsRemoved = true;
+ } else if (mProfileGroupIsRemoved && numProfiles != 0) {
+ getPreferenceScreen().addPreference(mProfileContainer);
+ mProfileGroupIsRemoved = false;
+ }
}
/**
@@ -193,18 +201,17 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
* @return A preference that allows the user to choose whether this profile
* will be connected to.
*/
- private Preference createProfilePreference(LocalBluetoothProfile profile) {
- BluetoothProfilePreference pref = new BluetoothProfilePreference(getActivity(), profile);
+ private CheckBoxPreference createProfilePreference(LocalBluetoothProfile profile) {
+ CheckBoxPreference pref = new CheckBoxPreference(getActivity());
pref.setKey(profile.toString());
- pref.setTitle(profile.getNameResource());
- pref.setExpanded(false);
+ pref.setTitle(profile.getNameResource(mCachedDevice.getDevice()));
pref.setPersistent(false);
pref.setOrder(getProfilePreferenceIndex(profile.getOrdinal()));
- pref.setOnExpandClickListener(this);
+ pref.setOnPreferenceChangeListener(this);
int iconResource = profile.getDrawableResource(mCachedDevice.getBtClass());
if (iconResource != 0) {
- pref.setProfileDrawable(getResources().getDrawable(iconResource));
+ pref.setIcon(getResources().getDrawable(iconResource));
}
/**
@@ -220,10 +227,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
String key = preference.getKey();
- if (preference instanceof BluetoothProfilePreference) {
- onProfileClicked(mProfileManager.getProfileByName(key));
- return true;
- } else if (key.equals(KEY_UNPAIR)) {
+ if (key.equals(KEY_UNPAIR)) {
unpairDevice();
finish();
return true;
@@ -236,11 +240,9 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
if (preference == mDeviceNamePref) {
mCachedDevice.setName((String) newValue);
} else if (preference instanceof CheckBoxPreference) {
- boolean autoConnect = (Boolean) newValue;
LocalBluetoothProfile prof = getProfileOf(preference);
- prof.setPreferred(mCachedDevice.getDevice(),
- autoConnect);
- return true;
+ onProfileClicked(prof);
+ return false; // checkbox will update from onDeviceAttributesChanged() callback
} else {
return false;
}
@@ -258,6 +260,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
if (isConnected) {
askDisconnect(getActivity(), profile);
} else {
+ profile.setPreferred(device, true);
mCachedDevice.connectProfile(profile);
}
}
@@ -270,22 +273,23 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
if (TextUtils.isEmpty(name)) {
name = context.getString(R.string.bluetooth_device);
}
- int disconnectMessage = profile.getDisconnectResource(device.getDevice());
- if (disconnectMessage == 0) {
- Log.w(TAG, "askDisconnect: unexpected profile " + profile);
- disconnectMessage = R.string.bluetooth_disconnect_blank;
- }
- String message = context.getString(disconnectMessage, name);
+
+ String profileName = context.getString(profile.getNameResource(device.getDevice()));
+
+ String title = context.getString(R.string.bluetooth_disable_profile_title);
+ String message = context.getString(R.string.bluetooth_disable_profile_message,
+ profileName, name);
DialogInterface.OnClickListener disconnectListener =
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
device.disconnect(profile);
+ profile.setPreferred(device.getDevice(), false);
}
};
mDisconnectDialog = Utils.showDisconnectDialog(context,
- mDisconnectDialog, disconnectListener, name, message);
+ mDisconnectDialog, disconnectListener, title, Html.fromHtml(message));
}
public void onDeviceAttributesChanged() {
@@ -294,15 +298,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private void refresh() {
String deviceName = mCachedDevice.getName();
- // TODO: figure out how to update "bread crumb" title in action bar
-// FragmentTransaction transaction = getFragmentManager().openTransaction();
-// transaction.setBreadCrumbTitle(deviceName);
-// transaction.commit();
-
- findPreference(KEY_TITLE).setTitle(getString(
- R.string.bluetooth_device_advanced_title,
- deviceName));
- mDeviceNamePref = (EditTextPreference) findPreference(KEY_RENAME_DEVICE);
mDeviceNamePref.setSummary(deviceName);
mDeviceNamePref.setText(deviceName);
@@ -311,7 +306,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private void refreshProfiles() {
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
- Preference profilePref = findPreference(profile.toString());
+ CheckBoxPreference profilePref = (CheckBoxPreference)findPreference(profile.toString());
if (profilePref == null) {
profilePref = createProfilePreference(profile);
mProfileContainer.addPreference(profilePref);
@@ -326,15 +321,18 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mProfileContainer.removePreference(profilePref);
}
}
+ showOrHideProfileGroup();
}
- private void refreshProfilePreference(Preference profilePref, LocalBluetoothProfile profile) {
+ private void refreshProfilePreference(CheckBoxPreference profilePref,
+ LocalBluetoothProfile profile) {
BluetoothDevice device = mCachedDevice.getDevice();
/*
* Gray out checkbox while connecting and disconnecting
*/
profilePref.setEnabled(!mCachedDevice.isBusy());
+ profilePref.setChecked(mCachedDevice.isConnectedProfile(profile));
profilePref.setSummary(profile.getSummaryResourceForDevice(device));
}
@@ -352,32 +350,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
}
}
- public void onClick(View v) {
- if (v.getTag() instanceof LocalBluetoothProfile) {
- LocalBluetoothProfile prof = (LocalBluetoothProfile) v.getTag();
- CheckBoxPreference autoConnectPref = mAutoConnectPrefs.get(prof);
- if (autoConnectPref == null) {
- autoConnectPref = new CheckBoxPreference(getActivity());
- autoConnectPref.setLayoutResource(com.android.internal.R.layout.preference_child);
- autoConnectPref.setKey(prof.toString());
- autoConnectPref.setTitle(R.string.bluetooth_auto_connect);
- autoConnectPref.setOrder(getProfilePreferenceIndex(prof.getOrdinal()) + 1);
- autoConnectPref.setChecked(getAutoConnect(prof));
- autoConnectPref.setOnPreferenceChangeListener(this);
- mAutoConnectPrefs.put(prof, autoConnectPref);
- }
- BluetoothProfilePreference profilePref =
- (BluetoothProfilePreference) findPreference(prof.toString());
- if (profilePref != null) {
- if (profilePref.isExpanded()) {
- mProfileContainer.addPreference(autoConnectPref);
- } else {
- mProfileContainer.removePreference(autoConnectPref);
- }
- }
- }
- }
-
private int getProfilePreferenceIndex(int profIndex) {
return mProfileContainer.getOrder() + profIndex * 10;
}
@@ -386,18 +358,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mCachedDevice.unpair();
}
- /*
- private void setIncomingFileTransfersAllowed(boolean allow) {
- // TODO: make an IPC call into BluetoothOpp to update
- Log.d(TAG, "Set allow incoming = " + allow);
- }
-
- private boolean isIncomingFileTransfersAllowed() {
- // TODO: get this value from BluetoothOpp ???
- return true;
- }
- */
-
private boolean getAutoConnect(LocalBluetoothProfile prof) {
return prof.isPreferred(mCachedDevice.getDevice());
}
diff --git a/src/com/android/settings/bluetooth/HeadsetProfile.java b/src/com/android/settings/bluetooth/HeadsetProfile.java
index 13dce335cf2..99d070b9b27 100644
--- a/src/com/android/settings/bluetooth/HeadsetProfile.java
+++ b/src/com/android/settings/bluetooth/HeadsetProfile.java
@@ -170,14 +170,10 @@ final class HeadsetProfile implements LocalBluetoothProfile {
return ORDINAL;
}
- public int getNameResource() {
+ public int getNameResource(BluetoothDevice device) {
return R.string.bluetooth_profile_headset;
}
- public int getDisconnectResource(BluetoothDevice device) {
- return R.string.bluetooth_disconnect_headset_profile;
- }
-
public int getSummaryResourceForDevice(BluetoothDevice device) {
int state = mService.getConnectionState(device);
switch (state) {
diff --git a/src/com/android/settings/bluetooth/HidProfile.java b/src/com/android/settings/bluetooth/HidProfile.java
index 13d3db9dffe..920f4bbc062 100644
--- a/src/com/android/settings/bluetooth/HidProfile.java
+++ b/src/com/android/settings/bluetooth/HidProfile.java
@@ -112,14 +112,11 @@ final class HidProfile implements LocalBluetoothProfile {
return ORDINAL;
}
- public int getNameResource() {
+ public int getNameResource(BluetoothDevice device) {
+ // TODO: distinguish between keyboard and mouse?
return R.string.bluetooth_profile_hid;
}
- public int getDisconnectResource(BluetoothDevice device) {
- return R.string.bluetooth_disconnect_hid_profile;
- }
-
public int getSummaryResourceForDevice(BluetoothDevice device) {
int state = mService.getConnectionState(device);
switch (state) {
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfile.java b/src/com/android/settings/bluetooth/LocalBluetoothProfile.java
index 878a032b443..8c0de95d94c 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothProfile.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothProfile.java
@@ -54,15 +54,9 @@ interface LocalBluetoothProfile {
/**
* Returns the string resource ID for the localized name for this profile.
+ * @param device the Bluetooth device (to distinguish between PAN roles)
*/
- int getNameResource();
-
- /**
- * Returns the string resource ID for the disconnect confirmation text
- * for this profile.
- * @param device
- */
- int getDisconnectResource(BluetoothDevice device);
+ int getNameResource(BluetoothDevice device);
/**
* Returns the string resource ID for the summary text for this profile
diff --git a/src/com/android/settings/bluetooth/OppProfile.java b/src/com/android/settings/bluetooth/OppProfile.java
index eb5900e0e14..7ee2ad1b745 100644
--- a/src/com/android/settings/bluetooth/OppProfile.java
+++ b/src/com/android/settings/bluetooth/OppProfile.java
@@ -75,14 +75,10 @@ final class OppProfile implements LocalBluetoothProfile {
return ORDINAL;
}
- public int getNameResource() {
+ public int getNameResource(BluetoothDevice device) {
return R.string.bluetooth_profile_opp;
}
- public int getDisconnectResource(BluetoothDevice device) {
- return 0; // user must use notification to disconnect OPP transfer.
- }
-
public int getSummaryResourceForDevice(BluetoothDevice device) {
return 0; // OPP profile not displayed in UI
}
diff --git a/src/com/android/settings/bluetooth/PanProfile.java b/src/com/android/settings/bluetooth/PanProfile.java
index 6cb1991efbd..3db4a2bf100 100644
--- a/src/com/android/settings/bluetooth/PanProfile.java
+++ b/src/com/android/settings/bluetooth/PanProfile.java
@@ -112,15 +112,11 @@ final class PanProfile implements LocalBluetoothProfile {
return ORDINAL;
}
- public int getNameResource() {
- return R.string.bluetooth_profile_pan;
- }
-
- public int getDisconnectResource(BluetoothDevice device) {
+ public int getNameResource(BluetoothDevice device) {
if (isLocalRoleNap(device)) {
- return R.string.bluetooth_disconnect_pan_nap_profile;
+ return R.string.bluetooth_profile_pan_nap;
} else {
- return R.string.bluetooth_disconnect_pan_user_profile;
+ return R.string.bluetooth_profile_pan;
}
}