Skip to content

Commit

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

81 settings voice announcements announce max speed at end of each recording
  • Loading branch information
priscila-aramouni authored Apr 7, 2024
2 parents 2a0695c + db51e4a commit e38f50e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ public void endCurrentTrack() {
return;
}

// announce after recording
Pair<Track, Pair<TrackPoint, SensorDataSet>> data = trackRecordingManager.getDataForUI();

voiceAnnouncementManager.announceAfterRecording(data.first);

// Set recording status
updateRecordingStatus(STATUS_DEFAULT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ public void announce(@NonNull Spannable announcement) {
}

public void stop() {
// Shutdown the TextToSpeech engine after the current task is done
if (tts != null) {
while (tts.isSpeaking()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

tts.shutdown();
tts = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public void announceIdle() {
voiceAnnouncement.announce(VoiceAnnouncementUtils.createIdle(context));
}

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

// add other check with and here
if (!PreferencesUtils.shouldVoiceAnnounceMaxSpeedRecording()) {
return;
}

voiceAnnouncement.announce(VoiceAnnouncementUtils.createAfterRecording(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 @@ -8,6 +8,8 @@
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceMovingTime;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceTotalDistance;

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

import android.content.Context;
import android.icu.text.MessageFormat;
import android.text.Spannable;
Expand Down Expand Up @@ -38,6 +40,54 @@ static Spannable createIdle(Context context) {
.append(context.getString(R.string.voiceIdle));
}

static Spannable createAfterRecording(Context context, TrackStatistics trackStatistics, UnitSystem unitSystem) {
SpannableStringBuilder builder = new SpannableStringBuilder();
Speed maxSpeed = trackStatistics.getMaxSpeed();

int perUnitStringId;
int distanceId;
int speedId;
String unitDistanceTTS;
String unitSpeedTTS;
switch (unitSystem) {
case METRIC -> {
perUnitStringId = R.string.voice_per_kilometer;
distanceId = R.string.voiceDistanceKilometersPlural;
speedId = R.string.voiceSpeedKilometersPerHourPlural;
unitDistanceTTS = "kilometer";
unitSpeedTTS = "kilometer per hour";
}
case IMPERIAL_FEET, IMPERIAL_METER -> {
perUnitStringId = R.string.voice_per_mile;
distanceId = R.string.voiceDistanceMilesPlural;
speedId = R.string.voiceSpeedMilesPerHourPlural;
unitDistanceTTS = "mile";
unitSpeedTTS = "mile per hour";
}
case NAUTICAL_IMPERIAL -> {
perUnitStringId = R.string.voice_per_nautical_mile;
distanceId = R.string.voiceDistanceNauticalMilesPlural;
speedId = R.string.voiceSpeedMKnotsPlural;
unitDistanceTTS = "nautical mile";
unitSpeedTTS = "knots";
}
default -> throw new RuntimeException("Not implemented");
}


if (shouldVoiceAnnounceMaxSpeedRecording()) {
double speedInUnit = maxSpeed.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 @@ -440,6 +440,16 @@ public static void setVoiceAnnounceAverageHeartRate(boolean value) {
setBoolean(R.string.voice_announce_average_heart_rate_key, value);
}

// recoding related setting helper methods
public static boolean shouldVoiceAnnounceMaxSpeedRecording() {
return getBoolean(R.string.voice_announce_max_speed_recording_key, true);
}

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

public static Distance getRecordingDistanceInterval() {
return Distance.of(getInt(R.string.recording_distance_interval_key, getRecordingDistanceIntervalDefaultInternal()));
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@
<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_speed_recording_key">voiceAnnounceMaxSpeedRecording</string>
<bool name="voice_announce_max_speed_recording_default" translatable="false">true</bool>

<string name="export_trackfileformat_key" translatable="false">exportTrackFileFormat</string>
<!-- See TrackFileFormat -->
<string name="export_trackfileformat_default" translatable="false">KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES</string>
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ limitations under the License.
<string name="settings_announcements_statistics_title">Statistics Announcements</string>
<string name="settings_announcements_summary">Time, Distance, Voice Speed</string>

<string name="settings_announcements_recording_title">Announcements After Recording</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 @@ -412,6 +414,9 @@ limitations under the License.
<string name="settings_announcements_average_speed_pace">Average speed/pace</string>
<string name="settings_announcements_lap_speed_pace">Lap speed/pace</string>

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

<!-- Custom Layout -->


Expand Down
6 changes: 6 additions & 0 deletions src/main/res/xml/settings_announcements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@
android:title="@string/settings_announcements_lap_heart_rate" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_announcements_recording_title">
<SwitchPreferenceCompat
android:defaultValue="@bool/voice_announce_max_speed_recording_default"
android:key="@string/voice_announce_max_speed_recording_key"
android:title="@string/settings_announcements_max_speed_recording" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit e38f50e

Please sign in to comment.