import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.util.Log;
private BluetoothEnabler mBluetoothEnabler;
- private PreferenceGroup mFoundDevicesCategory;
- private boolean mFoundDevicesCategoryIsPresent;
+ private PreferenceGroup mAvailableDevicesCategory;
+ private boolean mAvailableDevicesCategoryIsPresent;
private View mView;
private TextView mEmptyView;
mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);
- if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
- activity.getActionBar().setSubtitle(mLocalAdapter.getName());
- }
-
setHasOptionsMenu(true);
}
}
private void startScanning() {
- if (!mFoundDevicesCategoryIsPresent) {
- getPreferenceScreen().addPreference(mFoundDevicesCategory);
+ if (!mAvailableDevicesCategoryIsPresent) {
+ getPreferenceScreen().addPreference(mAvailableDevicesCategory);
}
mLocalAdapter.startScanning(true);
}
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) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
getActivity().invalidateOptionsMenu();
switch (bluetoothState) {
case BluetoothAdapter.STATE_ON:
preferenceScreen.removeAll();
-
- // Add bonded devices from cache first
- setFilter(BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
- setDeviceListGroup(preferenceScreen);
preferenceScreen.setOrderingAsAdded(true);
- addCachedDevices();
- int numberOfPairedDevices = preferenceScreen.getPreferenceCount();
-
- // Found devices category
- mFoundDevicesCategory = new ProgressCategory(getActivity(), null);
- mFoundDevicesCategory.setTitle(R.string.bluetooth_preference_found_devices);
- preferenceScreen.addPreference(mFoundDevicesCategory);
- mFoundDevicesCategoryIsPresent = true;
-
- // Unbonded found devices from cache
- setFilter(BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
- setDeviceListGroup(mFoundDevicesCategory);
- addCachedDevices();
-
- int numberOfUnpairedDevices = mFoundDevicesCategory.getPreferenceCount();
- if (numberOfUnpairedDevices == 0) {
- preferenceScreen.removePreference(mFoundDevicesCategory);
- mFoundDevicesCategoryIsPresent = false;
+ // This device
+ if (mMyDevicePreference == null) {
+ mMyDevicePreference = new Preference(getActivity());
+ }
+ if (mLocalAdapter != null) {
+ mMyDevicePreference.setTitle(mLocalAdapter.getName());
}
+ mMyDevicePreference.setEnabled(true);
+ preferenceScreen.addPreference(mMyDevicePreference);
- if (numberOfPairedDevices == 0) startScanning();
+ // Paired devices category
+ if (mPairedDevicesCategory == null) {
+ mPairedDevicesCategory = new PreferenceCategory(getActivity());
+ } else {
+ mPairedDevicesCategory.removeAll();
+ }
+ addDeviceCategory(mPairedDevicesCategory,
+ R.string.bluetooth_preference_paired_devices,
+ BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
+ int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();
+
+ // Available devices category
+ if (mAvailableDevicesCategory == null) {
+ mAvailableDevicesCategory = new ProgressCategory(getActivity(), null);
+ } else {
+ mAvailableDevicesCategory.removeAll();
+ }
+ addDeviceCategory(mAvailableDevicesCategory,
+ R.string.bluetooth_preference_found_devices,
+ BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
+ int numberOfAvailableDevices = mAvailableDevicesCategory.getPreferenceCount();
+ mAvailableDevicesCategoryIsPresent = true;
+
+ if (numberOfAvailableDevices == 0) {
+ preferenceScreen.removePreference(mAvailableDevicesCategory);
+ mAvailableDevicesCategoryIsPresent = false;
+ }
- return;
+ if (numberOfPairedDevices == 0) {
+ preferenceScreen.removePreference(mPairedDevicesCategory);
+ startScanning();
+ }
+ return; // not break
case BluetoothAdapter.STATE_TURNING_OFF:
int preferenceCount = preferenceScreen.getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
preferenceScreen.getPreference(i).setEnabled(false);
}
- return;
+ return; // not break
case BluetoothAdapter.STATE_OFF:
messageId = R.string.bluetooth_empty_list_bluetooth_off;
}
};
+ private Preference mMyDevicePreference;
+
+ private PreferenceGroup mPairedDevicesCategory;
+
/**
* Add a listener, which enables the advanced settings icon.
* @param preference the newly added preference