private void close() { if (hrProvider != null) { log(hrProvider.getProviderName() + ".close()"); hrProvider.close(); hrProvider = null; } }
private void save() { Resources res = getResources(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Editor ed = prefs.edit(); ed.putString(res.getString(R.string.pref_bt_name), btName); ed.putString(res.getString(R.string.pref_bt_address), btAddress); ed.putString(res.getString(R.string.pref_bt_provider), hrProvider.getProviderName()); ed.commit(); }
private void startScan() { log(hrProvider.getProviderName() + ".startScan()"); updateView(); deviceAdapter.deviceList.clear(); hrProvider.startScan(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Scanning"); builder.setPositiveButton( "Connect", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { log(hrProvider.getProviderName() + ".stopScan()"); hrProvider.stopScan(); connect(); updateView(); dialog.dismiss(); } }); if (hrProvider.isBondingDevice()) { builder.setNeutralButton( "Pairing", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); Intent i = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS); startActivityForResult(i, 123); } }); } builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { log(hrProvider.getProviderName() + ".stopScan()"); hrProvider.stopScan(); load(); open(); dialog.dismiss(); updateView(); } }); builder.setSingleChoiceItems( deviceAdapter, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { HRDeviceRef hrDevice = deviceAdapter.deviceList.get(arg1); btAddress = hrDevice.getAddress(); btName = hrDevice.getName(); } }); builder.show(); }
@Override public void onConnectResult(boolean connectOK) { log(hrProvider.getProviderName() + "::onConnectResult(" + connectOK + ")"); if (connectOK) { save(); startTimer(); } else { } updateView(); }
@Override public void onOpenResult(boolean ok) { log(hrProvider.getProviderName() + "::onOpenResult(" + ok + ")"); if (mIsScanning) { mIsScanning = false; startScan(); return; } updateView(); }
@Override public void onScanResult(HRDeviceRef device) { log( hrProvider.getProviderName() + "::onScanResult(" + device.getAddress() + ", " + device.getName() + ")"); deviceAdapter.deviceList.add(device); deviceAdapter.notifyDataSetChanged(); }
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(); }
private void open() { if (hrProvider != null && !hrProvider.isEnabled()) { if (hrProvider.startEnableIntent(this, 0) == true) { return; } hrProvider = null; } if (hrProvider != null) { log(hrProvider.getProviderName() + ".open(this)"); hrProvider.open(handler, this); } else { updateView(); } }
@Override public void onCloseResult(boolean closeOK) { log(hrProvider.getProviderName() + "::onCloseResult(" + closeOK + ")"); }
@Override public void onDisconnectResult(boolean disconnectOK) { log(hrProvider.getProviderName() + "::onDisconnectResult(" + disconnectOK + ")"); }