From 69fcec059ddef7156302cc44af3905cc93d51173 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Fri, 6 Oct 2023 22:06:35 +0200 Subject: [PATCH] Replace old-style preference switch with Material 3 switch --- .../AbstractPreferenceFragment.java | 6 +-- .../capabilities/HeartRateCapability.java | 8 ++-- .../HybridHRWatchfaceSettingsActivity.java | 10 ++-- .../HybridHRWatchfaceWidgetActivity.java | 6 +-- .../res/layout/preference_material_switch.xml | 10 ++++ app/src/main/res/values/styles.xml | 12 +++++ app/src/main/res/xml/charts_preferences.xml | 12 ++--- .../xml/devicesettings_always_on_display.xml | 2 +- .../main/res/xml/devicesettings_antilost.xml | 2 +- .../res/xml/devicesettings_autoheartrate.xml | 4 +- .../main/res/xml/devicesettings_autolight.xml | 2 +- .../xml/devicesettings_autoremove_message.xml | 2 +- ...evicesettings_autoremove_notifications.xml | 2 +- .../xml/devicesettings_banglejs_location.xml | 4 +- ...icesettings_bt_connected_advertisement.xml | 2 +- .../res/xml/devicesettings_buttonactions.xml | 4 +- ...esettings_buttonactions_with_longpress.xml | 4 +- .../res/xml/devicesettings_camera_remote.xml | 2 +- .../devicesettings_connect_two_devices.xml | 2 +- .../xml/devicesettings_custom_deviceicon.xml | 2 +- .../xml/devicesettings_custom_emoji_font.xml | 2 +- ..._device_card_activity_card_preferences.xml | 8 ++-- .../res/xml/devicesettings_device_intents.xml | 2 +- .../devicesettings_device_internet_access.xml | 2 +- ...settings_disconnectnotification_noshed.xml | 2 +- .../res/xml/devicesettings_display_caller.xml | 2 +- ...devicesettings_donotdisturb_lift_wrist.xml | 2 +- .../devicesettings_expose_hr_thirdparty.xml | 2 +- .../xml/devicesettings_fake_ring_duration.xml | 2 +- .../res/xml/devicesettings_fossilhybridhr.xml | 22 ++++----- ...devicesettings_fossilhybridhr_pre_fw20.xml | 4 +- .../res/xml/devicesettings_galaxy_buds.xml | 12 ++--- .../res/xml/devicesettings_galaxy_buds_2.xml | 18 ++++---- .../xml/devicesettings_galaxy_buds_2_pro.xml | 20 ++++---- .../xml/devicesettings_galaxy_buds_live.xml | 8 ++-- .../xml/devicesettings_galaxy_buds_pro.xml | 20 ++++---- .../xml/devicesettings_goal_notification.xml | 2 +- .../main/res/xml/devicesettings_gps_agps.xml | 2 +- .../xml/devicesettings_heartrate_sleep.xml | 2 +- ...evicesettings_heartrate_sleep_activity.xml | 4 +- ..._heartrate_sleep_alert_activity_stress.xml | 8 ++-- ...trate_sleep_alert_activity_stress_spo2.xml | 12 ++--- .../main/res/xml/devicesettings_high_mtu.xml | 2 +- .../res/xml/devicesettings_hourly_chime.xml | 2 +- .../xml/devicesettings_huami2021_alexa.xml | 2 +- ...gs_huami2021_fetch_operation_time_unit.xml | 2 +- .../xml/devicesettings_hydration_reminder.xml | 2 +- .../res/xml/devicesettings_inactivity.xml | 2 +- .../res/xml/devicesettings_inactivity_dnd.xml | 4 +- ...cesettings_inactivity_dnd_no_threshold.xml | 4 +- .../devicesettings_inactivity_extended.xml | 2 +- .../xml/devicesettings_inactivity_noshed.xml | 2 +- ...esettings_keep_activity_data_on_device.xml | 2 +- .../res/xml/devicesettings_key_vibration.xml | 2 +- ...evicesettings_liftwrist_display_noshed.xml | 2 +- .../res/xml/devicesettings_lock_unlock.xml | 2 +- .../devicesettings_lowlatency_fwupdate.xml | 2 +- .../main/res/xml/devicesettings_miband2.xml | 2 +- .../devicesettings_miband6_new_protocol.xml | 2 +- .../xml/devicesettings_morning_updates.xml | 2 +- .../res/xml/devicesettings_nothing_ear1.xml | 2 +- .../devicesettings_notifications_enable.xml | 2 +- .../res/xml/devicesettings_offline_voice.xml | 6 +-- .../xml/devicesettings_operating_sounds.xml | 2 +- ...tings_overwrite_settings_on_connection.xml | 2 +- .../main/res/xml/devicesettings_password.xml | 2 +- .../devicesettings_phone_calls_watch_pair.xml | 4 +- .../devicesettings_reconnect_bl_classic.xml | 2 +- .../res/xml/devicesettings_reconnect_ble.xml | 2 +- .../devicesettings_relax_firmware_checks.xml | 2 +- .../devicesettings_rotatewrist_cycleinfo.xml | 2 +- ...icesettings_screen_brightness_withauto.xml | 2 +- ...icesettings_screen_on_on_notifications.xml | 2 +- ...vicesettings_settings_third_party_apps.xml | 2 +- .../res/xml/devicesettings_sleep_mode.xml | 4 +- ..._sony_headphones_ambient_sound_control.xml | 2 +- ...ent_sound_control_wind_noise_reduction.xml | 2 +- ...tings_sony_headphones_audio_upsampling.xml | 2 +- ...y_headphones_notifications_voice_guide.xml | 2 +- ...s_sony_headphones_pause_when_taken_off.xml | 2 +- ...s_sony_headphones_speak_to_chat_simple.xml | 2 +- ...headphones_speak_to_chat_with_settings.xml | 4 +- ...gs_sony_headphones_touch_sensor_single.xml | 2 +- .../main/res/xml/devicesettings_sonyswr12.xml | 4 +- .../devicesettings_sound_and_vibration.xml | 10 ++-- .../res/xml/devicesettings_swipeunlock.xml | 2 +- .../res/xml/devicesettings_sync_calendar.xml | 2 +- .../res/xml/devicesettings_text_bitmaps.xml | 2 +- .../xml/devicesettings_vibrations_enable.xml | 2 +- .../res/xml/devicesettings_watchxplus.xml | 12 ++--- app/src/main/res/xml/devicesettings_wena3.xml | 14 +++--- .../xml/devicesettings_workout_detection.xml | 2 +- .../devicesettings_workout_keep_screen_on.xml | 2 +- ...evicesettings_workout_send_gps_to_band.xml | 2 +- .../devicesettings_workout_start_on_phone.xml | 2 +- .../res/xml/discovery_pairing_preferences.xml | 6 +-- .../res/xml/fossil_hr_watchface_settings.xml | 8 ++-- .../res/xml/fossil_hr_widget_settings.xml | 4 +- app/src/main/res/xml/hplus_preferences.xml | 2 +- app/src/main/res/xml/loyalty_cards.xml | 6 +-- app/src/main/res/xml/miband_preferences.xml | 4 +- .../res/xml/notifications_preferences.xml | 16 +++---- app/src/main/res/xml/pebble_preferences.xml | 28 +++++------ app/src/main/res/xml/preferences.xml | 46 +++++++++---------- app/src/main/res/xml/zetime_preferences.xml | 24 +++++----- 105 files changed, 287 insertions(+), 265 deletions(-) create mode 100644 app/src/main/res/layout/preference_material_switch.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java index bf1e5ae2b..07b4de95e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java @@ -29,7 +29,7 @@ import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceScreen; import androidx.preference.SeekBarPreference; -import androidx.preference.SwitchPreference; +import androidx.preference.SwitchPreferenceCompat; import com.mobeta.android.dslv.DragSortListPreference; import com.mobeta.android.dslv.DragSortListPreferenceFragment; @@ -183,8 +183,8 @@ public abstract class AbstractPreferenceFragment extends PreferenceFragmentCompa if (preference instanceof SeekBarPreference) { final SeekBarPreference seekBarPreference = (SeekBarPreference) preference; seekBarPreference.setValue(prefs.getInt(key, seekBarPreference.getValue())); - } else if (preference instanceof SwitchPreference) { - final SwitchPreference switchPreference = (SwitchPreference) preference; + } else if (preference instanceof SwitchPreferenceCompat) { + final SwitchPreferenceCompat switchPreference = (SwitchPreferenceCompat) preference; switchPreference.setChecked(prefs.getBoolean(key, switchPreference.isChecked())); } else if (preference instanceof ListPreference) { final ListPreference listPreference = (ListPreference) preference; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/HeartRateCapability.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/HeartRateCapability.java index c855c6203..6fd390d25 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/HeartRateCapability.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/HeartRateCapability.java @@ -28,7 +28,7 @@ import android.content.Context; import androidx.preference.ListPreference; import androidx.preference.Preference; -import androidx.preference.SwitchPreference; +import androidx.preference.SwitchPreferenceCompat; import java.util.List; @@ -109,9 +109,9 @@ public class HeartRateCapability { heartrateMeasurementInterval.setEntries(entries); heartrateMeasurementInterval.setEntryValues(values); - final SwitchPreference activityMonitoring = handler.findPreference(PREF_HEARTRATE_ACTIVITY_MONITORING); - final SwitchPreference heartrateAlertEnabled = handler.findPreference(PREF_HEARTRATE_ALERT_ENABLED); - final SwitchPreference stressMonitoring = handler.findPreference(PREF_HEARTRATE_STRESS_MONITORING); + final SwitchPreferenceCompat activityMonitoring = handler.findPreference(PREF_HEARTRATE_ACTIVITY_MONITORING); + final SwitchPreferenceCompat heartrateAlertEnabled = handler.findPreference(PREF_HEARTRATE_ALERT_ENABLED); + final SwitchPreferenceCompat stressMonitoring = handler.findPreference(PREF_HEARTRATE_STRESS_MONITORING); heartrateMeasurementInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(final Preference preference, final Object newVal) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java index fd72ab140..8e43162ee 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java @@ -25,7 +25,7 @@ import androidx.preference.EditTextPreference; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.SwitchPreference; +import androidx.preference.SwitchPreferenceCompat; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment; @@ -99,7 +99,7 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivityV refresh_partial.setSummary(Integer.toString(settings.getDisplayTimeoutPartial())); setInputTypeFor("pref_hybridhr_watchface_refresh_partial", InputType.TYPE_CLASS_NUMBER); - SwitchPreference wrist_flick_relative = findPreference("pref_hybridhr_watchface_wrist_flick_relative"); + SwitchPreferenceCompat wrist_flick_relative = findPreference("pref_hybridhr_watchface_wrist_flick_relative"); wrist_flick_relative.setOnPreferenceChangeListener(this); wrist_flick_relative.setChecked(settings.isWristFlickHandsMoveRelative()); @@ -136,15 +136,15 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivityV move_hands.setValue(settings.getMoveHandsEvent()); move_hands.setSummary(move_hands.getEntry()); - SwitchPreference power_saving_display = findPreference("pref_hybridhr_watchface_power_saving_display"); + SwitchPreferenceCompat power_saving_display = findPreference("pref_hybridhr_watchface_power_saving_display"); power_saving_display.setOnPreferenceChangeListener(this); power_saving_display.setChecked(settings.getPowersaveDisplay()); - SwitchPreference power_saving_hands = findPreference("pref_hybridhr_watchface_power_saving_hands"); + SwitchPreferenceCompat power_saving_hands = findPreference("pref_hybridhr_watchface_power_saving_hands"); power_saving_hands.setOnPreferenceChangeListener(this); power_saving_hands.setChecked(settings.getPowersaveHands()); - SwitchPreference light_up_on_notification = findPreference("pref_hybridhr_watchface_light_up_on_notification"); + SwitchPreferenceCompat light_up_on_notification = findPreference("pref_hybridhr_watchface_light_up_on_notification"); light_up_on_notification.setOnPreferenceChangeListener(this); light_up_on_notification.setChecked(settings.getLightUpOnNotification()); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidgetActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidgetActivity.java index e7bdfbc35..a8fca2b59 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidgetActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidgetActivity.java @@ -26,7 +26,7 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.SwitchPreference; +import androidx.preference.SwitchPreferenceCompat; import java.util.LinkedHashMap; import java.util.TimeZone; @@ -173,11 +173,11 @@ public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivityV2 customWidgetTimeout.setSummary(Integer.toString(widget.getExtraConfigInt("update_timeout", WIDGET_CUSTOM_DEFAULT_TIMEOUT))); setInputTypeFor("pref_hybridhr_widget_custom_timeout", InputType.TYPE_CLASS_NUMBER); - SwitchPreference customWidgetHideText = findPreference("pref_hybridhr_widget_custom_hide_text"); + SwitchPreferenceCompat customWidgetHideText = findPreference("pref_hybridhr_widget_custom_hide_text"); customWidgetHideText.setOnPreferenceChangeListener(this); customWidgetHideText.setChecked(widget.getExtraConfigBoolean("timeout_hide_text", WIDGET_CUSTOM_DEFAULT_HIDE_TEXT)); - SwitchPreference customWidgetShowCircle = findPreference("pref_hybridhr_widget_custom_show_circle"); + SwitchPreferenceCompat customWidgetShowCircle = findPreference("pref_hybridhr_widget_custom_show_circle"); customWidgetShowCircle.setOnPreferenceChangeListener(this); customWidgetShowCircle.setChecked(widget.getExtraConfigBoolean("timeout_show_circle", WIDGET_CUSTOM_DEFAULT_SHOW_CIRCLE)); } diff --git a/app/src/main/res/layout/preference_material_switch.xml b/app/src/main/res/layout/preference_material_switch.xml new file mode 100644 index 000000000..af3272ec5 --- /dev/null +++ b/app/src/main/res/layout/preference_material_switch.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 303953358..efbac57ed 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -18,6 +18,7 @@ @style/GadgetbridgeTheme.DrawerButtonStyle @style/GadgetbridgeTheme.NavigationButtonStyle @style/GadgetbridgeTheme.OverflowMenuButton + @style/AppPreferenceThemeOverlay ?attr/colorPrimaryDark @android:color/white @@ -51,6 +52,7 @@ @style/GadgetbridgeTheme.DrawerButtonStyle @style/GadgetbridgeTheme.NavigationButtonStyle @style/GadgetbridgeTheme.OverflowMenuButton + @style/AppPreferenceThemeOverlay ?attr/colorPrimaryDark @android:color/white @@ -84,6 +86,7 @@ ?attr/colorOnSurface ?attr/colorSecondaryContainer ?attr/colorSurface + @style/AppPreferenceThemeOverlay + + + + diff --git a/app/src/main/res/xml/charts_preferences.xml b/app/src/main/res/xml/charts_preferences.xml index 17eb110df..8d12ffa0a 100644 --- a/app/src/main/res/xml/charts_preferences.xml +++ b/app/src/main/res/xml/charts_preferences.xml @@ -24,7 +24,7 @@ app:iconSpaceReserved="false" app:useSimpleSummaryProvider="true" /> - - - - - - - diff --git a/app/src/main/res/xml/devicesettings_antilost.xml b/app/src/main/res/xml/devicesettings_antilost.xml index a4c9dc705..491daf709 100644 --- a/app/src/main/res/xml/devicesettings_antilost.xml +++ b/app/src/main/res/xml/devicesettings_antilost.xml @@ -1,6 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/xml/devicesettings_inactivity.xml b/app/src/main/res/xml/devicesettings_inactivity.xml index a5cddd42c..55f33896b 100644 --- a/app/src/main/res/xml/devicesettings_inactivity.xml +++ b/app/src/main/res/xml/devicesettings_inactivity.xml @@ -7,7 +7,7 @@ android:summary="@string/mi2_prefs_inactivity_warnings_summary" android:title="@string/mi2_prefs_inactivity_warnings"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/xml/devicesettings_wena3.xml b/app/src/main/res/xml/devicesettings_wena3.xml index 549a3b20c..914770bef 100644 --- a/app/src/main/res/xml/devicesettings_wena3.xml +++ b/app/src/main/res/xml/devicesettings_wena3.xml @@ -3,7 +3,7 @@ - - - - - - - diff --git a/app/src/main/res/xml/devicesettings_workout_detection.xml b/app/src/main/res/xml/devicesettings_workout_detection.xml index 3b58eb98c..00930b394 100644 --- a/app/src/main/res/xml/devicesettings_workout_detection.xml +++ b/app/src/main/res/xml/devicesettings_workout_detection.xml @@ -17,7 +17,7 @@ android:summary="@string/pref_workout_detection_categories_summary" android:title="@string/pref_workout_detection_categories_title" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -