protected void onListItemClick(int position) {
    iBeaconClass.iBeacon device = mLeDeviceListAdapter.getDevice(position);
    if (device == null) return;

    if (!device.name.equals("pBeacon_n")) {
      Toast.makeText(MainActivity.this, "The iBeacon is not connectable", Toast.LENGTH_LONG).show();
      return;
    }

    Intent intent = new Intent(this, DeviceControlActivity.class);

    Bundle bundle = new Bundle();
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.bluetoothAddress);
    intent.putExtras(bundle);

    if (mScanning) {
      // ask scan service to stop scanning
      Intent intent1 = new Intent(BluetoothLeScanService.SCAN_COMMAND_ACTION);
      intent1.putExtra(
          BluetoothLeScanService.SCAN_COMMAND_ACTION, BluetoothLeScanService.SCAN_COMMAND_STOP);
      LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(intent1);
      mScanning = false;
    }
    startActivity(intent);
  }
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
   if (device == null) return;
   final Intent intent = new Intent(this, DeviceControlActivity.class);
   intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
   intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
   if (mScanning) {
     mBluetoothAdapter.stopLeScan(mLeScanCallback);
     mScanning = false;
   }
   startActivity(intent);
 }
Beispiel #3
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    Log.d(TAG, "Item Clicked");
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null || device.getName() == null) return;
    Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show();

    ActiveBluetoothDevice btDevice =
        new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();

    final SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    prefs.edit().putString("last_connected_device_address", device.getAddress()).apply();
    if (btDevice == null) {
      ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
      newBtDevice.name = device.getName();
      newBtDevice.address = device.getAddress();
      newBtDevice.save();
    } else {
      btDevice.name = device.getName();
      btDevice.address = device.getAddress();
      btDevice.save();
    }
    if (device.getName().toLowerCase().contains("dexcom")) {
      if (!CollectionServiceStarter.isBTShare(getApplicationContext())) {
        prefs.edit().putString("dex_collection_method", "DexcomShare").apply();
        prefs.edit().putBoolean("calibration_notifications", false).apply();
      }
      if (prefs.getString("share_key", "SM00000000").compareTo("SM00000000") == 0
          || prefs.getString("share_key", "SM00000000").length() < 10) {
        requestSerialNumber(prefs);
      } else returnToHome();

    } else if (device.getName().toLowerCase().contains("bridge")) {
      if (!CollectionServiceStarter.isDexbridgeWixel(getApplicationContext()))
        prefs.edit().putString("dex_collection_method", "DexbridgeWixel").apply();
      if (prefs.getString("dex_txid", "00000").compareTo("00000") == 0
          || prefs.getString("dex_txid", "00000").length() < 5) {
        requestTransmitterId(prefs);
      } else returnToHome();

    } else if (device.getName().toLowerCase().contains("drip")) {
      if (!(CollectionServiceStarter.isBTWixel(getApplicationContext())
          || CollectionServiceStarter.isWifiandBTWixel(getApplicationContext()))) {
        prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply();
      }
      returnToHome();
    } else {
      returnToHome();
    }
  }