private PreferenceGroup mAvailableDevicesCategory;
private boolean mAvailableDevicesCategoryIsPresent;
+ private boolean mActivityStarted;
- private View mView;
private TextView mEmptyView;
private final IntentFilter mIntentFilter;
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- mView = inflater.inflate(R.layout.custom_preference_list_fragment, container, false);
- return mView;
- }
-
- @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
+ mActivityStarted = (savedInstanceState == null); // don't auto start scan after rotation
- mEmptyView = (TextView) mView.findViewById(R.id.empty);
+ mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(mEmptyView);
}
public void onResume() {
// resume BluetoothEnabler before calling super.onResume() so we don't get
// any onDeviceAdded() callbacks before setting up view in updateContent()
- mBluetoothEnabler.resume();
+ if (mBluetoothEnabler != null) {
+ mBluetoothEnabler.resume();
+ }
super.onResume();
if (mDiscoverableEnabler != null) {
mDiscoverableEnabler.resume();
}
getActivity().registerReceiver(mReceiver, mIntentFilter);
-
- updateContent(mLocalAdapter.getBluetoothState());
+ if (mLocalAdapter != null) {
+ updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
+ }
}
@Override
public void onPause() {
super.onPause();
- mBluetoothEnabler.pause();
+ if (mBluetoothEnabler != null) {
+ mBluetoothEnabler.pause();
+ }
getActivity().unregisterReceiver(mReceiver);
if (mDiscoverableEnabler != null) {
mDiscoverableEnabler.pause();
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ if (mLocalAdapter == null) return;
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
boolean isDiscovering = mLocalAdapter.isDiscovering();
int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
preferenceGroup.setEnabled(true);
}
- private void updateContent(int bluetoothState) {
+ private void updateContent(int bluetoothState, boolean scanState) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
int messageId = 0;
case BluetoothAdapter.STATE_ON:
preferenceScreen.removeAll();
preferenceScreen.setOrderingAsAdded(true);
+ mDevicePreferenceMap.clear();
// This device
if (mMyDevicePreference == null) {
if (numberOfPairedDevices == 0) {
preferenceScreen.removePreference(mPairedDevicesCategory);
- startScanning();
+ if (scanState == true) {
+ mActivityStarted = false;
+ startScanning();
+ } else {
+ if (!mAvailableDevicesCategoryIsPresent) {
+ getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+ }
+ }
}
getActivity().invalidateOptionsMenu();
return; // not break
@Override
public void onBluetoothStateChanged(int bluetoothState) {
super.onBluetoothStateChanged(bluetoothState);
- updateContent(bluetoothState);
+ updateContent(bluetoothState, true);
}
@Override
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
setDeviceListGroup(getPreferenceScreen());
removeAllDevices();
- updateContent(mLocalAdapter.getBluetoothState());
+ updateContent(mLocalAdapter.getBluetoothState(), false);
}
private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {