Let discovery activity also display device aliases
This commit is contained in:
parent
903890067d
commit
154b7d28bb
|
@ -179,6 +179,7 @@ public class DiscoveryActivity extends GBActivity implements AdapterView.OnItemC
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeviceFound(BluetoothDevice device, short rssi) {
|
private void handleDeviceFound(BluetoothDevice device, short rssi) {
|
||||||
|
LOG.debug("found device: " + device.getName() + ", " + device.getAddress());
|
||||||
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
|
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||||
return; // ignore already bonded devices
|
return; // ignore already bonded devices
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import android.os.Parcelable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
@ -76,14 +78,22 @@ public class GBDeviceCandidate implements Parcelable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
String name = null;
|
String deviceName = null;
|
||||||
if (device != null) {
|
try {
|
||||||
name = device.getName();
|
Method method = device.getClass().getMethod("getAliasName");
|
||||||
|
if (method != null) {
|
||||||
|
deviceName = (String) method.invoke(device);
|
||||||
}
|
}
|
||||||
if (name == null || name.length() == 0) {
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) {
|
||||||
name = GBApplication.getContext().getString(R.string._unknown_);
|
LOG.info("Could not get device alias for " + deviceName);
|
||||||
}
|
}
|
||||||
return name;
|
if (deviceName == null || deviceName.length() == 0) {
|
||||||
|
deviceName = device.getName();
|
||||||
|
}
|
||||||
|
if (deviceName == null || deviceName.length() == 0) {
|
||||||
|
deviceName = "(unknown)";
|
||||||
|
}
|
||||||
|
return deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getRssi() {
|
public short getRssi() {
|
||||||
|
|
|
@ -8,8 +8,6 @@ import android.widget.Toast;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -18,7 +16,6 @@ import java.util.Set;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
||||||
|
@ -115,22 +112,12 @@ public class DeviceHelper {
|
||||||
public GBDevice toSupportedDevice(BluetoothDevice device) {
|
public GBDevice toSupportedDevice(BluetoothDevice device) {
|
||||||
GBDeviceCandidate candidate = new GBDeviceCandidate(device, GBDevice.RSSI_UNKNOWN);
|
GBDeviceCandidate candidate = new GBDeviceCandidate(device, GBDevice.RSSI_UNKNOWN);
|
||||||
|
|
||||||
String deviceName = device.getName();
|
|
||||||
try {
|
|
||||||
Method method = device.getClass().getMethod("getAliasName");
|
|
||||||
if (method != null) {
|
|
||||||
deviceName = (String) method.invoke(device);
|
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) {
|
|
||||||
LOG.info("Could not get device alias for " + deviceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (coordinator != null && coordinator.supports(candidate)) {
|
if (coordinator != null && coordinator.supports(candidate)) {
|
||||||
return new GBDevice(device.getAddress(), deviceName, coordinator.getDeviceType());
|
return new GBDevice(device.getAddress(), candidate.getName(), coordinator.getDeviceType());
|
||||||
}
|
}
|
||||||
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
||||||
if (coordinator.supports(candidate)) {
|
if (coordinator.supports(candidate)) {
|
||||||
return new GBDevice(device.getAddress(), deviceName, coordinator.getDeviceType());
|
return new GBDevice(device.getAddress(), candidate.getName(), coordinator.getDeviceType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue