Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #268 from rilling/Group4Motivation
Browse files Browse the repository at this point in the history
Motivation Announcements
  • Loading branch information
SecretAgentShh authored Nov 22, 2023
2 parents 435df5c + 6022e59 commit d768a71
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand All @@ -167,6 +171,8 @@ public void announce(@NonNull Track track) {
return;
}



Distance currentIntervalDistance = PreferencesUtils.getVoiceAnnouncementDistance();
if (currentIntervalDistance != intervalDistance) {
intervalStatistics = new IntervalStatistics(currentIntervalDistance);
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,14 +33,15 @@
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.
*
* @author Sandor Dornbush
*/
public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPreferenceChangeListener {

String motivationString = "";
private static final String TAG = VoiceAnnouncementManager.class.getSimpleName();

private final TrackRecordingService trackRecordingService;
Expand Down Expand Up @@ -99,18 +101,25 @@ public void update(@NonNull Context context, @NonNull Track track) {
announce = true;
}


if (announce) {
voiceAnnouncement.announce(track);

}
}




public void stop() {
if (voiceAnnouncement != null) {
voiceAnnouncement.stop();
voiceAnnouncement = null;
}
}



public void setFrequency(Duration frequency) {
this.totalTimeFrequency = frequency;
update(this.trackStatistics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"};




}

0 comments on commit d768a71

Please sign in to comment.