private void updateView() { if (hrProvider == null) { scanButton.setEnabled(true); connectButton.setEnabled(false); connectButton.setText("Connect"); tvBTName.setText(""); tvHR.setText(""); return; } if (btName != null) { tvBTName.setText(btName); } else { tvBTName.setText(""); tvHR.setText(""); } if (hrProvider.isConnected()) { connectButton.setText("Disconnect"); connectButton.setEnabled(true); } else if (hrProvider.isConnecting()) { connectButton.setEnabled(false); connectButton.setText("Connecting"); } else { connectButton.setEnabled(btName == null ? false : true); connectButton.setText("Connect"); } }
void connect() { stopTimer(); if (hrProvider == null || btName == null || btAddress == null) { updateView(); return; } if (hrProvider.isConnecting() || hrProvider.isConnected()) { log(hrProvider.getProviderName() + ".disconnect()"); hrProvider.disconnect(); updateView(); return; } tvBTName.setText(getName()); tvHR.setText("?"); String name = btName; if (name == null || name.length() == 0) { name = btAddress; } log(hrProvider.getProviderName() + ".connect(" + name + ")"); hrProvider.connect(HRDeviceRef.create(btProviderName, btName, btAddress)); updateView(); }