1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 17:02:13 +01:00

Fossil HR: added long and double button presses

This commit is contained in:
Daniel Dakhno 2020-10-13 03:06:05 +02:00
parent 0d49eaaf9e
commit 05a4c0ce68
7 changed files with 137 additions and 44 deletions

View File

@ -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";

View File

@ -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);

View File

@ -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:

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -907,9 +907,15 @@
<string name="hr_appname_workout">Workout</string>
<string name="hr_appname_stopwatch">Stopwatch</string>
<string name="hr_appname_commute">Commute</string>
<string name="pref_title_upper_button_function">Upper Button</string>
<string name="pref_title_middle_button_function">Middle Button</string>
<string name="pref_title_lower_button_function">Lower Button</string>
<string name="pref_title_upper_button_function_short">Upper Button short</string>
<string name="pref_title_middle_button_function_short">Middle Button short</string>
<string name="pref_title_lower_button_function_short">Lower Button short</string>
<string name="pref_title_upper_button_function_long">Upper Button long</string>
<string name="pref_title_middle_button_function_long">Middle Button long</string>
<string name="pref_title_lower_button_function_long">Lower Button long</string>
<string name="pref_title_upper_button_function_double">Upper Button double</string>
<string name="pref_title_middle_button_function_double">Middle Button double</string>
<string name="pref_title_lower_button_function_double">Lower Button double</string>
<string name="prefs_button_single_press_action_selection_title">Event 1 action</string>
<string name="prefs_button_double_press_action_selection_title">Event 2 action</string>
<string name="prefs_button_triple_press_action_selection_title">Event 3 action</string>

View File

@ -1,27 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
android:defaultValue="weatherApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_1_function"
android:key="button_1_function_short"
android:summary="%s"
android:title="@string/pref_title_upper_button_function" />
android:title="@string/pref_title_upper_button_function_short" />
<ListPreference
android:defaultValue="weatherApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_1_function_long"
android:summary="%s"
android:title="@string/pref_title_upper_button_function_long" />
<ListPreference
android:defaultValue="weatherApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_1_function_double"
android:summary="%s"
android:title="@string/pref_title_upper_button_function_double" />
<ListPreference
android:defaultValue="commuteApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_2_function"
android:key="button_2_function_short"
android:summary="%s"
android:title="@string/pref_title_middle_button_function" />
android:title="@string/pref_title_middle_button_function_short" />
<ListPreference
android:defaultValue="commuteApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_2_function_double"
android:summary="%s"
android:title="@string/pref_title_middle_button_function_double" />
<ListPreference
android:defaultValue="musicApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_3_function"
android:key="button_3_function_short"
android:summary="%s"
android:title="@string/pref_title_lower_button_function" />
android:title="@string/pref_title_lower_button_function_short" />
<ListPreference
android:defaultValue="musicApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_3_function_long"
android:summary="%s"
android:title="@string/pref_title_lower_button_function_long" />
<ListPreference
android:defaultValue="musicApp"
android:entries="@array/pref_hybridhr_buttonfunctions"
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
android:key="button_3_function_double"
android:summary="%s"
android:title="@string/pref_title_lower_button_function_double" />
<SwitchPreference
android:defaultValue="false"
android:key="force_white_color_scheme"