From 53aa8f98ae235a4f38af2a225a795f595caffc7c Mon Sep 17 00:00:00 2001 From: Valter Costa Date: Tue, 14 Oct 2025 20:47:46 +0100 Subject: [PATCH 1/3] Don't adjust audio alert volume when using bell --- .../com/valterc/ki2/input/ActionAdapter.java | 6 +- .../valterc/ki2/karoo/audio/AudioManager.kt | 84 +++++++++++++------ 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java b/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java index 6010894..4daa8b9 100644 --- a/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java +++ b/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java @@ -47,9 +47,9 @@ public ActionAdapter(Ki2ExtensionContext context) { this.keyMapping.put(KarooAction.VIRTUAL_TOGGLE_AUDIO_ALERTS, karooKeyEvent -> toggleAudioAlerts(context)); this.keyMapping.put(KarooAction.VIRTUAL_DISABLE_AUDIO_ALERTS, karooKeyEvent -> disableAudioAlerts(context)); this.keyMapping.put(KarooAction.VIRTUAL_ENABLE_AUDIO_ALERTS, karooKeyEvent -> enableAudioAlerts(context)); - this.keyMapping.put(KarooAction.VIRTUAL_SINGLE_BEEP, karooKeyEvent -> context.getAudioManager().playSingleBeep()); - this.keyMapping.put(KarooAction.VIRTUAL_DOUBLE_BEEP, karooKeyEvent -> context.getAudioManager().playDoubleBeep()); - this.keyMapping.put(KarooAction.VIRTUAL_BELL, karooKeyEvent -> context.getAudioManager().playKarooBell()); + this.keyMapping.put(KarooAction.VIRTUAL_SINGLE_BEEP, karooKeyEvent -> context.getAudioManager().playSingleBeep(false)); + this.keyMapping.put(KarooAction.VIRTUAL_DOUBLE_BEEP, karooKeyEvent -> context.getAudioManager().playDoubleBeep(false)); + this.keyMapping.put(KarooAction.VIRTUAL_BELL, karooKeyEvent -> context.getAudioManager().playKarooBell(false)); this.keyMapping.put(KarooAction.VIRTUAL_LAP, karooKeyEvent -> context.getKarooSystem().dispatch(MarkLap.INSTANCE)); this.keyMapping.put(KarooAction.VIRTUAL_ZOOM_IN, karooKeyEvent -> context.getKarooSystem().dispatch(new ZoomPage(true))); this.keyMapping.put(KarooAction.VIRTUAL_ZOOM_OUT, karooKeyEvent -> context.getKarooSystem().dispatch(new ZoomPage(false))); diff --git a/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt b/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt index 4b8d45c..de0bf55 100644 --- a/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt +++ b/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt @@ -63,26 +63,48 @@ class AudioManager(private val context: Ki2ExtensionContext) { else -> max(times(intensity.durationMultiplierK24).toInt(), 50) } - fun playSingleBeep() { - context.karooSystem.dispatch( - PlayBeepPattern( - listOf( - PlayBeepPattern.Tone(5000.f, 350.d) + fun playSingleBeep(adjustVolume: Boolean = true) { + if (adjustVolume){ + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(5000.f, 350.d) + ) ) ) - ) + } else { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(5000, 350) + ) + ) + ) + } } - fun playDoubleBeep() { - context.karooSystem.dispatch( - PlayBeepPattern( - listOf( - PlayBeepPattern.Tone(5000.f, 350.d), - PlayBeepPattern.Tone(null, 150.d), - PlayBeepPattern.Tone(5000.f, 350.d) + fun playDoubleBeep(adjustVolume: Boolean = true) { + if (adjustVolume) { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(5000.f, 350.d), + PlayBeepPattern.Tone(null, 150.d), + PlayBeepPattern.Tone(5000.f, 350.d) + ) ) ) - ) + } else { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(5000, 350), + PlayBeepPattern.Tone(null, 150), + PlayBeepPattern.Tone(5000, 350) + ) + ) + ) + } } private fun playKarooGeneric() { @@ -101,18 +123,32 @@ class AudioManager(private val context: Ki2ExtensionContext) { ) } - fun playKarooBell() { - context.karooSystem.dispatch( - PlayBeepPattern( - listOf( - PlayBeepPattern.Tone(3750.f, 50.d), - PlayBeepPattern.Tone(5800.f, 200.d), - PlayBeepPattern.Tone(null, 50.d), - PlayBeepPattern.Tone(3750.f, 50.d), - PlayBeepPattern.Tone(5800.f, 300.d) + fun playKarooBell(adjustVolume: Boolean = true) { + if (adjustVolume){ + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(2349.f, 31.d), + PlayBeepPattern.Tone(3520.f, 125.d), + PlayBeepPattern.Tone(null, 31.d), + PlayBeepPattern.Tone(2349.f, 31.d), + PlayBeepPattern.Tone(3520.f, 406.d) + ) ) ) - ) + } else { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(2349, 31), + PlayBeepPattern.Tone(3520, 125), + PlayBeepPattern.Tone(null, 31), + PlayBeepPattern.Tone(2349, 31), + PlayBeepPattern.Tone(3520, 406) + ) + ) + ) + } } fun playKarooDeviceWarning() { From 99aede934fe43b44803ec73d4e3197480c036313 Mon Sep 17 00:00:00 2001 From: Valter Costa Date: Thu, 16 Oct 2025 13:07:53 +0100 Subject: [PATCH 2/3] Add option for old and new Karoo bell --- .../valterc/ki2/data/action/KarooAction.java | 3 +- .../ki2/data/message/AudioAlertMessage.java | 16 ++- .../com/valterc/ki2/input/ActionAdapter.java | 3 +- .../com/valterc/ki2/input/InputManager.java | 23 ++++- .../valterc/ki2/karoo/audio/AudioManager.kt | 43 ++++++-- .../ki2/update/post/PostUpdateActions.java | 2 + .../post/actions/KarooBellUpdateAction.kt | 50 ++++++++++ .../preference/SwitchListPreference.java | 97 +++++++++++++++++++ app/src/main/res/values/arrays.xml | 34 ++++--- app/src/main/res/xml/preferences_switches.xml | 24 ++--- 10 files changed, 255 insertions(+), 40 deletions(-) create mode 100644 app/src/main/java/com/valterc/ki2/update/post/actions/KarooBellUpdateAction.kt create mode 100644 app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java diff --git a/app/src/main/java/com/valterc/ki2/data/action/KarooAction.java b/app/src/main/java/com/valterc/ki2/data/action/KarooAction.java index ffd183c..6918d47 100644 --- a/app/src/main/java/com/valterc/ki2/data/action/KarooAction.java +++ b/app/src/main/java/com/valterc/ki2/data/action/KarooAction.java @@ -23,7 +23,8 @@ public enum KarooAction { VIRTUAL_ENABLE_AUDIO_ALERTS, VIRTUAL_SINGLE_BEEP, VIRTUAL_DOUBLE_BEEP, - VIRTUAL_BELL, + VIRTUAL_BELL_OLD, + VIRTUAL_BELL_NEW, VIRTUAL_LAP, VIRTUAL_ZOOM_OUT, VIRTUAL_ZOOM_IN, diff --git a/app/src/main/java/com/valterc/ki2/data/message/AudioAlertMessage.java b/app/src/main/java/com/valterc/ki2/data/message/AudioAlertMessage.java index 24895e4..f908691 100644 --- a/app/src/main/java/com/valterc/ki2/data/message/AudioAlertMessage.java +++ b/app/src/main/java/com/valterc/ki2/data/message/AudioAlertMessage.java @@ -3,8 +3,9 @@ import android.os.Bundle; public class AudioAlertMessage extends Message { - private static final String KEY_NAME = "name"; public static final String KEY = "audio-alert"; + private static final String KEY_NAME = "name"; + private static final String KEY_ADJUST_INTENSITY = "adjust-intensity"; public static AudioAlertMessage parse(Message message) { if (!message.getClassType().equals(AudioAlertMessage.class.getName())) { @@ -15,21 +16,32 @@ public static AudioAlertMessage parse(Message message) { } private final String name; + private final boolean adjustIntensity; private AudioAlertMessage(Message message) { super(message); name = getBundle().getString(KEY_NAME); + adjustIntensity = getBundle().getBoolean(KEY_ADJUST_INTENSITY); } - public AudioAlertMessage(String name) { + public AudioAlertMessage(String name, boolean adjustIntensity) { super(KEY, new Bundle(), MessageType.AUDIO_ALERT, false); getBundle().putString(KEY_NAME, name); + getBundle().putBoolean(KEY_ADJUST_INTENSITY, adjustIntensity); this.name = name; + this.adjustIntensity = adjustIntensity; + } + + public AudioAlertMessage(String name) { + this(name, true); } public String getName() { return name; } + public boolean getAdjustIntensity() { + return adjustIntensity; + } } diff --git a/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java b/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java index 4daa8b9..f44d108 100644 --- a/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java +++ b/app/src/main/java/com/valterc/ki2/input/ActionAdapter.java @@ -49,7 +49,8 @@ public ActionAdapter(Ki2ExtensionContext context) { this.keyMapping.put(KarooAction.VIRTUAL_ENABLE_AUDIO_ALERTS, karooKeyEvent -> enableAudioAlerts(context)); this.keyMapping.put(KarooAction.VIRTUAL_SINGLE_BEEP, karooKeyEvent -> context.getAudioManager().playSingleBeep(false)); this.keyMapping.put(KarooAction.VIRTUAL_DOUBLE_BEEP, karooKeyEvent -> context.getAudioManager().playDoubleBeep(false)); - this.keyMapping.put(KarooAction.VIRTUAL_BELL, karooKeyEvent -> context.getAudioManager().playKarooBell(false)); + this.keyMapping.put(KarooAction.VIRTUAL_BELL_OLD, karooKeyEvent -> context.getAudioManager().playKarooBellOld(false)); + this.keyMapping.put(KarooAction.VIRTUAL_BELL_NEW, karooKeyEvent -> context.getAudioManager().playKarooBellNew(false)); this.keyMapping.put(KarooAction.VIRTUAL_LAP, karooKeyEvent -> context.getKarooSystem().dispatch(MarkLap.INSTANCE)); this.keyMapping.put(KarooAction.VIRTUAL_ZOOM_IN, karooKeyEvent -> context.getKarooSystem().dispatch(new ZoomPage(true))); this.keyMapping.put(KarooAction.VIRTUAL_ZOOM_OUT, karooKeyEvent -> context.getKarooSystem().dispatch(new ZoomPage(false))); diff --git a/app/src/main/java/com/valterc/ki2/input/InputManager.java b/app/src/main/java/com/valterc/ki2/input/InputManager.java index e99767f..95f7c50 100644 --- a/app/src/main/java/com/valterc/ki2/input/InputManager.java +++ b/app/src/main/java/com/valterc/ki2/input/InputManager.java @@ -54,7 +54,8 @@ public class InputManager { preferenceToSwitchKeyMap.put("press_enable_audio_alerts", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_ENABLE_AUDIO_ALERTS, switchEvent.getRepeat())); preferenceToSwitchKeyMap.put("press_single_beep", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_SINGLE_BEEP, switchEvent.getRepeat())); preferenceToSwitchKeyMap.put("press_double_beep", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_DOUBLE_BEEP, switchEvent.getRepeat())); - preferenceToSwitchKeyMap.put("press_bell", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_BELL, switchEvent.getRepeat())); + preferenceToSwitchKeyMap.put("press_bell_old", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_BELL_OLD, switchEvent.getRepeat())); + preferenceToSwitchKeyMap.put("press_bell_new", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_BELL_NEW, switchEvent.getRepeat())); preferenceToSwitchKeyMap.put("press_control_center", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_CONTROL_CENTER, switchEvent.getRepeat())); preferenceToSwitchKeyMap.put("press_drawer_action", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_DRAWER_ACTION, switchEvent.getRepeat())); preferenceToSwitchKeyMap.put("press_toggle_overlay", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_TOGGLE_OVERLAY, switchEvent.getRepeat())); @@ -200,17 +201,29 @@ public class InputManager { } return new KarooActionEvent(KarooAction.VIRTUAL_SINGLE_BEEP, switchEvent.getRepeat()); }); - preferenceToSwitchKeyMap.put("hold_short_single_bell", (switchEvent, converter) -> { + preferenceToSwitchKeyMap.put("hold_short_single_bell_old", (switchEvent, converter) -> { if (switchEvent.getCommand() != SwitchCommand.LONG_PRESS_DOWN) { return null; } - return new KarooActionEvent(KarooAction.VIRTUAL_BELL, switchEvent.getRepeat()); + return new KarooActionEvent(KarooAction.VIRTUAL_BELL_OLD, switchEvent.getRepeat()); }); - preferenceToSwitchKeyMap.put("hold_continuous_bell", (switchEvent, converter) -> { + preferenceToSwitchKeyMap.put("hold_short_single_bell_new", (switchEvent, converter) -> { + if (switchEvent.getCommand() != SwitchCommand.LONG_PRESS_DOWN) { + return null; + } + return new KarooActionEvent(KarooAction.VIRTUAL_BELL_NEW, switchEvent.getRepeat()); + }); + preferenceToSwitchKeyMap.put("hold_continuous_bell_old", (switchEvent, converter) -> { + if (switchEvent.getCommand() == SwitchCommand.LONG_PRESS_UP) { + return null; + } + return new KarooActionEvent(KarooAction.VIRTUAL_BELL_OLD, switchEvent.getRepeat()); + }); + preferenceToSwitchKeyMap.put("hold_continuous_bell_new", (switchEvent, converter) -> { if (switchEvent.getCommand() == SwitchCommand.LONG_PRESS_UP) { return null; } - return new KarooActionEvent(KarooAction.VIRTUAL_BELL, switchEvent.getRepeat()); + return new KarooActionEvent(KarooAction.VIRTUAL_BELL_NEW, switchEvent.getRepeat()); }); preferenceToSwitchKeyMap.put("hold_short_single_toggle_overlay", (switchEvent, converter) -> { if (switchEvent.getCommand() != SwitchCommand.LONG_PRESS_DOWN) { diff --git a/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt b/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt index de0bf55..3ef07df 100644 --- a/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt +++ b/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt @@ -43,7 +43,8 @@ class AudioManager(private val context: Ki2ExtensionContext) { private fun playAudio(audio: String?) { when (audio) { "karoo_generic" -> playKarooGeneric() - "karoo_bell" -> playKarooBell() + "karoo_bell_old" -> playKarooBellOld() + "karoo_bell_new" -> playKarooBellNew() "custom_single_beep" -> playSingleBeep() "custom_double_beep" -> playDoubleBeep() "disabled" -> return @@ -63,8 +64,8 @@ class AudioManager(private val context: Ki2ExtensionContext) { else -> max(times(intensity.durationMultiplierK24).toInt(), 50) } - fun playSingleBeep(adjustVolume: Boolean = true) { - if (adjustVolume){ + fun playSingleBeep(adjustIntensity: Boolean = true) { + if (adjustIntensity){ context.karooSystem.dispatch( PlayBeepPattern( listOf( @@ -83,8 +84,8 @@ class AudioManager(private val context: Ki2ExtensionContext) { } } - fun playDoubleBeep(adjustVolume: Boolean = true) { - if (adjustVolume) { + fun playDoubleBeep(adjustIntensity: Boolean = true) { + if (adjustIntensity) { context.karooSystem.dispatch( PlayBeepPattern( listOf( @@ -123,8 +124,36 @@ class AudioManager(private val context: Ki2ExtensionContext) { ) } - fun playKarooBell(adjustVolume: Boolean = true) { - if (adjustVolume){ + fun playKarooBellOld(adjustIntensity: Boolean = true) { + if (adjustIntensity){ + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(3750.f, 50.d), + PlayBeepPattern.Tone(5800.f, 200.d), + PlayBeepPattern.Tone(null, 50.d), + PlayBeepPattern.Tone(3750.f, 50.d), + PlayBeepPattern.Tone(5800.f, 300.d) + ) + ) + ) + } else { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(3750, 50), + PlayBeepPattern.Tone(5800, 200), + PlayBeepPattern.Tone(null, 50), + PlayBeepPattern.Tone(3750, 50), + PlayBeepPattern.Tone(5800, 300) + ) + ) + ) + } + } + + fun playKarooBellNew(adjustIntensity: Boolean = true) { + if (adjustIntensity){ context.karooSystem.dispatch( PlayBeepPattern( listOf( diff --git a/app/src/main/java/com/valterc/ki2/update/post/PostUpdateActions.java b/app/src/main/java/com/valterc/ki2/update/post/PostUpdateActions.java index 23a5943..0f2791c 100644 --- a/app/src/main/java/com/valterc/ki2/update/post/PostUpdateActions.java +++ b/app/src/main/java/com/valterc/ki2/update/post/PostUpdateActions.java @@ -7,6 +7,7 @@ import com.valterc.ki2.update.post.actions.IPostUpdateAction; import com.valterc.ki2.update.post.actions.IPreInitPostUpdateAction; import com.valterc.ki2.update.post.actions.KarooAudioAlertsUpdateAction; +import com.valterc.ki2.update.post.actions.KarooBellUpdateAction; import com.valterc.ki2.update.post.actions.ShowOverlayUpdateAction; import java.util.HashMap; @@ -26,6 +27,7 @@ private PostUpdateActions() { preInitActionMap = new HashMap<>(); preInitActionMap.put(KarooAudioAlertsUpdateAction.class.getSimpleName(), new KarooAudioAlertsUpdateAction()); preInitActionMap.put(ShowOverlayUpdateAction.class.getSimpleName(), new ShowOverlayUpdateAction()); + preInitActionMap.put(KarooBellUpdateAction.class.getSimpleName(), new KarooBellUpdateAction()); postInitActionMap = new HashMap<>(); } diff --git a/app/src/main/java/com/valterc/ki2/update/post/actions/KarooBellUpdateAction.kt b/app/src/main/java/com/valterc/ki2/update/post/actions/KarooBellUpdateAction.kt new file mode 100644 index 0000000..7ed3877 --- /dev/null +++ b/app/src/main/java/com/valterc/ki2/update/post/actions/KarooBellUpdateAction.kt @@ -0,0 +1,50 @@ +package com.valterc.ki2.update.post.actions + +import androidx.core.content.edit +import androidx.preference.PreferenceManager +import com.valterc.ki2.R +import com.valterc.ki2.update.post.PostUpdateContext + +class KarooBellUpdateAction : IPreInitPostUpdateAction { + override fun execute(context: PostUpdateContext) { + val preferences = PreferenceManager.getDefaultSharedPreferences(context.context) + + val preferencesWithPossibleBellValue = listOf( + context.context.getString(R.string.preference_audio_alert_lowest_gear), + context.context.getString(R.string.preference_audio_alert_highest_gear), + context.context.getString(R.string.preference_audio_alert_shifting_limit), + context.context.getString(R.string.preference_audio_alert_upcoming_synchro_shift), + context.context.getString(R.string.preference_switch_ch1_single_press), + context.context.getString(R.string.preference_switch_ch1_double_press), + context.context.getString(R.string.preference_switch_ch1_hold), + context.context.getString(R.string.preference_switch_ch2_single_press), + context.context.getString(R.string.preference_switch_ch2_double_press), + context.context.getString(R.string.preference_switch_ch2_hold), + context.context.getString(R.string.preference_switch_ch3_single_press), + context.context.getString(R.string.preference_switch_ch3_double_press), + context.context.getString(R.string.preference_switch_ch3_hold), + context.context.getString(R.string.preference_switch_ch4_single_press), + context.context.getString(R.string.preference_switch_ch4_double_press), + context.context.getString(R.string.preference_switch_ch4_hold), + ) + + for (preferenceKey in preferencesWithPossibleBellValue) { + val preferenceValue = preferences.getString(preferenceKey, null) + + when (preferenceValue) { + "press_bell" -> preferences.edit { + putString(preferenceKey, "press_bell_old") + } + "hold_short_single_bell" -> preferences.edit { + putString(preferenceKey, "hold_short_single_bell_old") + } + "hold_continuous_bell" -> preferences.edit { + putString(preferenceKey, "hold_continuous_bell_old") + } + "karoo_bell" -> preferences.edit { + putString(preferenceKey, "karoo_bell_old") + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java b/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java new file mode 100644 index 0000000..5102896 --- /dev/null +++ b/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java @@ -0,0 +1,97 @@ +package com.valterc.ki2.views.preference; + +import android.content.ComponentName; +import android.content.Context; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.util.AttributeSet; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.preference.ListPreference; + +import com.valterc.ki2.data.message.AudioAlertMessage; +import com.valterc.ki2.services.IKi2Service; +import com.valterc.ki2.services.Ki2Service; + +import timber.log.Timber; + +@SuppressWarnings("unused") +public class SwitchListPreference extends ListPreference { + + private final ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + service = IKi2Service.Stub.asInterface(binder); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + service = null; + } + }; + + private IKi2Service service; + private boolean serviceBound; + + public SwitchListPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public SwitchListPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SwitchListPreference(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public SwitchListPreference(@NonNull Context context) { + super(context); + } + + @Override + public void setValue(String value) { + super.setValue(value); + + try { + if (service != null) { + switch (value) { + case "press_single_beep": service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); + case "press_double_beep": service.sendMessage(new AudioAlertMessage("custom_double_beep", false)); + case "press_bell_old": service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); + case "press_bell_new": service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); + case "hold_short_single_single_beep": service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); + case "hold_short_single_double_beep": service.sendMessage(new AudioAlertMessage("custom_double_beep", false)); + case "hold_short_single_bell_old": service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); + case "hold_short_single_bell_new": service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); + case "hold_continuous_single_beep": service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); + case "hold_continuous_bell_old": service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); + case "hold_continuous_bell_new": service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); + } + } + } catch (Exception e) { + Timber.w(e, "Unable to send message"); + } + } + + @Override + public void onAttached() { + super.onAttached(); + serviceBound = getContext().bindService(Ki2Service.getIntent(), serviceConnection, Context.BIND_AUTO_CREATE); + } + + @Override + public void onDetached() { + super.onDetached(); + + if (serviceBound) { + serviceBound = false; + try { + getContext().unbindService(serviceConnection); + } catch (Exception e) { + // ignore + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index d4c7ea0..7546074 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -19,7 +19,8 @@ Enable Shifting Audio Alerts Single Beep Double Beep - Bell + Bell (old) + Bell (new) Control Center Drawer @@ -44,7 +45,8 @@ press_enable_audio_alerts press_single_beep press_double_beep - press_bell + press_bell_old + press_bell_new press_control_center press_drawer_action @@ -70,7 +72,8 @@ Enable Shifting Audio Alerts Single Beep Double Beep - Bell + Bell (old) + Bell (new) Control Center Drawer @@ -96,7 +99,8 @@ press_enable_audio_alerts press_single_beep press_double_beep - press_bell + press_bell_old + press_bell_new press_control_center press_drawer_action @@ -124,11 +128,13 @@ Enable Shifting Audio Alerts Single Beep Double Beep - Bell + Bell (old) + Bell (new) Control Center Drawer Continuous Single Beep - Continuous Bell + Continuous Bell (old) + Continuous Bell (new) @@ -154,11 +160,13 @@ hold_short_single_enable_audio_alerts hold_short_single_single_beep hold_short_single_double_beep - hold_short_single_bell + hold_short_single_bell_old + hold_short_single_bell_new hold_short_single_control_center hold_short_single_drawer_action hold_continuous_single_beep - hold_continuous_bell + hold_continuous_bell_old + hold_continuous_bell_new @@ -225,18 +233,20 @@ Disabled - Karoo - Generic - Karoo - Bell Single Beep Double Beep + Karoo - Generic + Karoo - Bell (old) + Karoo - Bell (new) @string/value_preference_audio_alert_disabled - karoo_generic - karoo_bell custom_single_beep custom_double_beep + karoo_generic + karoo_bell_old + karoo_bell_new diff --git a/app/src/main/res/xml/preferences_switches.xml b/app/src/main/res/xml/preferences_switches.xml index 321de1f..b3cabe8 100644 --- a/app/src/main/res/xml/preferences_switches.xml +++ b/app/src/main/res/xml/preferences_switches.xml @@ -5,7 +5,7 @@ - - - - - - - - - - - - Date: Fri, 17 Oct 2025 10:04:19 +0100 Subject: [PATCH 3/3] Improve audio alerts --- .../valterc/ki2/karoo/audio/AudioManager.kt | 54 ++++++++++++------- .../preference/AudioAlertPreference.java | 2 +- .../preference/AudioPlaybackPreference.java | 2 +- .../preference/SwitchListPreference.java | 30 +++++++---- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt b/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt index 3ef07df..864c59e 100644 --- a/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt +++ b/app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt @@ -21,7 +21,7 @@ class AudioManager(private val context: Ki2ExtensionContext) { private var intensity: AudioIntensity = AudioIntensity.Normal private val playAudioConsumer = Consumer { - playAudio(it.name) + playAudio(it.name, it.adjustIntensity) } private val preferencesConsumer = Consumer { preferences -> @@ -40,13 +40,13 @@ class AudioManager(private val context: Ki2ExtensionContext) { context.serviceClient.registerPreferencesWeakListener(preferencesConsumer) } - private fun playAudio(audio: String?) { + private fun playAudio(audio: String?, adjustIntensity: Boolean = true) { when (audio) { - "karoo_generic" -> playKarooGeneric() - "karoo_bell_old" -> playKarooBellOld() - "karoo_bell_new" -> playKarooBellNew() - "custom_single_beep" -> playSingleBeep() - "custom_double_beep" -> playDoubleBeep() + "karoo_generic" -> playKarooGeneric(adjustIntensity) + "karoo_bell_old" -> playKarooBellOld(adjustIntensity) + "karoo_bell_new" -> playKarooBellNew(adjustIntensity) + "custom_single_beep" -> playSingleBeep(adjustIntensity) + "custom_double_beep" -> playDoubleBeep(adjustIntensity) "disabled" -> return else -> Timber.i("Unknown audio requested '%s'", audio) } @@ -108,20 +108,36 @@ class AudioManager(private val context: Ki2ExtensionContext) { } } - private fun playKarooGeneric() { - context.karooSystem.dispatch( - PlayBeepPattern( - listOf( - PlayBeepPattern.Tone(5000.f, 350.d), - PlayBeepPattern.Tone(null, 100.d), - PlayBeepPattern.Tone(4250.f, 100.d), - PlayBeepPattern.Tone(null, 50.d), - PlayBeepPattern.Tone(4250.f, 100.d), - PlayBeepPattern.Tone(null, 50.d), - PlayBeepPattern.Tone(4250.f, 100.d) + private fun playKarooGeneric(adjustIntensity: Boolean = true) { + if (adjustIntensity) { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(5000.f, 350.d), + PlayBeepPattern.Tone(null, 100.d), + PlayBeepPattern.Tone(4250.f, 100.d), + PlayBeepPattern.Tone(null, 50.d), + PlayBeepPattern.Tone(4250.f, 100.d), + PlayBeepPattern.Tone(null, 50.d), + PlayBeepPattern.Tone(4250.f, 100.d) + ) ) ) - ) + } else { + context.karooSystem.dispatch( + PlayBeepPattern( + listOf( + PlayBeepPattern.Tone(5000, 350), + PlayBeepPattern.Tone(null, 100), + PlayBeepPattern.Tone(4250, 100), + PlayBeepPattern.Tone(null, 50), + PlayBeepPattern.Tone(4250, 100), + PlayBeepPattern.Tone(null, 50), + PlayBeepPattern.Tone(4250, 100) + ) + ) + ) + } } fun playKarooBellOld(adjustIntensity: Boolean = true) { diff --git a/app/src/main/java/com/valterc/ki2/views/preference/AudioAlertPreference.java b/app/src/main/java/com/valterc/ki2/views/preference/AudioAlertPreference.java index 912148b..725760c 100644 --- a/app/src/main/java/com/valterc/ki2/views/preference/AudioAlertPreference.java +++ b/app/src/main/java/com/valterc/ki2/views/preference/AudioAlertPreference.java @@ -55,7 +55,7 @@ public void setValue(String value) { try { if (service != null) { - service.sendMessage(new AudioAlertMessage(value)); + service.sendMessage(new AudioAlertMessage(value, true)); } } catch (Exception e) { Timber.w(e, "Unable to send message"); diff --git a/app/src/main/java/com/valterc/ki2/views/preference/AudioPlaybackPreference.java b/app/src/main/java/com/valterc/ki2/views/preference/AudioPlaybackPreference.java index a921aaa..01844e7 100644 --- a/app/src/main/java/com/valterc/ki2/views/preference/AudioPlaybackPreference.java +++ b/app/src/main/java/com/valterc/ki2/views/preference/AudioPlaybackPreference.java @@ -55,7 +55,7 @@ public void setValue(String value) { try { if (service != null) { - service.sendMessage(new AudioAlertMessage("custom_single_beep")); + service.sendMessage(new AudioAlertMessage("custom_single_beep", true)); } } catch (Exception e) { Timber.w(e, "Unable to send message"); diff --git a/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java b/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java index 5102896..afd32e8 100644 --- a/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java +++ b/app/src/main/java/com/valterc/ki2/views/preference/SwitchListPreference.java @@ -57,17 +57,25 @@ public void setValue(String value) { try { if (service != null) { switch (value) { - case "press_single_beep": service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); - case "press_double_beep": service.sendMessage(new AudioAlertMessage("custom_double_beep", false)); - case "press_bell_old": service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); - case "press_bell_new": service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); - case "hold_short_single_single_beep": service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); - case "hold_short_single_double_beep": service.sendMessage(new AudioAlertMessage("custom_double_beep", false)); - case "hold_short_single_bell_old": service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); - case "hold_short_single_bell_new": service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); - case "hold_continuous_single_beep": service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); - case "hold_continuous_bell_old": service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); - case "hold_continuous_bell_new": service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); + case "press_single_beep": + case "hold_short_single_single_beep": + case "hold_continuous_single_beep": + service.sendMessage(new AudioAlertMessage("custom_single_beep", false)); + break; + case "press_double_beep": + case "hold_short_single_double_beep": + service.sendMessage(new AudioAlertMessage("custom_double_beep", false)); + break; + case "press_bell_old": + case "hold_short_single_bell_old": + case "hold_continuous_bell_old": + service.sendMessage(new AudioAlertMessage("karoo_bell_old", false)); + break; + case "press_bell_new" : + case "hold_short_single_bell_new": + case "hold_continuous_bell_new": + service.sendMessage(new AudioAlertMessage("karoo_bell_new", false)); + break; } } } catch (Exception e) {