1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Fossil Hybrid HR: Add toggling of widgets with physical button event

This commit is contained in:
Arjan Schrijver 2022-07-25 22:23:22 +02:00
parent 03db850b3e
commit 0b6c2db606
9 changed files with 105 additions and 50 deletions

View File

@ -393,6 +393,9 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
if (watchfaceConfig.has("wrist_flick_move_minute")) { if (watchfaceConfig.has("wrist_flick_move_minute")) {
watchfaceSettings.setWristFlickMoveMinute(watchfaceConfig.getInt("wrist_flick_move_minute")); watchfaceSettings.setWristFlickMoveMinute(watchfaceConfig.getInt("wrist_flick_move_minute"));
} }
if (watchfaceConfig.has("toggle_widgets_event")) {
watchfaceSettings.setToggleWidgetsEvent(watchfaceConfig.getString("toggle_widgets_event"));
}
if (watchfaceConfig.has("powersave_display")) { if (watchfaceConfig.has("powersave_display")) {
watchfaceSettings.setPowersaveDisplay(watchfaceConfig.getBoolean("powersave_display")); watchfaceSettings.setPowersaveDisplay(watchfaceConfig.getBoolean("powersave_display"));
} }

View File

@ -301,9 +301,10 @@ public class HybridHRWatchfaceFactory {
config.put("wrist_flick_duration", settings.getWristFlickDuration()); config.put("wrist_flick_duration", settings.getWristFlickDuration());
config.put("wrist_flick_move_hour", settings.getWristFlickMoveHour()); config.put("wrist_flick_move_hour", settings.getWristFlickMoveHour());
config.put("wrist_flick_move_minute", settings.getWristFlickMoveMinute()); config.put("wrist_flick_move_minute", settings.getWristFlickMoveMinute());
config.put("light_up_on_notification", settings.getLightUpOnNotification()); config.put("toggle_widgets_event", settings.getToggleWidgetsEvent());
config.put("powersave_display", settings.getPowersaveDisplay()); config.put("powersave_display", settings.getPowersaveDisplay());
config.put("powersave_hands", settings.getPowersaveHands()); config.put("powersave_hands", settings.getPowersaveHands());
config.put("light_up_on_notification", settings.getLightUpOnNotification());
configuration.put("config", config); configuration.put("config", config);
return configuration.toString(); return configuration.toString();

View File

@ -25,6 +25,7 @@ public class HybridHRWatchfaceSettings implements Serializable {
private int wristFlickDuration = 2200; private int wristFlickDuration = 2200;
private int wristFlickMoveHour = 360; private int wristFlickMoveHour = 360;
private int wristFlickMoveMinute = -360; private int wristFlickMoveMinute = -360;
private String toggleWidgetsEvent = "";
private boolean powersaveDisplay = false; private boolean powersaveDisplay = false;
private boolean powersaveHands = false; private boolean powersaveHands = false;
private boolean lightUpOnNotification = false; private boolean lightUpOnNotification = false;
@ -100,6 +101,14 @@ public class HybridHRWatchfaceSettings implements Serializable {
} }
} }
public String getToggleWidgetsEvent() {
return toggleWidgetsEvent;
}
public void setToggleWidgetsEvent(String event) {
this.toggleWidgetsEvent = event;
}
public boolean getPowersaveDisplay() { public boolean getPowersaveDisplay() {
return powersaveDisplay; return powersaveDisplay;
} }

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.SwitchPreference; import android.preference.SwitchPreference;
@ -68,7 +69,7 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivity
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
public static class HybridHRWatchfaceSettingsFragment extends PreferenceFragment public static class HybridHRWatchfaceSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener
{ {
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
@ -76,86 +77,94 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivity
addPreferencesFromResource(R.xml.fossil_hr_watchface_settings); addPreferencesFromResource(R.xml.fossil_hr_watchface_settings);
EditTextPreference refresh_full = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_full"); EditTextPreference refresh_full = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_full");
refresh_full.setOnPreferenceChangeListener(new PreferenceChangeListener()); refresh_full.setOnPreferenceChangeListener(this);
refresh_full.setText(Integer.toString(settings.getDisplayTimeoutFull())); refresh_full.setText(Integer.toString(settings.getDisplayTimeoutFull()));
refresh_full.setSummary(Integer.toString(settings.getDisplayTimeoutFull())); refresh_full.setSummary(Integer.toString(settings.getDisplayTimeoutFull()));
EditTextPreference refresh_partial = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_partial"); EditTextPreference refresh_partial = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_partial");
refresh_partial.setOnPreferenceChangeListener(new PreferenceChangeListener()); refresh_partial.setOnPreferenceChangeListener(this);
refresh_partial.setText(Integer.toString(settings.getDisplayTimeoutPartial())); refresh_partial.setText(Integer.toString(settings.getDisplayTimeoutPartial()));
refresh_partial.setSummary(Integer.toString(settings.getDisplayTimeoutPartial())); refresh_partial.setSummary(Integer.toString(settings.getDisplayTimeoutPartial()));
SwitchPreference wrist_flick_relative = (SwitchPreference) findPreference("pref_hybridhr_watchface_wrist_flick_relative"); SwitchPreference wrist_flick_relative = (SwitchPreference) findPreference("pref_hybridhr_watchface_wrist_flick_relative");
wrist_flick_relative.setOnPreferenceChangeListener(new PreferenceChangeListener()); wrist_flick_relative.setOnPreferenceChangeListener(this);
wrist_flick_relative.setChecked(settings.isWristFlickHandsMoveRelative()); wrist_flick_relative.setChecked(settings.isWristFlickHandsMoveRelative());
EditTextPreference wrist_flick_hour_hand = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_hour_hand"); EditTextPreference wrist_flick_hour_hand = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_hour_hand");
wrist_flick_hour_hand.setOnPreferenceChangeListener(new PreferenceChangeListener()); wrist_flick_hour_hand.setOnPreferenceChangeListener(this);
wrist_flick_hour_hand.setText(Integer.toString(settings.getWristFlickMoveHour())); wrist_flick_hour_hand.setText(Integer.toString(settings.getWristFlickMoveHour()));
wrist_flick_hour_hand.setSummary(Integer.toString(settings.getWristFlickMoveHour())); wrist_flick_hour_hand.setSummary(Integer.toString(settings.getWristFlickMoveHour()));
EditTextPreference wrist_flick_minute_hand = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_minute_hand"); EditTextPreference wrist_flick_minute_hand = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_minute_hand");
wrist_flick_minute_hand.setOnPreferenceChangeListener(new PreferenceChangeListener()); wrist_flick_minute_hand.setOnPreferenceChangeListener(this);
wrist_flick_minute_hand.setText(Integer.toString(settings.getWristFlickMoveMinute())); wrist_flick_minute_hand.setText(Integer.toString(settings.getWristFlickMoveMinute()));
wrist_flick_minute_hand.setSummary(Integer.toString(settings.getWristFlickMoveMinute())); wrist_flick_minute_hand.setSummary(Integer.toString(settings.getWristFlickMoveMinute()));
EditTextPreference wrist_flick_duration = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_duration"); EditTextPreference wrist_flick_duration = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_duration");
wrist_flick_duration.setOnPreferenceChangeListener(new PreferenceChangeListener()); wrist_flick_duration.setOnPreferenceChangeListener(this);
wrist_flick_duration.setText(Integer.toString(settings.getWristFlickDuration())); wrist_flick_duration.setText(Integer.toString(settings.getWristFlickDuration()));
wrist_flick_duration.setSummary(Integer.toString(settings.getWristFlickDuration())); wrist_flick_duration.setSummary(Integer.toString(settings.getWristFlickDuration()));
ListPreference toggle_widgets = (ListPreference) findPreference("pref_hybridhr_watchface_toggle_widgets");
toggle_widgets.setOnPreferenceChangeListener(this);
toggle_widgets.setValue(settings.getToggleWidgetsEvent());
toggle_widgets.setSummary(toggle_widgets.getEntry());
SwitchPreference power_saving_display = (SwitchPreference) findPreference("pref_hybridhr_watchface_power_saving_display"); SwitchPreference power_saving_display = (SwitchPreference) findPreference("pref_hybridhr_watchface_power_saving_display");
power_saving_display.setOnPreferenceChangeListener(new PreferenceChangeListener()); power_saving_display.setOnPreferenceChangeListener(this);
power_saving_display.setChecked(settings.getPowersaveDisplay()); power_saving_display.setChecked(settings.getPowersaveDisplay());
SwitchPreference power_saving_hands = (SwitchPreference) findPreference("pref_hybridhr_watchface_power_saving_hands"); SwitchPreference power_saving_hands = (SwitchPreference) findPreference("pref_hybridhr_watchface_power_saving_hands");
power_saving_hands.setOnPreferenceChangeListener(new PreferenceChangeListener()); power_saving_hands.setOnPreferenceChangeListener(this);
power_saving_hands.setChecked(settings.getPowersaveHands()); power_saving_hands.setChecked(settings.getPowersaveHands());
SwitchPreference light_up_on_notification = (SwitchPreference) findPreference("pref_hybridhr_watchface_light_up_on_notification"); SwitchPreference light_up_on_notification = (SwitchPreference) findPreference("pref_hybridhr_watchface_light_up_on_notification");
light_up_on_notification.setOnPreferenceChangeListener(new PreferenceChangeListener()); light_up_on_notification.setOnPreferenceChangeListener(this);
light_up_on_notification.setChecked(settings.getLightUpOnNotification()); light_up_on_notification.setChecked(settings.getLightUpOnNotification());
} }
private static class PreferenceChangeListener implements Preference.OnPreferenceChangeListener { @Override
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(Preference preference, Object newValue) { switch (preference.getKey()) {
switch (preference.getKey()) { case "pref_hybridhr_watchface_refresh_full":
case "pref_hybridhr_watchface_refresh_full": settings.setDisplayTimeoutFull(Integer.parseInt(newValue.toString()));
settings.setDisplayTimeoutFull(Integer.parseInt(newValue.toString())); preference.setSummary(newValue.toString());
preference.setSummary(newValue.toString()); break;
break; case "pref_hybridhr_watchface_refresh_partial":
case "pref_hybridhr_watchface_refresh_partial": settings.setDisplayTimeoutPartial(Integer.parseInt(newValue.toString()));
settings.setDisplayTimeoutPartial(Integer.parseInt(newValue.toString())); preference.setSummary(newValue.toString());
preference.setSummary(newValue.toString()); break;
break; case "pref_hybridhr_watchface_wrist_flick_relative":
case "pref_hybridhr_watchface_wrist_flick_relative": settings.setWristFlickHandsMoveRelative((boolean) newValue);
settings.setWristFlickHandsMoveRelative((boolean) newValue); break;
break; case "pref_hybridhr_watchface_wrist_flick_hour_hand":
case "pref_hybridhr_watchface_wrist_flick_hour_hand": settings.setWristFlickMoveHour(Integer.parseInt(newValue.toString()));
settings.setWristFlickMoveHour(Integer.parseInt(newValue.toString())); preference.setSummary(newValue.toString());
preference.setSummary(newValue.toString()); break;
break; case "pref_hybridhr_watchface_wrist_flick_minute_hand":
case "pref_hybridhr_watchface_wrist_flick_minute_hand": settings.setWristFlickMoveMinute(Integer.parseInt(newValue.toString()));
settings.setWristFlickMoveMinute(Integer.parseInt(newValue.toString())); preference.setSummary(newValue.toString());
preference.setSummary(newValue.toString()); break;
break; case "pref_hybridhr_watchface_wrist_flick_duration":
case "pref_hybridhr_watchface_light_up_on_notification": settings.setWristFlickDuration(Integer.parseInt(newValue.toString()));
settings.setLightUpOnNotification((boolean) newValue); preference.setSummary(newValue.toString());
break; break;
case "pref_hybridhr_watchface_wrist_flick_duration": case "pref_hybridhr_watchface_toggle_widgets":
settings.setWristFlickDuration(Integer.parseInt(newValue.toString())); settings.setToggleWidgetsEvent(newValue.toString());
preference.setSummary(newValue.toString()); ((ListPreference)preference).setValue(newValue.toString());
break; preference.setSummary(((ListPreference)preference).getEntry());
case "pref_hybridhr_watchface_power_saving_display": break;
settings.setPowersaveDisplay((boolean) newValue); case "pref_hybridhr_watchface_power_saving_display":
break; settings.setPowersaveDisplay((boolean) newValue);
case "pref_hybridhr_watchface_power_saving_hands": break;
settings.setPowersaveHands((boolean) newValue); case "pref_hybridhr_watchface_power_saving_hands":
break; settings.setPowersaveHands((boolean) newValue);
} break;
return true; case "pref_hybridhr_watchface_light_up_on_notification":
settings.setLightUpOnNotification((boolean) newValue);
break;
} }
return true;
} }
} }
} }

View File

@ -1824,6 +1824,23 @@
<item>widget_bg_dashed_circle</item> <item>widget_bg_dashed_circle</item>
</string-array> </string-array>
<string-array name="pref_hybridhr_watchface_togglewidgets_items">
<item name="">@string/menuitem_nothing</item>
<item name="top_short_press_release">@string/pref_title_upper_button_function_short</item>
<item name="top_hold">@string/pref_title_upper_button_function_long</item>
<item name="middle_short_press_release">@string/pref_title_middle_button_function_short</item>
<item name="bottom_short_press_release">@string/pref_title_lower_button_function_short</item>
<item name="bottom_hold">@string/pref_title_lower_button_function_long</item>
</string-array>
<string-array name="pref_hybridhr_watchface_togglewidgets_values">
<item></item>
<item>top_short_press_release</item>
<item>top_hold</item>
<item>middle_short_press_release</item>
<item>bottom_short_press_release</item>
<item>bottom_hold</item>
</string-array>
<string-array name="activity_filter_quick_filter_period_items"> <string-array name="activity_filter_quick_filter_period_items">
<item>@string/sports_activity_quick_filter_select</item> <item>@string/sports_activity_quick_filter_select</item>
<item>@string/sports_activity_quick_filter_this_week</item> <item>@string/sports_activity_quick_filter_this_week</item>

