From 6022e5973902b3fcd5415ee3e29cff864bd49fff Mon Sep 17 00:00:00 2001 From: Sharon C <54977773+SecretAgentShh@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:48:40 -0500 Subject: [PATCH] Creating motivational announcements at set time intervals with set of motivation quotes chosen at random --- .../services/announcement/VoiceAnnouncement.java | 11 ++++++++++- .../announcement/VoiceAnnouncementManager.java | 11 ++++++++++- .../services/announcement/VoiceAnnouncementUtils.java | 8 ++++++++ .../opentracks/util/MotivationalAnnouncements.java | 10 ++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/dennisguse/opentracks/util/MotivationalAnnouncements.java diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java index bc8594d61..cb99b2cdb 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java @@ -23,6 +23,7 @@ import android.speech.tts.TextToSpeech; import android.speech.tts.UtteranceProgressListener; import android.text.Spannable; +import android.text.SpannableStringBuilder; import android.util.Log; import androidx.annotation.NonNull; @@ -108,6 +109,7 @@ public void onError(String utteranceId) { private boolean ttsReady = false; private MediaPlayer ttsFallback; + public String msg; VoiceAnnouncement(Context context) { this.context = context; @@ -150,6 +152,8 @@ public void announce(@NonNull Track track) { } } + + if (Arrays.asList(AudioManager.MODE_IN_CALL, AudioManager.MODE_IN_COMMUNICATION) .contains(audioManager.getMode())) { Log.i(TAG, "Announcement is not allowed at this time."); @@ -167,6 +171,8 @@ public void announce(@NonNull Track track) { return; } + + Distance currentIntervalDistance = PreferencesUtils.getVoiceAnnouncementDistance(); if (currentIntervalDistance != intervalDistance) { intervalStatistics = new IntervalStatistics(currentIntervalDistance); @@ -182,7 +188,10 @@ public void announce(@NonNull Track track) { sensorStatistics = contentProviderUtils.getSensorStats(track.getId()); } - Spannable announcement = VoiceAnnouncementUtils.getAnnouncement(context, track.getTrackStatistics(), PreferencesUtils.getUnitSystem(), PreferencesUtils.isReportSpeed(track), lastInterval, sensorStatistics); +// Spannable announcement = VoiceAnnouncementUtils.getAnnouncement(context, track.getTrackStatistics(), PreferencesUtils.getUnitSystem(), PreferencesUtils.isReportSpeed(track), lastInterval, sensorStatistics); + // SpannableStringBuilder announcement = new SpannableStringBuilder(); + Spannable announcement = VoiceAnnouncementUtils.getMotivationalAnnouncements(); + // announcement.append("good job"); if (announcement.length() > 0) { // We don't care about the utterance id. It is supplied here to force onUtteranceCompleted to be called. diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java index 0bfe185af..e17407ff9 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java @@ -17,6 +17,7 @@ import android.content.Context; import android.content.SharedPreferences; +import android.speech.tts.TextToSpeech; import android.util.Log; import androidx.annotation.NonNull; @@ -32,6 +33,7 @@ import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.stats.TrackStatistics; +import de.dennisguse.opentracks.services.announcement.VoiceAnnouncement; /** * Execute a periodic task on a time or distance schedule. @@ -39,7 +41,7 @@ * @author Sandor Dornbush */ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPreferenceChangeListener { - + String motivationString = ""; private static final String TAG = VoiceAnnouncementManager.class.getSimpleName(); private final TrackRecordingService trackRecordingService; @@ -99,11 +101,16 @@ public void update(@NonNull Context context, @NonNull Track track) { announce = true; } + if (announce) { voiceAnnouncement.announce(track); + } } + + + public void stop() { if (voiceAnnouncement != null) { voiceAnnouncement.stop(); @@ -111,6 +118,8 @@ public void stop() { } } + + public void setFrequency(Duration frequency) { this.totalTimeFrequency = frequency; update(this.trackStatistics); diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java index 21432d569..c26808859 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java @@ -31,6 +31,7 @@ import de.dennisguse.opentracks.ui.intervals.IntervalStatistics; import de.dennisguse.opentracks.util.CTime; import de.dennisguse.opentracks.util.SpeechTxtForTime; +import de.dennisguse.opentracks.util.MotivationalAnnouncements; class VoiceAnnouncementUtils { @@ -165,6 +166,13 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic return builder; } + static Spannable getMotivationalAnnouncements(){ + //TODO - randomize the motivational quotes and pass the value + //int randomchoice = 5; + SpannableStringBuilder motivator = new SpannableStringBuilder(); + return (motivator.append(new MotivationalAnnouncements().motivations[5])); + } + private static void appendDuration(@NonNull Context context, @NonNull SpannableStringBuilder builder, @NonNull Duration duration) { int hours = (int) (duration.toHours()); int minutes = (int) (duration.toMinutes() % 60); diff --git a/src/main/java/de/dennisguse/opentracks/util/MotivationalAnnouncements.java b/src/main/java/de/dennisguse/opentracks/util/MotivationalAnnouncements.java new file mode 100644 index 000000000..71bfec244 --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/util/MotivationalAnnouncements.java @@ -0,0 +1,10 @@ +package de.dennisguse.opentracks.util; + +public class MotivationalAnnouncements { + public String []motivations = {"You are doing great","Kudos","Play Hard or Go Home","Yippee","Faster if you can","Its okay,You can do this","I believe in you", + "You're the best sportsperson I have ever seen","Keep going"}; + + + + +}