Commit f41d1ef0 authored by y0no's avatar y0no
Browse files

Add fallback name for listView

Add getter/setter for device on DeviceInfo
Simplify addOrUpdateDevice method
parent 3387f2d5
......@@ -72,6 +72,7 @@ public class BtScanner {
@Override
public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice oBtDevice = result.getDevice();
Log.d(TAG, "Data: " + result.getScanRecord().toString());
addOrUpdateDevice(
oBtDevice,
result.getScanRecord().getBytes(),
......@@ -84,19 +85,23 @@ public class BtScanner {
private void addOrUpdateDevice(BluetoothDevice device, byte[] scanRecord,
long timestamp, int rssi){
DeviceInfo deviceInfo;
if(!m_oDetectedDevices.containsKey(device.getAddress())){
Log.d(TAG, "Add new device to list : " + device.getName());
DeviceInfo deviceInfo = new DeviceInfo(
deviceInfo = new DeviceInfo(
device, scanRecord, timestamp, rssi
);
m_oUiAdapter.add(deviceInfo);
m_oDetectedDevices.put(device.getAddress(), deviceInfo);
} else {
Log.d(TAG, "Updating : " + device.getName() + " (" + device.getAddress() + ")");
DeviceInfo deviceInfo = m_oDetectedDevices.get(device.getAddress());
deviceInfo = m_oDetectedDevices.get(device.getAddress());
deviceInfo.setM_lLastSeen(timestamp);
deviceInfo.setM_iRssi(rssi);
if(!deviceInfo.getDeviceName().equals(device.getName())) {
deviceInfo.setM_oDevice(device);
}
}
m_oDetectedDevices.put(device.getAddress(), deviceInfo);
m_oList.setAdapter(m_oUiAdapter);
}
......
......@@ -43,8 +43,10 @@ public class DeviceAdapter extends ArrayAdapter<DeviceInfo> {
} else {
h = (Holder)convertView.getTag();
}
h.name.setText(p.getDeviceName());
if (p.getDeviceName() != null)
h.name.setText(p.getDeviceName());
else
h.name.setText("Unknown");
h.address.setText(p.getMacAddress());
h.rssi.setText("RSSI: " + String.valueOf(p.getM_iRssi()));
} else {
......
......@@ -55,4 +55,8 @@ public class DeviceInfo {
public void setM_bData(byte[] m_bData) {
this.m_bData = m_bData;
}
public BluetoothDevice getM_oDevice() { return m_oDevice; }
public void setM_oDevice(BluetoothDevice m_oDevice) { this.m_oDevice = m_oDevice; }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment