Esempio n. 1
0
 @Override
 public void onServicesReady(String macAddress) {
   gattProviderNews.registerConnGattSub(gattListenWeather);
   gattProviderNews.getGattCharacteristicRead(
       Constants.WEATHER.GATT_SERVICE_WEATHER.getUuid(),
       Constants.WEATHER.GATT_WEATHER_TODAY.getUuid());
 }
Esempio n. 2
0
  @Override
  public void onScanResultReceived(ScanResult result) {
    Log.d(TAG, "onScanResultReceived: " + result.getDevice().getAddress());
    findViewById(R.id.txt_headline_displays).setVisibility(View.VISIBLE);
    for (BlData b : rcycAdaptDevices.getBlData()) {
      if (b.isActive() && b.getAddress().equals(result.getDevice().getAddress())) {
        return;
      }
    }
    BlData data = new BlData();
    data.setActive(true);
    data.setAddress(result.getDevice().getAddress());
    data.setRssi(result.getRssi());
    //noinspection ConstantConditions
    data.setAdvertisement(
        result.getScanRecord().getServiceData(Constants.UUID_ADVERT_SERVICE_MULTI));
    App.holder()
        .access(
            App.holder().new HolderAccess() {
              private BlData data;
              private ScanResult result;

              public HolderBlData.HolderAccess init(BlData data, ScanResult result) {
                this.data = data;
                this.result = result;
                return this;
              }

              @Override
              public void onRun() {
                Iterator<BlData> i = getData();
                boolean found = false;
                while (i.hasNext()) {
                  BlData b = i.next();
                  if (b.getAddress().equals(data.getAddress())) {
                    if (!b.isActive()) {
                      Intent showIntent =
                          new Intent(getString(R.string.intent_advert_gatt_connect));
                      showIntent.putExtra(getString(R.string.bndl_bl_scan_result), result);
                      LocalBroadcastManager.getInstance(ActScan.this).sendBroadcast(showIntent);
                    }
                    b.setActive(true);
                    found = true;
                    break;
                  }
                }
                if (!found) {
                  Log.d(TAG, "Display not found and will be added: " + data.getAddress());
                  SoundPlayer.playExampleBeep(440, 1, 0);
                  VibratorBuilder.vibrate(VibratorBuilder.SHORT_SHORT);
                  addData(data);
                  Intent showIntent = new Intent(getString(R.string.intent_advert_gatt_connect));
                  showIntent.putExtra(getString(R.string.bndl_bl_scan_result), result);
                  LocalBroadcastManager.getInstance(ActScan.this).sendBroadcast(showIntent);
                }
              }
            }.init(data, result));

    if (gattListenWeather == null) {
      gattProviderWeather =
          service.subscribeGattConnection(
              Constants.WEATHER.GATT_SERVICE_WEATHER.getUuid(),
              gattListenWeather = new GattWeather());
    }
    if (gattListenShout == null) {
      gattProviderShout =
          service.subscribeGattConnection(
              Constants.SHOUT.GATT_SERVICE_SHOUT.getUuid(), gattListenShout = new GattShout());
    }
    if (gattListenNews == null) {
      gattProviderNews =
          service.subscribeGattConnection(
              Constants.NEWS.GATT_SERVICE_NEWS.getUuid(), gattListenNews = new GattNews());
    }
    if (gattListenBooking == null) {
      gattProviderBooking =
          service.subscribeGattConnection(
              Constants.BOOKING.GATT_SERVICE_BOOKING.getUuid(),
              gattListenBooking = new GattBooking());
    }
  }