From 05a4c0ce68aa326d776871c019abc1726bdb1282 Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Tue, 13 Oct 2020 03:06:05 +0200 Subject: [PATCH] Fossil HR: added long and double button presses --- .../DeviceSettingsPreferenceConst.java | 12 +++-- .../DeviceSpecificSettingsFragment.java | 24 ++++++--- .../fossil_hr/FossilHRWatchAdapter.java | 32 ++++++++---- .../buttons/ButtonConfiguration.java | 25 +++++++++ .../ButtonConfigurationPutRequest.java | 25 +++------ app/src/main/res/values/strings.xml | 12 +++-- .../res/xml/devicesettings_fossilhybridhr.xml | 51 ++++++++++++++++--- 7 files changed, 137 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfiguration.java 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 1d8d2a98b..bec59cc47 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 @@ -26,9 +26,15 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_ALLOW_HIGH_MTU = "allow_high_mtu"; public static final String PREF_SYNC_CALENDAR = "sync_calendar"; public static final String PREF_USE_CUSTOM_DEVICEICON = "use_custom_deviceicon"; - public static final String PREF_BUTTON_1_FUNCTION = "button_1_function"; - public static final String PREF_BUTTON_2_FUNCTION = "button_2_function"; - public static final String PREF_BUTTON_3_FUNCTION = "button_3_function"; + public static final String PREF_BUTTON_1_FUNCTION_SHORT = "button_1_function_short"; + public static final String PREF_BUTTON_2_FUNCTION_SHORT = "button_2_function_short"; + public static final String PREF_BUTTON_3_FUNCTION_SHORT = "button_3_function_short"; + public static final String PREF_BUTTON_1_FUNCTION_LONG = "button_1_function_long"; + public static final String PREF_BUTTON_2_FUNCTION_LONG = "button_2_function_long"; + public static final String PREF_BUTTON_3_FUNCTION_LONG = "button_3_function_long"; + public static final String PREF_BUTTON_1_FUNCTION_DOUBLE = "button_1_function_double"; + public static final String PREF_BUTTON_2_FUNCTION_DOUBLE = "button_2_function_double"; + public static final String PREF_BUTTON_3_FUNCTION_DOUBLE = "button_3_function_double"; public static final String PREF_VIBRATION_STRENGH_PERCENTAGE = "vibration_strength"; public static final String PREF_RELAX_FIRMWARE_CHECKS = "relax_firmware_checks"; 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 c7dc9bddf..cdf6031cf 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 @@ -44,9 +44,15 @@ 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_AMPM_ENABLED; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ANTILOST_ENABLED; -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_1_FUNCTION_SHORT; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_SHORT; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_SHORT; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_LONG; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_LONG; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_LONG; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_DOUBLE; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_DOUBLE; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_DOUBLE; 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; @@ -349,9 +355,15 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat { addPreferenceHandlerFor(PREF_WEARLOCATION); addPreferenceHandlerFor(PREF_SCREEN_ORIENTATION); addPreferenceHandlerFor(PREF_TIMEFORMAT); - addPreferenceHandlerFor(PREF_BUTTON_1_FUNCTION); - addPreferenceHandlerFor(PREF_BUTTON_2_FUNCTION); - addPreferenceHandlerFor(PREF_BUTTON_3_FUNCTION); + addPreferenceHandlerFor(PREF_BUTTON_1_FUNCTION_SHORT); + addPreferenceHandlerFor(PREF_BUTTON_2_FUNCTION_SHORT); + addPreferenceHandlerFor(PREF_BUTTON_3_FUNCTION_SHORT); + addPreferenceHandlerFor(PREF_BUTTON_1_FUNCTION_LONG); + addPreferenceHandlerFor(PREF_BUTTON_2_FUNCTION_LONG); + addPreferenceHandlerFor(PREF_BUTTON_3_FUNCTION_LONG); + addPreferenceHandlerFor(PREF_BUTTON_1_FUNCTION_DOUBLE); + addPreferenceHandlerFor(PREF_BUTTON_2_FUNCTION_DOUBLE); + addPreferenceHandlerFor(PREF_BUTTON_3_FUNCTION_DOUBLE); addPreferenceHandlerFor(PREF_VIBRATION_STRENGH_PERCENTAGE); addPreferenceHandlerFor(PREF_POWER_MODE); addPreferenceHandlerFor(PREF_LIFTWRIST_NOSHED); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index 68308d151..4cd67b1a1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -69,6 +69,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayCallNotificationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayTextNotificationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.configuration.ConfigurationGetRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.configuration.ConfigurationPutRequest; @@ -914,15 +915,22 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { for (int i = 0; i < jsonArray.length(); i++) menuItems[i] = jsonArray.getString(i); SharedPreferences prefs = getDeviceSpecificPreferences(); - String upperButtonApp = prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION, "weatherApp"); - String middleButtonApp = prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION, "commuteApp"); - String lowerButtonApp = prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION, "musicApp"); + + ButtonConfiguration[] buttonConfigurations = new ButtonConfiguration[]{ + new ButtonConfiguration("top_single_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_SHORT, "weatherApp")), + new ButtonConfiguration("middle_single_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_SHORT, "commuteApp")), + new ButtonConfiguration("bottom_single_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_SHORT, "musicApp")), + new ButtonConfiguration("top_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_LONG, "weatherApp")), + // new ButtonConfiguration("middle_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_LONG, "commuteApp")), + new ButtonConfiguration("bottom_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_LONG, "musicApp")), + new ButtonConfiguration("top_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_DOUBLE, "weatherApp")), + new ButtonConfiguration("middle_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_DOUBLE, "commuteApp")), + new ButtonConfiguration("bottom_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_DOUBLE, "musicApp")), + }; queueWrite(new ButtonConfigurationPutRequest( menuItems, - upperButtonApp, - middleButtonApp, - lowerButtonApp, + buttonConfigurations, this )); } catch (JSONException e) { @@ -933,9 +941,15 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { @Override public void onSendConfiguration(String config) { switch (config) { - case DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION: - case DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION: - case DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION: + case DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_SHORT: + case DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_SHORT: + case DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_SHORT: + case DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_LONG: + case DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_LONG: + case DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_LONG: + case DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_DOUBLE: + case DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_DOUBLE: + case DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_DOUBLE: overwriteButtons(null); break; case DeviceSettingsPreferenceConst.PREF_VIBRATION_STRENGH_PERCENTAGE: diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfiguration.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfiguration.java new file mode 100644 index 000000000..e52eb0ff2 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfiguration.java @@ -0,0 +1,25 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons; + +import org.json.JSONException; +import org.json.JSONObject; + +public class ButtonConfiguration { + private String triggerEvent; + private String action; + + public ButtonConfiguration(String triggerEvent, String action) { + this.triggerEvent = triggerEvent; + this.action = action; + } + + public JSONObject toJsonObject(){ + try { + return new JSONObject() + .put("button_evt", triggerEvent) + .put("name", action); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfigurationPutRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfigurationPutRequest.java index 983dc32c4..fd498c623 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfigurationPutRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/buttons/ButtonConfigurationPutRequest.java @@ -12,30 +12,21 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos import nodomain.freeyourgadget.gadgetbridge.util.GB; public class ButtonConfigurationPutRequest extends JsonPutRequest { - public ButtonConfigurationPutRequest(String[] menuItems, String upperButtonApp, String middleButtonApp, String lowerButtonApp, FossilHRWatchAdapter adapter) { - super(createObject(menuItems, upperButtonApp, middleButtonApp, lowerButtonApp), adapter); + public ButtonConfigurationPutRequest(String[] menuItems, ButtonConfiguration[] buttonConfigurations, FossilHRWatchAdapter adapter) { + super(createObject(menuItems, buttonConfigurations), adapter); } - private static JSONObject createObject(String[] menuItems, String upperButtonApp, String middleButtonApp, String lowerButtonApp) { + private static JSONObject createObject(String[] menuItems, ButtonConfiguration[] buttonConfigurations) { try { + JSONArray configuration = new JSONArray(); + for(ButtonConfiguration buttonConfiguration : buttonConfigurations){ + configuration.put(buttonConfiguration.toJsonObject()); + } return new JSONObject() .put("push", new JSONObject() .put("set", new JSONObject() .put("commuteApp._.config.destinations", new JSONArray(menuItems)) - .put("master._.config.buttons", new JSONArray() - .put(new JSONObject() - .put("name", upperButtonApp) - .put("button_evt", "top_short_press_release") - ) - .put(new JSONObject() - .put("name", middleButtonApp) - .put("button_evt", "middle_short_press_release") - ) - .put(new JSONObject() - .put("name", lowerButtonApp) - .put("button_evt", "bottom_short_press_release") - ) - ) + .put("master._.config.buttons", configuration) ) ); } catch (JSONException e) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7ef777ec3..2d902f73c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -907,9 +907,15 @@ Workout Stopwatch Commute - Upper Button - Middle Button - Lower Button + Upper Button short + Middle Button short + Lower Button short + Upper Button long + Middle Button long + Lower Button long + Upper Button double + Middle Button double + Lower Button double Event 1 action Event 2 action Event 3 action diff --git a/app/src/main/res/xml/devicesettings_fossilhybridhr.xml b/app/src/main/res/xml/devicesettings_fossilhybridhr.xml index 9a5873f34..de4b53713 100644 --- a/app/src/main/res/xml/devicesettings_fossilhybridhr.xml +++ b/app/src/main/res/xml/devicesettings_fossilhybridhr.xml @@ -1,27 +1,66 @@ + + android:title="@string/pref_title_upper_button_function_short" /> + + + + android:title="@string/pref_title_middle_button_function_short" /> + + + android:title="@string/pref_title_lower_button_function_short" /> + + +