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 #238 from rilling/Group_2_C2
Browse files Browse the repository at this point in the history
Time of day announcement feature #178
  • Loading branch information
ajay-ramasubramanian authored Nov 19, 2023
2 parents d8d4f9c + 3c0cd7f commit 435df5c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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.shouldVoiceAnnounceTime;


import android.content.Context;
import android.icu.text.MessageFormat;
Expand All @@ -27,6 +29,8 @@
import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics;
import de.dennisguse.opentracks.ui.intervals.IntervalStatistics;
import de.dennisguse.opentracks.util.CTime;
import de.dennisguse.opentracks.util.SpeechTxtForTime;

class VoiceAnnouncementUtils {

Expand All @@ -39,6 +43,13 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic
Speed averageMovingSpeed = trackStatistics.getAverageMovingSpeed();
Speed currentDistancePerTime = currentInterval != null ? currentInterval.getSpeed() : null;

// Announce current time
if(shouldVoiceAnnounceTime()){
SpeechTxtForTime t = new SpeechTxtForTime();
CTime c = new CTime();
String currentTime = c.getCurrentTime();
builder.append(t.speechText+currentTime+".");}

int perUnitStringId;
int distanceId;
int speedId;
Expand Down Expand Up @@ -83,6 +94,7 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic
if (totalDistance.isZero()) {
return builder;
}


// Announce time
Duration movingTime = trackStatistics.getMovingTime();
Expand All @@ -91,6 +103,7 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic
builder.append(".");
}


if (isReportSpeed) {
if (shouldVoiceAnnounceAverageSpeedPace()) {
double speedInUnit = averageMovingSpeed.to(unitSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ public static float getVoiceSpeedRate() {
return getFloat(R.string.voice_speed_rate_key, DEFAULT);
}

//adding time thing

public static boolean shouldVoiceAnnounceTime(){
return getBoolean(R.string.voice_announce_time_key, true);
}

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

public static boolean shouldVoiceAnnounceTotalDistance() {
return getBoolean(R.string.voice_announce_total_distance_key, true);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/de/dennisguse/opentracks/util/CTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.dennisguse.opentracks.util;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class CTime {
public String getCurrentTime(){
LocalTime currentTime = LocalTime.now();

// Create a formatter for the desired time format
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mm a");

// Format the current time using the formatter
String formattedTime = currentTime.format(formatter);
return formattedTime;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.dennisguse.opentracks.util;

public class SpeechTxtForTime {
public String speechText = "Current time is ";
}
2 changes: 2 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@
</string-array>
<string name="voice_announcement_distance_key" translatable="false">voiceDistance</string>
<string name="voice_announcement_distance_default" translatable="false">@string/announcement_off</string>
<!-- Added Current Time Voice Announcement Switch-->
<string name="voice_announce_time_key" translatable="false">voiceAnnounceTime</string>
<string-array name="voice_announcement_distance_values">
<item>@string/voice_announcement_distance_default</item> <!-- km/miles -->
<item>0.1</item>
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 @@ -605,6 +605,7 @@ limitations under the License.
<string name="voice_per_kilometer">per kilometer</string>
<string name="voice_per_mile">per mile</string>
<string name="voice_per_nautical_mile">per nautical mile</string>
<string name="time_announce">Current time</string>
<string name="lap_time">Lap time</string>
<string name="pace">Pace</string>
<string name="lap_speed">Lap speed</string>
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 @@ -32,6 +32,13 @@
android:title="@string/voice_on_device_speaker_title" />
<PreferenceCategory android:title="@string/settings_announcements_title">

<!-- Added Current Time Voice Announcement Switch-->
<SwitchPreference
android:defaultValue="true"
android:key="@string/voice_announce_time_key"
android:title="@string/time_announce" />


<SwitchPreference
android:defaultValue="true"
android:key="@string/voice_announce_total_distance_key"
Expand Down

0 comments on commit 435df5c

Please sign in to comment.