use of com.welie.blessed.BluetoothCentralManager in project openScale by oliexdev.
the class BluetoothSettingsFragment method startBluetoothDiscovery.
private void startBluetoothDiscovery() {
deviceListView.removeAllViews();
foundDevices.clear();
central = new BluetoothCentralManager(requireContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
central.scanForPeripherals();
txtSearching.setVisibility(View.VISIBLE);
txtSearching.setText(R.string.label_bluetooth_searching);
progressBar.setVisibility(View.VISIBLE);
progressHandler = new Handler();
// Don't let the BLE discovery run forever
progressHandler.postDelayed(new Runnable() {
@Override
public void run() {
stopBluetoothDiscovery();
txtSearching.setText(R.string.label_bluetooth_searching_finished);
progressBar.setVisibility(View.GONE);
new Handler().post(new Runnable() {
@Override
public void run() {
try {
BluetoothDeviceView notSupported = new BluetoothDeviceView(requireContext());
notSupported.setDeviceName(requireContext().getString(R.string.label_scale_not_supported));
notSupported.setSummaryText(requireContext().getString(R.string.label_click_to_help_add_support));
notSupported.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent notSupportedIntent = new Intent(Intent.ACTION_VIEW);
notSupportedIntent.setData(Uri.parse("https://github.com/oliexdev/openScale/wiki/Supported-scales-in-openScale"));
startActivity(notSupportedIntent);
}
});
deviceListView.addView(notSupported);
} catch (IllegalStateException ex) {
Timber.e(ex.getMessage());
}
}
});
}
}, 20 * 1000);
}