Refactor Bluetooth settings
Two lists: paired devices and available devices. New item at top for the device itself (not connected to discoverable, this is a larger refactoring). New settings icon. Change-Id: I788a6c0afdb07309d449a4d41a02cf8480c95a37
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 773 B |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 653 B |
@@ -955,10 +955,10 @@
|
|||||||
<string name="bluetooth_searching_for_devices">Searching\u2026</string>
|
<string name="bluetooth_searching_for_devices">Searching\u2026</string>
|
||||||
<!-- Bluetooth settings: The sub heading for device settings. [CHAR LIMIT=30] -->
|
<!-- Bluetooth settings: The sub heading for device settings. [CHAR LIMIT=30] -->
|
||||||
<string name="bluetooth_preference_device_settings">Device settings</string>
|
<string name="bluetooth_preference_device_settings">Device settings</string>
|
||||||
<!-- Bluetooth settings: The sub heading for paired devices. [CHAR LIMIT=30] -->
|
<!-- Bluetooth settings: The sub heading for devices which have already been paired with this device. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_preference_paired_devices">Paired devices</string>
|
<string name="bluetooth_preference_paired_devices">Paired devices</string>
|
||||||
<!-- Bluetooth settings: The sub heading for found devices when scanning. [CHAR LIMIT=30] -->
|
<!-- Bluetooth settings: The sub heading for available devices during and after scanning. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_preference_found_devices">Found devices</string>
|
<string name="bluetooth_preference_found_devices">Available devices</string>
|
||||||
<!-- Bluetooth settings. Context menu item for a device. Action will connect to all profiles on the device. -->
|
<!-- Bluetooth settings. Context menu item for a device. Action will connect to all profiles on the device. -->
|
||||||
<string name="bluetooth_device_context_connect">Connect</string>
|
<string name="bluetooth_device_context_connect">Connect</string>
|
||||||
<!-- Bluetooth settings. Context menu item for a device. Action will disconnect from all profiles on the device. -->
|
<!-- Bluetooth settings. Context menu item for a device. Action will disconnect from all profiles on the device. -->
|
||||||
|
@@ -23,6 +23,7 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -51,8 +52,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
|
|
||||||
private BluetoothEnabler mBluetoothEnabler;
|
private BluetoothEnabler mBluetoothEnabler;
|
||||||
|
|
||||||
private PreferenceGroup mFoundDevicesCategory;
|
private PreferenceGroup mAvailableDevicesCategory;
|
||||||
private boolean mFoundDevicesCategoryIsPresent;
|
private boolean mAvailableDevicesCategoryIsPresent;
|
||||||
|
|
||||||
private View mView;
|
private View mView;
|
||||||
private TextView mEmptyView;
|
private TextView mEmptyView;
|
||||||
@@ -97,10 +98,6 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
|
|
||||||
mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);
|
mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);
|
||||||
|
|
||||||
if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
|
|
||||||
activity.getActionBar().setSubtitle(mLocalAdapter.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,8 +156,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startScanning() {
|
private void startScanning() {
|
||||||
if (!mFoundDevicesCategoryIsPresent) {
|
if (!mAvailableDevicesCategoryIsPresent) {
|
||||||
getPreferenceScreen().addPreference(mFoundDevicesCategory);
|
getPreferenceScreen().addPreference(mAvailableDevicesCategory);
|
||||||
}
|
}
|
||||||
mLocalAdapter.startScanning(true);
|
mLocalAdapter.startScanning(true);
|
||||||
}
|
}
|
||||||
@@ -171,6 +168,16 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
super.onDevicePreferenceClick(btPreference);
|
super.onDevicePreferenceClick(btPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addDeviceCategory(PreferenceGroup preferenceGroup, int titleId,
|
||||||
|
BluetoothDeviceFilter.Filter filter) {
|
||||||
|
preferenceGroup.setTitle(titleId);
|
||||||
|
getPreferenceScreen().addPreference(preferenceGroup);
|
||||||
|
setFilter(filter);
|
||||||
|
setDeviceListGroup(preferenceGroup);
|
||||||
|
addCachedDevices();
|
||||||
|
preferenceGroup.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateContent(int bluetoothState) {
|
private void updateContent(int bluetoothState) {
|
||||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||||
getActivity().invalidateOptionsMenu();
|
getActivity().invalidateOptionsMenu();
|
||||||
@@ -179,42 +186,58 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
switch (bluetoothState) {
|
switch (bluetoothState) {
|
||||||
case BluetoothAdapter.STATE_ON:
|
case BluetoothAdapter.STATE_ON:
|
||||||
preferenceScreen.removeAll();
|
preferenceScreen.removeAll();
|
||||||
|
|
||||||
// Add bonded devices from cache first
|
|
||||||
setFilter(BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
|
|
||||||
setDeviceListGroup(preferenceScreen);
|
|
||||||
preferenceScreen.setOrderingAsAdded(true);
|
preferenceScreen.setOrderingAsAdded(true);
|
||||||
|
|
||||||
addCachedDevices();
|
// This device
|
||||||
int numberOfPairedDevices = preferenceScreen.getPreferenceCount();
|
if (mMyDevicePreference == null) {
|
||||||
|
mMyDevicePreference = new Preference(getActivity());
|
||||||
|
}
|
||||||
|
if (mLocalAdapter != null) {
|
||||||
|
mMyDevicePreference.setTitle(mLocalAdapter.getName());
|
||||||
|
}
|
||||||
|
mMyDevicePreference.setEnabled(true);
|
||||||
|
preferenceScreen.addPreference(mMyDevicePreference);
|
||||||
|
|
||||||
// Found devices category
|
// Paired devices category
|
||||||
mFoundDevicesCategory = new ProgressCategory(getActivity(), null);
|
if (mPairedDevicesCategory == null) {
|
||||||
mFoundDevicesCategory.setTitle(R.string.bluetooth_preference_found_devices);
|
mPairedDevicesCategory = new PreferenceCategory(getActivity());
|
||||||
preferenceScreen.addPreference(mFoundDevicesCategory);
|
} else {
|
||||||
mFoundDevicesCategoryIsPresent = true;
|
mPairedDevicesCategory.removeAll();
|
||||||
|
}
|
||||||
|
addDeviceCategory(mPairedDevicesCategory,
|
||||||
|
R.string.bluetooth_preference_paired_devices,
|
||||||
|
BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
|
||||||
|
int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();
|
||||||
|
|
||||||
// Unbonded found devices from cache
|
// Available devices category
|
||||||
setFilter(BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
|
if (mAvailableDevicesCategory == null) {
|
||||||
setDeviceListGroup(mFoundDevicesCategory);
|
mAvailableDevicesCategory = new ProgressCategory(getActivity(), null);
|
||||||
addCachedDevices();
|
} else {
|
||||||
|
mAvailableDevicesCategory.removeAll();
|
||||||
|
}
|
||||||
|
addDeviceCategory(mAvailableDevicesCategory,
|
||||||
|
R.string.bluetooth_preference_found_devices,
|
||||||
|
BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
|
||||||
|
int numberOfAvailableDevices = mAvailableDevicesCategory.getPreferenceCount();
|
||||||
|
mAvailableDevicesCategoryIsPresent = true;
|
||||||
|
|
||||||
int numberOfUnpairedDevices = mFoundDevicesCategory.getPreferenceCount();
|
if (numberOfAvailableDevices == 0) {
|
||||||
if (numberOfUnpairedDevices == 0) {
|
preferenceScreen.removePreference(mAvailableDevicesCategory);
|
||||||
preferenceScreen.removePreference(mFoundDevicesCategory);
|
mAvailableDevicesCategoryIsPresent = false;
|
||||||
mFoundDevicesCategoryIsPresent = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberOfPairedDevices == 0) startScanning();
|
if (numberOfPairedDevices == 0) {
|
||||||
|
preferenceScreen.removePreference(mPairedDevicesCategory);
|
||||||
return;
|
startScanning();
|
||||||
|
}
|
||||||
|
return; // not break
|
||||||
|
|
||||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||||
int preferenceCount = preferenceScreen.getPreferenceCount();
|
int preferenceCount = preferenceScreen.getPreferenceCount();
|
||||||
for (int i = 0; i < preferenceCount; i++) {
|
for (int i = 0; i < preferenceCount; i++) {
|
||||||
preferenceScreen.getPreference(i).setEnabled(false);
|
preferenceScreen.getPreference(i).setEnabled(false);
|
||||||
}
|
}
|
||||||
return;
|
return; // not break
|
||||||
|
|
||||||
case BluetoothAdapter.STATE_OFF:
|
case BluetoothAdapter.STATE_OFF:
|
||||||
messageId = R.string.bluetooth_empty_list_bluetooth_off;
|
messageId = R.string.bluetooth_empty_list_bluetooth_off;
|
||||||
@@ -268,6 +291,10 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Preference mMyDevicePreference;
|
||||||
|
|
||||||
|
private PreferenceGroup mPairedDevicesCategory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a listener, which enables the advanced settings icon.
|
* Add a listener, which enables the advanced settings icon.
|
||||||
* @param preference the newly added preference
|
* @param preference the newly added preference
|
||||||
|
Reference in New Issue
Block a user