package io.trygvis.android.bt; import android.bluetooth.BluetoothDevice; import android.util.Log; import io.trygvis.android.Function; public class BtDevice { private final static String TAG = BtDevice.class.getSimpleName(); private final DefaultBtService btService; private final BluetoothDevice bluetoothDevice; private Integer rssi; private BtScanResult scanResult; private A tag; private boolean seenNow; public static interface BtDeviceWrapper { BtDevice getBtDevice(); } BtDevice(DefaultBtService btService, BluetoothDevice bluetoothDevice, Function, A> tagConstructor, Integer rssi, BtScanResult scanResult) { this.btService = btService; this.bluetoothDevice = bluetoothDevice; this.tag = tagConstructor.apply(this); this.rssi = rssi; this.scanResult = scanResult; } public A getTag() { return tag; } public String getAddress() { return bluetoothDevice.getAddress(); } public String getName() { return bluetoothDevice.getName(); } public int getRssi() { return rssi; } public boolean connect(BtActionExecutor executor) { Log.i(TAG, "connect(), address=" + bluetoothDevice.getAddress() + ", queue=" + executor); bluetoothDevice.connectGatt(btService, false, executor.asCallback()); return true; } public BtScanResult getScanResult() { return scanResult; } @Override public String toString() { return "BtDevice{address=" + bluetoothDevice.getAddress() + '}'; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } BtDevice other = (BtDevice) o; return getAddress().equals(other.getAddress()); } @Override public int hashCode() { return getAddress().hashCode(); } }