From fefcf2d2b91635947eb396bf626269845a0def9a Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 5 May 2020 00:34:59 +0200 Subject: [PATCH] ZeTime: Fix setting the watch language and make the setting accessible from the per-device configuration menu This did not work at all before, it was supposed to take the language from Gadgetbridge App settings or the phone's default settings, but nothing was ever sent to the watch. --- .../DeviceSettingsPreferenceConst.java | 1 + .../DeviceSpecificSettingsFragment.java | 12 +++--- .../devices/huami/HuamiConst.java | 1 - .../devices/zetime/ZeTimeCoordinator.java | 1 + .../service/devices/huami/HuamiSupport.java | 3 +- .../devices/zetime/ZeTimeDeviceSupport.java | 35 +++++++++------- app/src/main/res/values/arrays.xml | 40 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + .../main/res/xml/devicesettings_zetime.xml | 11 +++++ 9 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/xml/devicesettings_zetime.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 c0ca5b97b..88f596bd3 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 @@ -17,6 +17,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings; public class DeviceSettingsPreferenceConst { + public static final String PREF_LANGUAGE = "language"; public static final String PREF_DATEFORMAT = "dateformat"; public static final String PREF_TIMEFORMAT = "timeformat"; public static final String PREF_WEARLOCATION = "wearlocation"; 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 f4e54be63..cc0970545 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 @@ -39,25 +39,26 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.XTimePreference; import nodomain.freeyourgadget.gadgetbridge.util.XTimePreferenceFragment; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALTITUDE_CALIBRATE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_BP_CALIBRATE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISCONNECTNOTIF_NOSHED; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HYBRID_HR_DRAW_WIDGET_CIRCLES; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HYBRID_HR_FORCE_WHITE_COLOR; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HYBRID_HR_SAVE_RAW_ACTIVITY_FILES; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LANGUAGE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LIFTWRIST_NOSHED; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISCONNECTNOTIF_NOSHED; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_POWER_MODE; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_BP_CALIBRATE; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALTITUDE_CALIBRATE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LONGSIT_PERIOD; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LONGSIT_SWITCH; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_POWER_MODE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SCREEN_ORIENTATION; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_VIBRATION_STRENGH_PERCENTAGE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END; @@ -66,7 +67,6 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY; -import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_LANGUAGE; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java index 6cd7850a0..791326dbd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java @@ -59,7 +59,6 @@ public class HuamiConst { public static final String PREF_DISCONNECT_NOTIFICATION_END = "disconnect_notification_end"; public static final String PREF_DISPLAY_ITEMS = "display_items"; - public static final String PREF_LANGUAGE = "language"; public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty"; public static final String PREF_USE_CUSTOM_FONT = "use_custom_font"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java index 967885213..01df56dca 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/zetime/ZeTimeCoordinator.java @@ -163,6 +163,7 @@ public class ZeTimeCoordinator extends AbstractDeviceCoordinator { @Override public int[] getSupportedDeviceSpecificSettings(GBDevice device) { return new int[]{ + R.xml.devicesettings_zetime, R.xml.devicesettings_timeformat, R.xml.devicesettings_wearlocation, }; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 4011578e3..55a443bfa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -136,6 +136,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.Version; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LANGUAGE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT; @@ -1829,7 +1830,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { case PREF_DATEFORMAT: setDateFormat(builder); break; - case HuamiConst.PREF_LANGUAGE: + case PREF_LANGUAGE: setLanguage(builder); break; case HuamiConst.PREF_EXPOSE_HR_THIRDPARTY: diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java index 980407017..ba4e59a2d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java @@ -154,6 +154,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport { case DeviceSettingsPreferenceConst.PREF_WEARLOCATION: setWrist(builder); break; + case DeviceSettingsPreferenceConst.PREF_LANGUAGE: + setLanguage(builder); + break; case ZeTimeConstants.PREF_SCREENTIME: setScreenTime(builder); break; @@ -2154,33 +2157,36 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport { } private void setLanguage(TransactionBuilder builder) { - Prefs prefs = GBApplication.getPrefs(); - String language = prefs.getString("language", "default"); - Locale locale; + String localeString = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_LANGUAGE, "auto"); byte[] languageMsg = { ZeTimeConstants.CMD_PREAMBLE, ZeTimeConstants.CMD_LANGUAGE_SETTINGS, - ZeTimeConstants.CMD_REQUEST, + ZeTimeConstants.CMD_SEND, (byte) 0x1, (byte) 0x0, (byte) 0x0, ZeTimeConstants.CMD_END }; - if (language == null || language.equals("default")) { - locale = Locale.getDefault(); - language = locale.getLanguage(); + if (localeString == null || localeString.equals("auto")) { + String language = Locale.getDefault().getLanguage(); + String country = Locale.getDefault().getCountry(); + + if (country == null) { + // sometimes country is null, no idea why, guess it. + country = language; + } + localeString = language + "_" + country.toUpperCase(); } - switch (language) { + switch (localeString.substring(0, 2)) { case "zh": - languageMsg[5] = 1; - break; - case "tw": - case "hk": - case "mo": - languageMsg[5] = 2; + if (localeString.equals("zh_CN")) { + languageMsg[5] = 1; + } else { + languageMsg[5] = 2; + } break; case "ko": languageMsg[5] = 3; @@ -2225,5 +2231,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport { default: languageMsg[5] = 0; } + sendMsgToWatch(builder, languageMsg); } } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 8d9275562..1bbef4757 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -551,6 +551,46 @@ ko_KO + + @string/automatic + @string/simplified_chinese + @string/traditional_chinese + @string/english + @string/spanish + @string/german + @string/italian + @string/french + @string/portuguese + @string/dutch + @string/hungarian + @string/romanian + @string/polish + @string/russian + @string/japanese + @string/korean + @string/thai + + + + auto + zh_CN + zh_TW + en_US + es_ES + de_DE + it_IT + fr_FR + pt_PT + nl_NL + hu_HU + ro_RO + pl_PL + ru_RU + ja_JP + ko_KO + th_TH + + @string/off @string/interval_one_minute diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 34ada6992..3ceb8fbd3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -558,6 +558,8 @@ Thai Vietnamese Portuguese + Romanian + Hungarian About to transfer data since %1$s Waiting for reconnect About you diff --git a/app/src/main/res/xml/devicesettings_zetime.xml b/app/src/main/res/xml/devicesettings_zetime.xml new file mode 100644 index 000000000..1bc378a4b --- /dev/null +++ b/app/src/main/res/xml/devicesettings_zetime.xml @@ -0,0 +1,11 @@ + + + +