diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
index 62e625512..aa1c26074 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
@@ -440,4 +440,5 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_AUTO_REPLY_INCOMING_CALL = "pref_auto_reply_phonecall";
public static final String PREF_AUTO_REPLY_INCOMING_CALL_DELAY = "pref_auto_reply_phonecall_delay";
+ public static final String PREF_SPEAK_NOTIFICATIONS_ALOUD = "pref_speak_notifications_aloud";
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/nothing/Ear1Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/nothing/Ear1Support.java
index 780e346a0..b972cc6c8 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/nothing/Ear1Support.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/nothing/Ear1Support.java
@@ -27,6 +27,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
+import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.serial.AbstractSerialDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceIoThread;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
@@ -57,6 +58,8 @@ public class Ear1Support extends AbstractSerialDeviceSupport {
callCmd.event = GBDeviceEventCallControl.Event.ACCEPT;
evaluateGBDeviceEvent(callCmd);
}, delayMillis); //15s
+
+ return;
}
String speechText = callSpec.name;
if (callSpec.name.equals(callSpec.number)) {
@@ -70,6 +73,26 @@ public class Ear1Support extends AbstractSerialDeviceSupport {
}
+ @Override
+ public void onNotification(NotificationSpec notificationSpec) {
+ SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
+
+ if (!prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SPEAK_NOTIFICATIONS_ALOUD, false))
+ return;
+
+ if (gbTextToSpeech.isConnected()) {
+
+ String notificationSpeller = new StringBuilder()
+ .append(notificationSpec.sourceName == null ? "" : notificationSpec.sourceName).append(". ")
+ .append(notificationSpec.title == null ? "" : notificationSpec.title).append(": ")
+ .append(notificationSpec.body == null ? "" : notificationSpec.body).toString();
+
+
+ gbTextToSpeech.speakNotification(notificationSpeller);
+
+ }
+ }
+
@Override
public void onSendConfiguration(String config) {
super.onSendConfiguration(config);
@@ -122,16 +145,18 @@ public class Ear1Support extends AbstractSerialDeviceSupport {
@Override
public void onDone(String utteranceId) {
// LOG.debug("UtteranceProgressListener onDone.");
- SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
- final int delayMillis = Integer.parseInt(prefs.getString(DeviceSettingsPreferenceConst.PREF_AUTO_REPLY_INCOMING_CALL_DELAY, "15")) * 1000;
+ if (utteranceId.equals("call")) {
+ SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
+ final int delayMillis = Integer.parseInt(prefs.getString(DeviceSettingsPreferenceConst.PREF_AUTO_REPLY_INCOMING_CALL_DELAY, "15")) * 1000;
- Looper mainLooper = Looper.getMainLooper();
- new Handler(mainLooper).postDelayed(() -> {
- GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl();
- callCmd.event = GBDeviceEventCallControl.Event.ACCEPT;
- evaluateGBDeviceEvent(callCmd);
- }, delayMillis); //15s
+ Looper mainLooper = Looper.getMainLooper();
+ new Handler(mainLooper).postDelayed(() -> {
+ GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl();
+ callCmd.event = GBDeviceEventCallControl.Event.ACCEPT;
+ evaluateGBDeviceEvent(callCmd);
+ }, delayMillis); //15s
+ }
}
@Override
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBTextToSpeech.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBTextToSpeech.java
index 11b120bfd..ed3e2d025 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBTextToSpeech.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBTextToSpeech.java
@@ -47,7 +47,13 @@ public class GBTextToSpeech {
Bundle params = new Bundle();
// Put the audio stream type into the Bundle
params.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_RING);
- textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, params, "utteranceId");
+ textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, params, "call");
+ }
+
+ public void speakNotification(String text) {
+ Bundle params = new Bundle();
+ params.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_MUSIC);
+ textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, params, "notification");
}
public void shutdown() {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ae63e8dc2..45110e573 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2782,4 +2782,6 @@
Automatically answer phone calls
Number of seconds after which the call is automatically picked up
Automatic Answer Delay
+ Notifications will be read aloud through the headphones
+ Speak Notifications Aloud
diff --git a/app/src/main/res/xml/devicesettings_nothing_ear1.xml b/app/src/main/res/xml/devicesettings_nothing_ear1.xml
index f0b682585..ed237a404 100644
--- a/app/src/main/res/xml/devicesettings_nothing_ear1.xml
+++ b/app/src/main/res/xml/devicesettings_nothing_ear1.xml
@@ -29,4 +29,10 @@
android:summary="@string/pref_auto_reply_calls_delay_summary"
android:title="@string/pref_auto_reply_calls_delay_title"
app:defaultValue="15" />
+