/** * Looks for the device with the same address as given one in the list of bonded devices. If the * device has been found it updates its RSSI value. * * @param address the device address * @param rssi the RSSI of the scanned device */ public void updateRssiOfBondedDevice(String address, int rssi) { comparator.address = address; final int indexInBonded = mListBondedValues.indexOf(comparator); if (indexInBonded >= 0) { ExtendedBluetoothDevice previousDevice = mListBondedValues.get(indexInBonded); previousDevice.rssi = rssi; notifyDataSetChanged(); } }
/** * If such device exists on the bonded device list, this method does nothing. If not then the * device is updated (rssi value) or added. * * @param results scan results */ public void update(final List<ScanResult> results) { for (final ScanResult result : results) { final ExtendedBluetoothDevice device = findDevice(result); if (device == null) { mDevices.add(new ExtendedBluetoothDevice(result)); } else { device.name = result.getScanRecord() != null ? result.getScanRecord().getDeviceName() : null; device.rssi = result.getRssi(); } } notifyDataSetChanged(); }
/** * If such device exists on the bonded device list, this method does nothing. If not then the * device is updated (rssi value) or added. * * @param device the device to be added or updated */ public void addOrUpdateDevice(ExtendedBluetoothDevice device) { final boolean indexInBonded = mListBondedValues.contains(device); if (indexInBonded) { return; } final int indexInNotBonded = mListValues.indexOf(device); if (indexInNotBonded >= 0) { ExtendedBluetoothDevice previousDevice = mListValues.get(indexInNotBonded); previousDevice.rssi = device.rssi; notifyDataSetChanged(); return; } mListValues.add(device); notifyDataSetChanged(); }
private ExtendedBluetoothDevice findDevice(final ScanResult result) { for (final ExtendedBluetoothDevice device : mDevices) if (device.matches(result)) return device; return null; }