From 3d09b9dc97f53513110d9fa56c1e989204db59aa Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 28 Sep 2017 15:44:07 +0200 Subject: [PATCH] Amazfit Bip: Switch language on the watch automatically according to the phone locale Supported: - Simplified Chinese - Traditional Chinese - English --- .../devices/amazfitbip/AmazfitBipService.java | 6 +++++ .../devices/amazfitbip/AmazfitBipSupport.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipService.java index fb1c6e3c..f354e5e8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipService.java @@ -19,6 +19,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip; import java.util.UUID; +import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service.ENDPOINT_DISPLAY; + public class AmazfitBipService { public static final UUID UUID_CHARACTERISTIC_WEATHER = UUID.fromString("0000000e-0000-3512-2118-0009af100700"); @@ -26,4 +28,8 @@ public class AmazfitBipService { public static final byte[] COMMAND_REQUEST_GPS_VERSION = new byte[]{0x0e}; public static final byte COMMAND_ACTIVITY_DATA_TYPE_DEBUGLOGS = 0x07; + + public static final byte[] COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x00}; + public static final byte[] COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x01}; + public static final byte[] COMMAND_SET_LANGUAGE_ENGLISH = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x02}; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java index 91cb3a0e..646651dc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.Locale; import java.util.SimpleTimeZone; import java.util.UUID; @@ -271,10 +272,31 @@ public class AmazfitBipSupport extends MiBand2Support { return this; } + private AmazfitBipSupport setLanguage(TransactionBuilder builder) { + String language = Locale.getDefault().getLanguage(); + String country = Locale.getDefault().getCountry(); + + LOG.info("Setting watch language, phone language = " + language + " country = " + country); + + byte[] command; + if (language.equals("zh")) { + if (country.equals("TW") || country.equals("HK") || country.equals("MO")) { // Taiwan, Hong Kong, Macao + command = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE; + } else { + command = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE; + } + } else { + command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH; + } + builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command); + return this; + } + @Override public void phase2Initialize(TransactionBuilder builder) { super.phase2Initialize(builder); LOG.info("phase2Initialize..."); + setLanguage(builder); requestGPSVersion(builder); } }