From 4a7a201971adcbbd020f10591756e06da055f92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 23 Dec 2023 21:27:53 +0000 Subject: [PATCH] Pixoo: Support custom device name --- .../devicesettings/DeviceSettingsPreferenceConst.java | 1 + .../devicesettings/DeviceSpecificSettingsFragment.java | 1 + .../gadgetbridge/devices/divoom/PixooCoordinator.java | 10 +++++++--- .../devices/huami/Huami2021Coordinator.java | 1 - .../service/devices/divoom/PixooProtocol.java | 9 +++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/devicesettings_device_name.xml | 9 +++++++++ 7 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/xml/devicesettings_device_name.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java index f80bf891b..8fab653be 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java @@ -47,6 +47,7 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_LANGUAGE = "language"; public static final String PREF_LANGUAGE_AUTO = "auto"; public static final String PREF_DEVICE_REGION = "device_region"; + public static final String PREF_DEVICE_NAME = "pref_device_name"; public static final String PREF_DATEFORMAT = "dateformat"; public static final String PREF_TIMEFORMAT = "timeformat"; public static final String PREF_TIMEFORMAT_24H = "24h"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java index f4eadc410..8df6db0fc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java @@ -339,6 +339,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i addPreferenceHandlerFor(PREF_WEARLOCATION); addPreferenceHandlerFor(PREF_VIBRATION_ENABLE); addPreferenceHandlerFor(PREF_NOTIFICATION_ENABLE); + addPreferenceHandlerFor(PREF_DEVICE_NAME); addPreferenceHandlerFor(PREF_SCREEN_BRIGHTNESS); addPreferenceHandlerFor(PREF_SCREEN_AUTO_BRIGHTNESS); addPreferenceHandlerFor(PREF_SCREEN_ORIENTATION); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java index 5b8e877fb..2f3ab8e81 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java @@ -32,7 +32,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.divoom.PixooSupport; public class PixooCoordinator extends AbstractBLEDeviceCoordinator { @Override protected Pattern getSupportedDeviceName() { - return Pattern.compile("Pixoo"); + return Pattern.compile("Pixoo(-.+)?"); } @Override @@ -79,10 +79,14 @@ public class PixooCoordinator extends AbstractBLEDeviceCoordinator { @Override public int[] getSupportedDeviceSpecificSettings(GBDevice device) { return new int[]{ - R.xml.devicesettings_pixoo, + R.xml.devicesettings_header_display, R.xml.devicesettings_screen_brightness, + R.xml.devicesettings_header_time, R.xml.devicesettings_timeformat, + R.xml.devicesettings_header_other, + R.xml.devicesettings_pixoo, + R.xml.devicesettings_header_connection, + R.xml.devicesettings_device_name, }; } - } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java index b12bfd42e..0ddbebe14 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java index 53ce5b2c6..d9dcdc99c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java @@ -52,6 +52,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; public class PixooProtocol extends GBDeviceProtocol { private static final Logger LOG = LoggerFactory.getLogger(PixooProtocol.class); @@ -158,6 +159,14 @@ public class PixooProtocol extends GBDeviceProtocol { SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()); switch (config) { + case DeviceSettingsPreferenceConst.PREF_DEVICE_NAME: + final byte[] deviceName = StringUtils.truncateToBytes(prefs.getString(DeviceSettingsPreferenceConst.PREF_DEVICE_NAME, ""), 26); + return encodeProtocol(ByteBuffer.allocate(2 + deviceName.length) + .order(ByteOrder.LITTLE_ENDIAN) + .put((byte) 0x75) + .put((byte) deviceName.length) + .put(deviceName) + .array()); case DeviceSettingsPreferenceConst.PREF_SCREEN_BRIGHTNESS: byte brightness = (byte) prefs.getInt(DeviceSettingsPreferenceConst.PREF_SCREEN_BRIGHTNESS, 50); LOG.debug("setting brightness to " + brightness); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 370012219..fb9df11c6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -976,6 +976,7 @@ Style follows Watchface Style Keep the band\'s display always on + Device name Password Lock the band with a password when removed from the wrist Password Enabled diff --git a/app/src/main/res/xml/devicesettings_device_name.xml b/app/src/main/res/xml/devicesettings_device_name.xml new file mode 100644 index 000000000..c37d90679 --- /dev/null +++ b/app/src/main/res/xml/devicesettings_device_name.xml @@ -0,0 +1,9 @@ + + + +