1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-24 01:03:20 +02:00

Don't crash if screen is rotated during scan

For simplicity the scan result is lost if screen is rotated. Hopefully
not a big issue.
This commit is contained in:
Erik Johansson
2018-04-13 19:19:38 +02:00
parent 0e7376a678
commit 8d7d1157c7

View File

@@ -66,6 +66,7 @@ public class BluetoothPreferences extends PreferenceFragment {
scanning.setEnabled(false); scanning.setEnabled(false);
btScanner.addPreference(scanning); btScanner.addPreference(scanning);
// Draw a simple progressbar during the discovery/scanning
final int progressUpdatePeriod = 150; final int progressUpdatePeriod = 150;
final String[] blocks = {"","","","","","","",""}; final String[] blocks = {"","","","","","","",""};
scanning.setSummary(blocks[0]); scanning.setSummary(blocks[0]);
@@ -85,6 +86,7 @@ public class BluetoothPreferences extends PreferenceFragment {
} }
}, progressUpdatePeriod); }, progressUpdatePeriod);
// Close any existing connection during the scan
OpenScale.getInstance(getActivity()).disconnectFromBluetoothDevice(); OpenScale.getInstance(getActivity()).disconnectFromBluetoothDevice();
btScanner.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() { btScanner.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@@ -113,6 +115,7 @@ public class BluetoothPreferences extends PreferenceFragment {
public void run() { public void run() {
handler.removeCallbacksAndMessages(null); handler.removeCallbacksAndMessages(null);
btAdapter.stopLeScan(leScanCallback); btAdapter.stopLeScan(leScanCallback);
btScanner.getDialog().setOnDismissListener(null);
Preference scanning = btScanner.getPreference(0); Preference scanning = btScanner.getPreference(0);
scanning.setTitle(R.string.label_bluetooth_searching_finished); scanning.setTitle(R.string.label_bluetooth_searching_finished);
@@ -204,8 +207,7 @@ public class BluetoothPreferences extends PreferenceFragment {
if (btAdapter == null) { if (btAdapter == null) {
btScanner.setEnabled(false); btScanner.setEnabled(false);
btScanner.setSummary("Bluetooth " + getResources().getString(R.string.info_is_not_available)); btScanner.setSummary("Bluetooth " + getResources().getString(R.string.info_is_not_available));
} } else {
else {
// Might have been started by another app // Might have been started by another app
btAdapter.cancelDiscovery(); btAdapter.cancelDiscovery();
@@ -231,6 +233,11 @@ public class BluetoothPreferences extends PreferenceFragment {
// Dummy preference to make screen open // Dummy preference to make screen open
btScanner.addPreference(new Preference(getActivity())); btScanner.addPreference(new Preference(getActivity()));
} }
}
@Override
public void onResume() {
super.onResume();
// Intent filter for the scanning process // Intent filter for the scanning process
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
@@ -241,10 +248,13 @@ public class BluetoothPreferences extends PreferenceFragment {
} }
@Override @Override
public void onDestroy() { public void onPause() {
getActivity().unregisterReceiver(mReceiver); getActivity().unregisterReceiver(mReceiver);
if (btScanner.getDialog() != null) {
btScanner.getDialog().dismiss();
}
super.onDestroy(); super.onPause();
} }
@Override @Override