From 9dc4dde5e741241dffb1bcd51eed6cdd815b08f0 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 24 Mar 2021 20:02:48 +0100 Subject: [PATCH] Amazfit Neo: Support sound settings --- .../DeviceSettingsPreferenceConst.java | 4 ++- .../DeviceSpecificSettingsFragment.java | 2 ++ .../service/devices/huami/HuamiSupport.java | 28 +++++++++++++++++ app/src/main/res/values/arrays.xml | 30 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/values/values.xml | 6 ++++ .../res/xml/devicesettings_amazfitneo.xml | 11 +++++++ 7 files changed, 83 insertions(+), 1 deletion(-) 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 346154d0c..ee90563ba 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 @@ -69,5 +69,7 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_SONYSWR12_STAMINA = "stamina_preference"; public static final String PREF_SONYSWR12_SMART_INTERVAL = "smart_alarm_interval_preference"; - public static final String PREF_BT_CONNECTED_ADVERTISEMENT = "bt_connected_advertisement"; + public static final String PREF_BT_CONNECTED_ADVERTISEMENT = "bt_connected_advertisement"; + + public static final String PREF_SOUNDS = "sounds"; } \ No newline at end of file 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 4bf55c305..3ea7311ca 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 @@ -83,6 +83,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONYSWR12_LOW_VIBRATION; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONYSWR12_SMART_INTERVAL; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONYSWR12_STAMINA; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SOUNDS; 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; @@ -400,6 +401,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat { addPreferenceHandlerFor(PREF_HYDRATION_PERIOD); addPreferenceHandlerFor(PREF_AMPM_ENABLED); addPreferenceHandlerFor(PREF_LEFUN_INTERFACE_LANGUAGE); + addPreferenceHandlerFor(PREF_SOUNDS); addPreferenceHandlerFor(PREF_HYBRID_HR_DRAW_WIDGET_CIRCLES); addPreferenceHandlerFor(PREF_HYBRID_HR_FORCE_WHITE_COLOR); 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 6257ebeeb..d5f43ab55 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 @@ -147,6 +147,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev 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_SOUNDS; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION; @@ -1979,6 +1980,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { case PREF_WEARLOCATION: setWearLocation(builder); break; + case PREF_SOUNDS: + setBeepSounds(builder); + break; } builder.queue(getQueue()); } catch (IOException e) { @@ -2489,6 +2493,30 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { return this; } + protected HuamiSupport setBeepSounds(TransactionBuilder builder) { + + SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); + Set sounds = prefs.getStringSet(PREF_SOUNDS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_amazfitneo_sounds_default)))); + + LOG.info("Setting sounds to " + (sounds == null ? "none" : sounds)); + + + if (sounds != null) { + final String[] soundOrder = new String[]{"button", "calls", "alarm", "notifications", "inactivity_warning", "sms", "goal"}; + byte[] command = new byte[]{0x3c, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 7, 0, 0}; + int i = 3; + for (String sound : soundOrder) { + if (sounds.contains(sound)) { + command[i] = 1; + } + i += 3; + } + writeToChunked(builder, 2, command); + } + + return this; + } + private HuamiSupport setRotateWristToSwitchInfo(TransactionBuilder builder) { boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo(gbDevice.getAddress()); LOG.info("Setting rotate wrist to cycle info to " + enable); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 79d7b92d0..df3307e63 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1479,4 +1479,34 @@ + + @string/prefs_operating_sounds + @string/pref_title_notifications_call + @string/menuitem_alarm + @string/menuitem_notifications + @string/mi2_prefs_inactivity_warnings + @string/pref_title_notifications_sms + @string/menuitem_goal + + + + @string/p_menuitem_button + @string/p_menuitem_calls + @string/p_menuitem_alarm + @string/p_menuitem_notifications + @string/p_menuitem_inactivity_warning + @string/p_menuitem_sms + @string/p_menuitem_goal + + + + @string/p_menuitem_button + @string/p_menuitem_calls + @string/p_menuitem_alarm + @string/p_menuitem_notifications + @string/p_menuitem_inactivity_warning + @string/p_menuitem_sms + @string/p_menuitem_goal + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4e9c2d88..2cd89fc68 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -469,6 +469,9 @@ Show ongoing activity popup Lack of sleep: %1$s Overslept: %1$s + Sounds + Configure when the device will beep + Device is connecting Device is connected diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index bb9cd637a..88055c606 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -51,6 +51,12 @@ sleep pomodoro + + button + calls + inactivity_warning + sms + off on sunset diff --git a/app/src/main/res/xml/devicesettings_amazfitneo.xml b/app/src/main/res/xml/devicesettings_amazfitneo.xml index 38b0ee543..8ba1ad604 100644 --- a/app/src/main/res/xml/devicesettings_amazfitneo.xml +++ b/app/src/main/res/xml/devicesettings_amazfitneo.xml @@ -19,4 +19,15 @@ android:key="language" android:summary="%s" android:title="@string/pref_title_language" /> + + +