mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
Fossil Hybrid HR: Support button configuration in per-device settings
Related: #1751
This commit is contained in:
parent
8761bf96a4
commit
159a937cab
@ -25,4 +25,7 @@ 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";
|
||||
}
|
@ -39,6 +39,9 @@ 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_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_DATEFORMAT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SCREEN_ORIENTATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
|
||||
@ -313,6 +316,9 @@ 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);
|
||||
|
||||
String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
|
||||
boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
||||
|
@ -330,6 +330,12 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
this.watchAdapter.onSetAlarms(alarms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
if (watchAdapter != null) {
|
||||
watchAdapter.onSendConfiguration(config);
|
||||
}
|
||||
}
|
||||
private void loadTimeOffset() {
|
||||
timeOffset = getContext().getSharedPreferences(getContext().getPackageName(), Context.MODE_PRIVATE).getInt("QHYBRID_TIME_OFFSET", 0);
|
||||
}
|
||||
|
@ -85,6 +85,8 @@ public abstract class WatchAdapter {
|
||||
|
||||
public abstract void onSetAlarms(ArrayList<? extends Alarm> alarms);
|
||||
|
||||
public abstract void onSendConfiguration(String config);
|
||||
|
||||
public abstract boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic);
|
||||
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status){};
|
||||
|
||||
|
@ -151,7 +151,7 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private SharedPreferences getDeviceSpecificPreferences(){
|
||||
protected SharedPreferences getDeviceSpecificPreferences(){
|
||||
return GBApplication.getDeviceSpecificSharedPrefs(
|
||||
getDeviceSupport().getDevice().getAddress()
|
||||
);
|
||||
@ -456,6 +456,11 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||
switch (characteristic.getUuid().toString()) {
|
||||
|
@ -26,6 +26,7 @@ import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||
@ -667,8 +668,16 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
String[] menuItems = new String[jsonArray.length()];
|
||||
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");
|
||||
|
||||
queueWrite(new ButtonConfigurationPutRequest(
|
||||
menuItems,
|
||||
upperButtonApp,
|
||||
middleButtonApp,
|
||||
lowerButtonApp,
|
||||
this
|
||||
));
|
||||
} catch (JSONException e) {
|
||||
@ -676,6 +685,16 @@ 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:
|
||||
overwriteButtons(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleHeartRateCharacteristic(BluetoothGattCharacteristic characteristic) {
|
||||
super.handleHeartRateCharacteristic(characteristic);
|
||||
|
@ -465,6 +465,11 @@ public class MisfitWatchAdapter extends WatchAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overwriteButtons(String jsonConfigString) {
|
||||
uploadFileRequest = new UploadFileRequest((short) 0x0800, new byte[]{
|
||||
|
@ -12,11 +12,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class ButtonConfigurationPutRequest extends JsonPutRequest {
|
||||
public ButtonConfigurationPutRequest(String[] menuItems, FossilHRWatchAdapter adapter) {
|
||||
super(createObject(menuItems), adapter);
|
||||
public ButtonConfigurationPutRequest(String[] menuItems, String upperButtonApp, String middleButtonApp, String lowerButtonApp, FossilHRWatchAdapter adapter) {
|
||||
super(createObject(menuItems, upperButtonApp, middleButtonApp, lowerButtonApp), adapter);
|
||||
}
|
||||
|
||||
private static JSONObject createObject(String[] menuItems) {
|
||||
private static JSONObject createObject(String[] menuItems, String upperButtonApp, String middleButtonApp, String lowerButtonApp) {
|
||||
try {
|
||||
return new JSONObject()
|
||||
.put("push", new JSONObject()
|
||||
@ -24,15 +24,15 @@ public class ButtonConfigurationPutRequest extends JsonPutRequest {
|
||||
.put("commuteApp._.config.destinations", new JSONArray(menuItems))
|
||||
.put("master._.config.buttons", new JSONArray()
|
||||
.put(new JSONObject()
|
||||
.put("name", "weatherApp")
|
||||
.put("name", upperButtonApp)
|
||||
.put("button_evt", "top_short_press_release")
|
||||
)
|
||||
.put(new JSONObject()
|
||||
.put("name", "commuteApp")
|
||||
.put("name", middleButtonApp)
|
||||
.put("button_evt", "middle_short_press_release")
|
||||
)
|
||||
.put(new JSONObject()
|
||||
.put("name", "commuteApp")
|
||||
.put("name", lowerButtonApp)
|
||||
.put("button_evt", "bottom_short_press_release")
|
||||
)
|
||||
)
|
||||
|
@ -653,4 +653,25 @@
|
||||
<string name="pref_media_forward_value" translatable="false">FORWARD</string>
|
||||
<string name="pref_media_rewind_value" translatable="false">REWIND</string>
|
||||
|
||||
<string-array name="pref_hybridhr_buttonfunctions">
|
||||
<item name="notificationsPanelApp">@string/menuitem_notifications</item>
|
||||
<item name="weatherApp">@string/menuitem_weather</item>
|
||||
<item name="musicApp">@string/menuitem_music</item>
|
||||
<item name="stopwatchApp">@string/hr_appname_stopwatch</item>
|
||||
<item name="timerApp">@string/menuitem_timer</item>
|
||||
<item name="commuteApp">@string/hr_appname_commute</item>
|
||||
<item name="wellnessApp">@string/hr_appname_wellness</item>
|
||||
<item name="workoutApp">@string/hr_appname_workout</item>
|
||||
</string-array>
|
||||
<string-array name="pref_hybridhr_buttonfunctions_values">
|
||||
<item>notificationsPanelApp</item>
|
||||
<item>weatherApp</item>
|
||||
<item>musicApp</item>
|
||||
<item>stopwatchApp</item>
|
||||
<item>timerApp</item>
|
||||
<item>commuteApp"</item>
|
||||
<item>wellnessApp</item>
|
||||
<item>workoutApp</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
@ -794,6 +794,15 @@
|
||||
<string name="hr_widget_weather">Weather</string>
|
||||
<string name="hr_widget_nothing">Nothing</string>
|
||||
|
||||
<string name="hr_appname_wellness">Wellness</string>
|
||||
<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="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>
|
||||
|
@ -1,5 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListPreference
|
||||
android:defaultValue="weatherApp"
|
||||
android:entries="@array/pref_hybridhr_buttonfunctions"
|
||||
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
|
||||
android:key="button_1_function"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_upper_button_function" />
|
||||
<ListPreference
|
||||
android:defaultValue="commuteApp"
|
||||
android:entries="@array/pref_hybridhr_buttonfunctions"
|
||||
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
|
||||
android:key="button_2_function"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_middle_button_function" />
|
||||
<ListPreference
|
||||
android:defaultValue="musicApp"
|
||||
android:entries="@array/pref_hybridhr_buttonfunctions"
|
||||
android:entryValues="@array/pref_hybridhr_buttonfunctions_values"
|
||||
android:key="button_3_function"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_lower_button_function" />
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="force_white_color_scheme"
|
||||
|
Loading…
Reference in New Issue
Block a user