View File

@ -1470,6 +1470,8 @@
<string name="watchface_setting_wrist_flick_hour">Hour hand (-360 to 360)</string> <string name="watchface_setting_wrist_flick_hour">Hour hand (-360 to 360)</string>
<string name="watchface_setting_wrist_flick_minute">Minute hand (-360 to 360)</string> <string name="watchface_setting_wrist_flick_minute">Minute hand (-360 to 360)</string>
<string name="watchface_setting_wrist_flick_duration">Duration (in ms)</string> <string name="watchface_setting_wrist_flick_duration">Duration (in ms)</string>
<string name="watchface_setting_title_button_toggle_widgets">Toggle widgets</string>
<string name="watchface_setting_button_toggle_widgets">Button action</string>
<string name="watchface_cache_confirm_overwrite">A watchface with this name already exists in the cache. Do you want to overwrite it?</string> <string name="watchface_cache_confirm_overwrite">A watchface with this name already exists in the cache. Do you want to overwrite it?</string>
<string name="watchface_upload_failed">Upload of the watchface failed. Please try again.</string> <string name="watchface_upload_failed">Upload of the watchface failed. Please try again.</string>
<string name="watchface_widget_type_battery">Battery</string> <string name="watchface_widget_type_battery">Battery</string>

View File

@ -44,6 +44,20 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/watchface_setting_title_button_toggle_widgets">
<ListPreference
android:persistent="false"
android:title="@string/watchface_setting_button_toggle_widgets"
android:key="pref_hybridhr_watchface_toggle_widgets"
android:entries="@array/pref_hybridhr_watchface_togglewidgets_items"
android:entryValues="@array/pref_hybridhr_watchface_togglewidgets_values"
android:dialogTitle="@string/watchface_setting_button_toggle_widgets"
android:negativeButtonText="@string/Cancel"/>
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/watchface_setting_title_power_saving"> android:title="@string/watchface_setting_title_power_saving">

@ -1 +1 @@
Subproject commit 84b3c55cda7515761600daaebe79582c6e0d4686 Subproject commit 0e2551757d8c70031c2533d3d94a0f284c05ca9f