Ejemplo n.º 1
0
 private void close() {
   if (hrProvider != null) {
     log(hrProvider.getProviderName() + ".close()");
     hrProvider.close();
     hrProvider = null;
   }
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
  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();
  }
Ejemplo n.º 4
0
 @Override
 public void onConnectResult(boolean connectOK) {
   log(hrProvider.getProviderName() + "::onConnectResult(" + connectOK + ")");
   if (connectOK) {
     save();
     startTimer();
   } else {
   }
   updateView();
 }
Ejemplo n.º 5
0
  @Override
  public void onOpenResult(boolean ok) {
    log(hrProvider.getProviderName() + "::onOpenResult(" + ok + ")");
    if (mIsScanning) {
      mIsScanning = false;
      startScan();
      return;
    }

    updateView();
  }
Ejemplo n.º 6
0
 @Override
 public void onScanResult(HRDeviceRef device) {
   log(
       hrProvider.getProviderName()
           + "::onScanResult("
           + device.getAddress()
           + ", "
           + device.getName()
           + ")");
   deviceAdapter.deviceList.add(device);
   deviceAdapter.notifyDataSetChanged();
 }
Ejemplo n.º 7
0
  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();
  }
Ejemplo n.º 8
0
 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();
   }
 }
Ejemplo n.º 9
0
 @Override
 public void onCloseResult(boolean closeOK) {
   log(hrProvider.getProviderName() + "::onCloseResult(" + closeOK + ")");
 }
Ejemplo n.º 10
0
 @Override
 public void onDisconnectResult(boolean disconnectOK) {
   log(hrProvider.getProviderName() + "::onDisconnectResult(" + disconnectOK + ")");
 }