BT device picker: don't rescan after rotating the device

The Bluetooth device picker was restarting the device scan after
the screen is rotated. Fix this by only starting the scan when the
savedInstanceState Bundle passed to onCreate() is null.

Also removes "No Bluetooth devices were found nearby" from list if
the user switches to a different app and then switches back to
the device picker.

Bug: 5249380
Change-Id: I8959c850649eb713fb930ee0a8a7bcb73ca7c1aa
This commit is contained in:
Jake Hamby
2011-09-06 15:38:23 -07:00
parent 491af0805d
commit de53b46b16
2 changed files with 8 additions and 4 deletions

View File

@@ -45,13 +45,13 @@ public class ProgressCategory extends ProgressCategoryBase {
textView.setVisibility(noDeviceFound ? View.INVISIBLE : View.VISIBLE); textView.setVisibility(noDeviceFound ? View.INVISIBLE : View.VISIBLE);
progressBar.setVisibility(mProgress ? View.VISIBLE : View.INVISIBLE); progressBar.setVisibility(mProgress ? View.VISIBLE : View.INVISIBLE);
if (mProgress) { if (mProgress || !noDeviceFound) {
if (mNoDeviceFoundAdded) { if (mNoDeviceFoundAdded) {
removePreference(mNoDeviceFoundPreference); removePreference(mNoDeviceFoundPreference);
mNoDeviceFoundAdded = false; mNoDeviceFoundAdded = false;
} }
} else { } else {
if (noDeviceFound && !mNoDeviceFoundAdded) { if (!mNoDeviceFoundAdded) {
if (mNoDeviceFoundPreference == null) { if (mNoDeviceFoundPreference == null) {
mNoDeviceFoundPreference = new Preference(getContext()); mNoDeviceFoundPreference = new Preference(getContext());
mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list); mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list);
@@ -70,4 +70,3 @@ public class ProgressCategory extends ProgressCategoryBase {
notifyChanged(); notifyChanged();
} }
} }

View File

@@ -33,6 +33,7 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
private boolean mNeedAuth; private boolean mNeedAuth;
private String mLaunchPackage; private String mLaunchPackage;
private String mLaunchClass; private String mLaunchClass;
private boolean mStartScanOnResume;
@Override @Override
void addPreferencesForActivity() { void addPreferencesForActivity() {
@@ -50,13 +51,17 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActivity().setTitle(getString(R.string.device_picker)); getActivity().setTitle(getString(R.string.device_picker));
mStartScanOnResume = (savedInstanceState == null); // don't start scan after rotation
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
addCachedDevices(); addCachedDevices();
if (mStartScanOnResume) {
mLocalAdapter.startScanning(true); mLocalAdapter.startScanning(true);
mStartScanOnResume = false;
}
} }
@Override @Override