diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java index d5af508f..78cc7775 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java @@ -27,25 +27,28 @@ public class BluetoothGattUuid { } public static final String prettyPrint(UUID uuid) { - for (Field field : BluetoothGattUuid.class.getFields()) { - try { - if (uuid.equals(field.get(null))) { - final String name = field.getName(); - return name.substring(name.indexOf('_') + 1); - } - } - catch (IllegalAccessException e) { - // Ignore - } - } + String str = uuid.toString(); - final String str = uuid.toString(); if (str.endsWith(STANDARD_SUFFIX)) { String code = str.substring(0, str.length() - STANDARD_SUFFIX.length()); if (code.startsWith("0000")) { code = code.substring(4); } - return "0x" + code; + str = "0x" + code; + } + + for (Field field : BluetoothGattUuid.class.getFields()) { + try { + if (uuid.equals(field.get(null))) { + String name = field.getName(); + name = name.substring(name.indexOf('_') + 1); + str = String.format("%s \"%s\"", str, name.replace('_', ' ')); + break; + } + } + catch (IllegalAccessException e) { + // Ignore + } } return str; diff --git a/android_app/app/src/test/java/com/health/openscale/BluetoothGattUuidTest.java b/android_app/app/src/test/java/com/health/openscale/BluetoothGattUuidTest.java index fc58176d..de3b5b65 100644 --- a/android_app/app/src/test/java/com/health/openscale/BluetoothGattUuidTest.java +++ b/android_app/app/src/test/java/com/health/openscale/BluetoothGattUuidTest.java @@ -28,13 +28,13 @@ public class BluetoothGattUuidTest { @Test public void prettyPrint() throws Exception { - assertEquals("GENERIC_ACCESS", + assertEquals("0x1800 \"GENERIC ACCESS\"", BluetoothGattUuid.prettyPrint(BluetoothGattUuid.SERVICE_GENERIC_ACCESS)); - assertEquals("CURRENT_TIME", + assertEquals("0x2a2b \"CURRENT TIME\"", BluetoothGattUuid.prettyPrint(BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME)); - assertEquals("CLIENT_CHARACTERISTIC_CONFIGURATION", + assertEquals("0x2902 \"CLIENT CHARACTERISTIC CONFIGURATION\"", BluetoothGattUuid.prettyPrint(BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION)); - assertEquals("GENERIC_ATTRIBUTE", + assertEquals("0x1801 \"GENERIC ATTRIBUTE\"", BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1801))); assertEquals("0x0001", BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1)));