Skip to content

Commit

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

82 settings voice announcements announce max speed at end of each run
  • Loading branch information
HWJFish authored Apr 8, 2024
2 parents 42a3637 + 7818897 commit 1a528fb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
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.shouldVoiceAnnounceMaxSpeedRun;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceRunAverageSpeed;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceMaxSlope;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceAveragesloperecording;




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

import android.content.Context;
Expand Down Expand Up @@ -128,6 +126,7 @@ static Spannable createRunStatistics(Context context, TrackStatistics trackStati
//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();
Speed maxSpeed = trackStatistics.getMaxSpeed();

int speedId;
String unitSpeedTTS;
Expand All @@ -147,9 +146,7 @@ static Spannable createRunStatistics(Context context, TrackStatistics trackStati
default -> throw new RuntimeException("Not implemented");
}

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


//Announce Average Speed
if (shouldVoiceAnnounceRunAverageSpeed()) {
Expand All @@ -160,13 +157,23 @@ static Spannable createRunStatistics(Context context, TrackStatistics trackStati
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
}
return builder;

if (shouldVoiceAnnounceMaxSpeedRun()) {
double speedInUnit = maxSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.settings_announcements_max_speed_run));
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();
Speed averageMovingSpeed = trackStatistics.getAverageMovingSpeed();

Speed currentDistancePerTime = currentInterval != null ? currentInterval.getSpeed() : null;

int perUnitStringId;
Expand Down Expand Up @@ -230,6 +237,7 @@ static Spannable createStatistics(Context context, TrackStatistics trackStatisti
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
}

if (shouldVoiceAnnounceLapSpeedPace() && currentDistancePerTime != null) {
double currentDistancePerTimeInUnit = currentDistancePerTime.to(unitSystem);
if (currentDistancePerTimeInUnit > 0) {
Expand All @@ -251,6 +259,7 @@ static Spannable createStatistics(Context context, TrackStatistics trackStatisti
.append(".");
}


if (shouldVoiceAnnounceLapSpeedPace() && currentDistancePerTime != null) {
Duration currentTime = currentDistancePerTime.toPace(unitSystem);
builder.append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ public static void setVoiceAnnounceAverageHeartRate(boolean value) {
}


public static boolean shouldVoiceAnnounceMaxSpeedRun() {
return getBoolean(R.string.voice_announce_max_speed_run_key, true);
}

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

public static boolean shouldVoiceAnnounceRunAverageSpeed() {
return getBoolean(R.string.voice_announce_run_average_speed_key, true);
}
Expand Down Expand Up @@ -476,6 +485,7 @@ public static boolean shouldVoiceAnnounceAveragesloperecording() {
@VisibleForTesting
public static void setVoiceAnnounceAveragesloperecording(boolean value) {
setBoolean(R.string.voice_announce_average_slope_recording_key, value);

}

public static Distance getRecordingDistanceInterval() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
<string name="voice_announce_lap_heart_rate_key" translatable="false">voiceAnnounceLapHeartRate</string>
<bool name="voice_announce_lap_heart_rate_default" translatable="false">false</bool>


<!-- Recording related data -->
<string name="voice_announce_max_slope_key">voiceAnnounceMaxSlope</string>
<bool name="voice_announce_max_slope_default" translatable="false">true</bool>
Expand All @@ -274,10 +275,10 @@
<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_speed_run_key">voiceAnnounceMaxSpeedRun</string>
<bool name="voice_announce_max_speed_run_default" translatable="false">true</bool>




<!-- See TrackFileFormat -->
<string name="export_trackfileformat_key" translatable="false">exportTrackFileFormat</string>
<string name="export_trackfileformat_default" translatable="false">KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES</string>
Expand Down
9 changes: 7 additions & 2 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,19 @@ 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_max_speed_run">Max speed/run</string>
<string name="settings_announcements_run_average_speed">Run Average Speed</string>
<string name="settings_announcements_max_slope">Max slope</string>


<!-- Recording Related Data -->
<string name="settings_announcements_max_speed_recording">Max speed/recording</string>
<!-- Recording Related Data -->
<string name="settings_announcements_max_slope">Max slope</string>
<string name="settings_announcements_average_slope_recording">Average slope</string>




<string name="custom_layout_list_title">Layouts</string>
<string name="custom_layout_list_edit_name">Type layout\'s name to add</string>
<string name="custom_layout_list_edit_already_exists">Layout\'s name already exists</string>
Expand Down Expand Up @@ -718,4 +721,6 @@ limitations under the License.
<string name="always">Always</string>

<string name="introduction_osm_dashboard">OpenTracks itself does not provide a map. Please install OSMDashboard to view your recordings on a map.</string>


</resources>
5 changes: 5 additions & 0 deletions src/main/res/xml/settings_announcements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
android:defaultValue="@bool/voice_announce_lap_heart_rate_default"
android:key="@string/voice_announce_lap_heart_rate_key"
android:title="@string/settings_announcements_lap_heart_rate" />

</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_announcements_recording_title">
Expand All @@ -94,5 +95,9 @@
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" />
<SwitchPreferenceCompat
android:defaultValue="@bool/voice_announce_max_speed_run_default"
android:key="@string/voice_announce_max_speed_run_key"
android:title="@string/settings_announcements_max_speed_run" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 1a528fb

Please sign in to comment.