New Setting to specify if announcements should be played always or only over headphones

This commit is contained in:
jannis 2020-01-08 13:36:03 +01:00
parent 9089689ce3
commit baf529f9ca
7 changed files with 119 additions and 1 deletions

View File

@ -41,6 +41,8 @@ public class VoiceAnnouncementsSettingsActivity extends FitoTrackSettingsActivit
addPreferencesFromResource(R.xml.preferences_voice_announcements);
bindPreferenceSummaryToValue(findPreference("announcementMode"));
findPreference("speechConfig").setOnPreferenceClickListener(preference -> {
showSpeechConfig();
return true;

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2020 Jannis Scheibe <jannis@tadris.de>
*
* This file is part of FitoTrack
*
* FitoTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FitoTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.tadris.fitness.announcement;
import android.content.Context;
import android.preference.PreferenceManager;
public enum AnnouncementMode {
ALWAYS,
HEADPHONES;
static AnnouncementMode getCurrentMode(Context context) {
String mode = PreferenceManager.getDefaultSharedPreferences(context).getString("announcementMode", "headphones");
assert mode != null;
switch (mode) {
case "always":
return ALWAYS;
default:
case "headphones":
return HEADPHONES;
}
}
}

View File

@ -42,6 +42,7 @@ public class VoiceAnnouncements {
private long lastSpokenUpdateTime = 0;
private int lastSpokenUpdateDistance = 0;
private final AnnouncementMode currentMode;
private final long intervalTime;
private final int intervalInMeters;
@ -57,6 +58,8 @@ public class VoiceAnnouncements {
this.manager = new AnnouncementManager(context);
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
this.currentMode = AnnouncementMode.getCurrentMode(context);
}
private void ttsReady(int status) {
@ -109,8 +112,13 @@ public class VoiceAnnouncements {
public void speak(String text) {
if (!ttsAvailable) {
// Cannot speak
return;
} // Cannot speak
}
if (currentMode == AnnouncementMode.HEADPHONES && !audioManager.isWiredHeadsetOn()) {
// Not allowed to speak
return;
}
Log.d("Recorder", "TTS speaks: " + text);
textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, null, "announcement" + (++speakId));
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 Jannis Scheibe <jannis@tadris.de>
~
~ This file is part of FitoTrack
~
~ FitoTrack is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ FitoTrack is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<string-array name="pref_announcement_mode">
<item>Immer</item>
<item>Nur mit Kopfhörern</item>
</string-array>
</resources>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 Jannis Scheibe <jannis@tadris.de>
~
~ This file is part of FitoTrack
~
~ FitoTrack is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ FitoTrack is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<string-array name="pref_announcement_mode">
<item>Always</item>
<item>Only on headphones</item>
</string-array>
<string-array name="pref_announcement_mode_values">
<item>always</item>
<item>headphones</item>
</string-array>
</resources>

View File

@ -149,4 +149,5 @@
<string name="description">Description</string>
<string name="ttsNotAvailable">TextToSpeech is not available</string>
<string name="action_edit_comment">Edit Comment</string>
<string name="pref_announcement_mode">Announcement Mode</string>
</resources>

View File

@ -25,6 +25,12 @@
android:title="@string/pref_announcements_config_title"
android:summary="@string/pref_announcements_config_summary" />
<ListPreference
android:defaultValue="headphones"
android:entries="@array/pref_announcement_mode"
android:entryValues="@array/pref_announcement_mode_values"
android:key="announcementMode"
android:title="@string/pref_announcement_mode" />
<PreferenceCategory android:title="@string/pref_announcements_content">
<CheckBoxPreference