Search in sources :

Example 1 with BluetoothCentralManager

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);
}
Also used : BluetoothCentralManager(com.welie.blessed.BluetoothCentralManager) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Aggregations

Intent (android.content.Intent)1 Handler (android.os.Handler)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BluetoothCentralManager (com.welie.blessed.BluetoothCentralManager)1