Skip to content

Commit

Permalink
Merge pull request #2 from HWJFish/64-settings-voice-announcements-an…
Browse files Browse the repository at this point in the history
…nounce-avg-speed-at-end-of-each-run

64 settings voice announcements announce avg speed at end of each run
  • Loading branch information
HWJFish authored Apr 8, 2024
2 parents 7a5c7cf + 0497a0e commit 2b08517
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void run() {
Pair<Track, Pair<TrackPoint, SensorDataSet>> data = trackRecordingManager.getDataForUI();

voiceAnnouncementManager.announceStatisticsIfNeeded(data.first);
voiceAnnouncementManager.announceAfterRun(data.first);

recordingDataObservable.postValue(new RecordingData(data.first, data.second.first, data.second.second));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ public void announceAfterRecording(@NonNull Track track) {
}



public void announceAfterRun(@NonNull Track track) {
if (shouldNotAnnounce()) {
return;
}

boolean announce = false;
this.trackStatistics = track.getTrackStatistics();
if (trackStatistics.getTotalDistance().greaterThan(nextTotalDistance)) {
updateNextTaskDistance();
announce = true;
}
if (!trackStatistics.getTotalTime().minus(nextTotalTime).isNegative()) {
updateNextDuration();
announce = true;
}

if (announce) {
//TODO: Once we have run data from other groups, change the conditions to only call this if we're at the end of a run
voiceAnnouncement.announce(VoiceAnnouncementUtils.createRunStatistics(context, track.getTrackStatistics(), PreferencesUtils.getUnitSystem()));
}
}

public void announceStatisticsIfNeeded(@NonNull Track track) {
if (shouldNotAnnounce()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceLapSpeedPace;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceMovingTime;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceTotalDistance;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceRunAverageSpeed;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceMaxSlope;


import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceMaxSpeedRecording;

import android.content.Context;
Expand Down Expand Up @@ -106,6 +108,46 @@ static Spannable createAfterRecording(Context context, TrackStatistics trackStat
return builder;
}

static Spannable createRunStatistics(Context context, TrackStatistics trackStatistics, UnitSystem unitSystem) {
SpannableStringBuilder builder = new SpannableStringBuilder();
//TODO: Once we get run data from other groups, we can announce run statistics instead of track statistics
Distance totalDistance = trackStatistics.getTotalDistance();
Speed averageMovingSpeed = trackStatistics.getAverageMovingSpeed();

int speedId;
String unitSpeedTTS;
switch (unitSystem) {
case METRIC -> {
speedId = R.string.voiceSpeedKilometersPerHourPlural;
unitSpeedTTS = "kilometer per hour";
}
case IMPERIAL_FEET, IMPERIAL_METER -> {
speedId = R.string.voiceSpeedMilesPerHourPlural;
unitSpeedTTS = "mile per hour";
}
case NAUTICAL_IMPERIAL -> {
speedId = R.string.voiceSpeedMKnotsPlural;
unitSpeedTTS = "knots";
}
default -> throw new RuntimeException("Not implemented");
}

if (totalDistance.isZero()) {
return builder;
}

//Announce Average Speed
if (shouldVoiceAnnounceRunAverageSpeed()) {
double speedInUnit = averageMovingSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.speed));
String template = context.getResources().getString(speedId);
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
}
return builder;
}

static Spannable createStatistics(Context context, TrackStatistics trackStatistics, UnitSystem unitSystem, boolean isReportSpeed, @Nullable IntervalStatistics.Interval currentInterval, @Nullable SensorStatistics sensorStatistics) {
SpannableStringBuilder builder = new SpannableStringBuilder();
Distance totalDistance = trackStatistics.getTotalDistance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@ public static boolean shouldVoiceAnnounceAverageHeartRate() {
public static void setVoiceAnnounceAverageHeartRate(boolean value) {
setBoolean(R.string.voice_announce_average_heart_rate_key, value);
}


public static boolean shouldVoiceAnnounceRunAverageSpeed() {
return getBoolean(R.string.voice_announce_run_average_speed_key, true);
}

@VisibleForTesting
public static void setVoiceAnnounceRunAverageSpeed(boolean value) {
setBoolean(R.string.voice_announce_run_average_speed_key, value);
}


public static boolean shouldVoiceAnnounceMaxSlope() {
return getBoolean(R.string.voice_announce_max_slope_key, true);
}
Expand All @@ -447,6 +459,7 @@ public static boolean shouldVoiceAnnounceMaxSlope() {
public static void setVoiceAnnounceMaxSlope(boolean value) {
setBoolean(R.string.voice_announce_max_slope_key, value);
}

// recoding related setting helper methods
public static boolean shouldVoiceAnnounceMaxSpeedRecording() {
return getBoolean(R.string.voice_announce_max_speed_recording_key, true);
Expand Down
7 changes: 7 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,15 @@
<bool name="voice_announce_average_heart_rate_default" translatable="false">false</bool>
<string name="voice_announce_lap_heart_rate_key" translatable="false">voiceAnnounceLapHeartRate</string>
<bool name="voice_announce_lap_heart_rate_default" translatable="false">false</bool>

<!-- Run related data -->
<string name="voice_announce_run_average_speed_key" translatable="false">voiceAnnounceRunAverageSpeed</string>
<bool name="voice_announce_run_average_speed_default" translatable="false">false</bool>


<string name="voice_announce_max_slope_key">voiceAnnounceMaxSlope</string>
<bool name="voice_announce_max_slope_default" translatable="false">true</bool>

<!-- Recording related data -->
<string name="voice_announce_max_speed_recording_key">voiceAnnounceMaxSpeedRecording</string>
<bool name="voice_announce_max_speed_recording_default" translatable="false">true</bool>
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ limitations under the License.
<string name="settings_announcements_summary">Time, Distance, Voice Speed</string>

<string name="settings_announcements_recording_title">Announcements After Recording</string>
<string name="settings_announcements_run_title">Announcements After Run</string>

<string name="settings_import_export_title">Import/Export</string>
<string name="settings_import_export_summary">Import, Export, Auto Export</string>
Expand Down Expand Up @@ -413,6 +414,7 @@ limitations under the License.
<string name="settings_announcements_lap_heart_rate">Lap heart rate</string>
<string name="settings_announcements_average_speed_pace">Average speed/pace</string>
<string name="settings_announcements_lap_speed_pace">Lap speed/pace</string>
<string name="settings_announcements_run_average_speed">Run Average Speed</string>
<string name="settings_announcements_max_slope">Max slope</string>

<!-- Recording Related Data -->
Expand Down
7 changes: 7 additions & 0 deletions src/main/res/xml/settings_announcements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@
android:key="@string/voice_announce_max_slope_key"
android:title="@string/settings_announcements_max_slope" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_announcements_run_title">
<SwitchPreferenceCompat
android:defaultValue="@bool/voice_announce_run_average_speed_default"
android:key="@string/voice_announce_run_average_speed_key"
android:title="@string/settings_announcements_run_average_speed" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 2b08517

Please sign in to comment.