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

Group7 181 current heart rate as speech output #307

Merged
merged 10 commits into from
Nov 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.ui.aggregatedStatistics.ConfirmDeleteDialogFragment;
import de.dennisguse.opentracks.util.ExportUtils;
import de.dennisguse.opentracks.util.IntentUtils;
Expand Down Expand Up @@ -46,6 +47,13 @@ protected void onCreate(Bundle savedInstanceState) {

ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this);
Track track = contentProviderUtils.getTrack(trackId);
try {
SensorStatistics sensorStatistics = contentProviderUtils.getSensorStats(trackId);
if(sensorStatistics!=null)
{
float maxHr = sensorStatistics.getMaxHeartRate().getBPM();
}
}catch (Exception e){}

viewBinding.trackEditName.setText(track.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.shouldVoiceAnnounceCurrentHeartRate;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldVoiceAnnounceTime;


Expand Down Expand Up @@ -96,7 +97,6 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic
if (totalDistance.isZero()) {
return builder;
}


// Announce time
Duration movingTime = trackStatistics.getMovingTime();
Expand Down Expand Up @@ -163,6 +163,11 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic
appendCardinal(builder, context.getString(R.string.sensor_state_heart_rate_value, currentHeartRate), currentHeartRate);
builder.append(".");
}
if(shouldVoiceAnnounceCurrentHeartRate() && currentInterval != null && currentInterval.hasAverageHeartRate()){
int currentHeartRate = Math.round(currentInterval.getAverageHeartRate().getBPM());
builder.append(context.getString(R.string.current_heart_rate)).append(" ").append(String.valueOf(currentHeartRate));
builder.append(".");
}

return builder;
}
Expand Down Expand Up @@ -229,4 +234,3 @@ private static void appendCardinal(@NonNull SpannableStringBuilder builder, @Non
.append(localizedText, new TtsSpan.CardinalBuilder().setNumber(number).build(), SPAN_INCLUSIVE_EXCLUSIVE);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ public static Distance getRecordingDistanceInterval() {
return Distance.of(getInt(R.string.recording_distance_interval_key, getRecordingDistanceIntervalDefaultInternal()));
}

public static boolean shouldVoiceAnnounceCurrentHeartRate() {
return getBoolean(R.string.voice_announce_current_heart_rate_key, false);
}

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

public static Distance getRecordingDistanceIntervalDefault() {
return Distance.of(getRecordingDistanceIntervalDefaultInternal());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
<string name="voice_announce_average_speed_pace_key" translatable="false">voiceAnnounceAverageSpeedPace</string>
<string name="voice_announce_lap_speed_pace_key" translatable="false">voiceAnnounceLapSpeedPace</string>
<string name="voice_announce_average_heart_rate_key" translatable="false">voiceAnnounceAverageHeartRate</string>
<string name="voice_announce_current_heart_rate_key" translatable="false">voiceAnnounceCurrentHeartRate</string>
<string name="voice_announce_lap_heart_rate_key" translatable="false">voiceAnnounceLapHeartRate</string>

<string name="export_trackfileformat_key" translatable="false">exportTrackFileFormat</string>
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ limitations under the License.
<string name="settings_announcements_totaltime_frequency">Time interval</string>
<string name="settings_announcements_distance_frequency">Distance interval</string>
<string name="settings_announcements_average_heart_rate">Average heart rate</string>
<string name="settings_announcements_current_heart_rate">Current heart rate</string>
<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>
Expand Down
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 @@ -64,6 +64,11 @@
android:key="@string/voice_announce_average_heart_rate_key"
android:title="@string/settings_announcements_average_heart_rate" />

<SwitchPreference
android:defaultValue="false"
android:key="@string/voice_announce_current_heart_rate_key"
android:title="@string/settings_announcements_current_heart_rate" />

<SwitchPreference
android:defaultValue="false"
android:key="@string/voice_announce_lap_heart_rate_key"
Expand Down