Skip to content

Commit

Permalink
3.1.0 Activity name can now be customized in app settings using Garmi…
Browse files Browse the repository at this point in the history
…n Connect or Garmin Express
  • Loading branch information
dliedke committed Aug 19, 2022
1 parent 4f81a15 commit b4c0af4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
3 changes: 2 additions & 1 deletion HrvAlgorithms/sources/activity/HrActivity.mc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ module HrvAlgorithms {
//DEBUG - start - test the heart rate chart instantaneously for X minutes
// also change min/max HR fixed in class HeartRateGraphView and
// call this method in initialize() of this class
/*var numMinutes = 10;
/*
var numMinutes = 10;
var mHRHistory1Min = [55,55,55,55,56,56,56,56,56,58,58,58,62,62,62,65,65,65,65,70,70,70,70,72,72,72,72,73,73,73,73,74,74,76,76,76,76,78,78,78,78,120,130,125,123,110,100,90,78,77,77,74,74,72,72,67,67,67,67,67];
private function PopulateFakeHRHistory() {
Expand Down
2 changes: 1 addition & 1 deletion Meditate/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. -->
<iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="MeditateApp" id="57843a03841b4410aff4e4c427c42caf" launcherIcon="@Drawables.launcherIcon" minSdkVersion="1.4.0" name="@Strings.AppName" type="watch-app" version="3.0.0">
<iq:application entry="MeditateApp" id="57843a03841b4410aff4e4c427c42caf" launcherIcon="@Drawables.launcherIcon" minSdkVersion="1.4.0" name="@Strings.AppName" type="watch-app" version="3.1.0">
<iq:products>
<iq:product id="fr235"/>
</iq:products>
Expand Down
5 changes: 5 additions & 0 deletions Meditate/resources/properties/properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<properties>
<property id="activityName" type="string"></property>
</properties>
</resources>
7 changes: 7 additions & 0 deletions Meditate/resources/settings/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>
<settings>
<setting propertyKey="@Properties.activityName" title="@Strings.activityName">
<settingConfig type="alphaNumeric" />
</setting>
</settings>
</resources>
3 changes: 3 additions & 0 deletions Meditate/resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<string id="summaryRollupMenuOption_exit">Exit</string>
<string id="activityDelayedFinishingText">Finishing...</string>
<string id="meditateActivityPaused">[Paused]</string>
<string id="activityName">Activity Name (use [time] to be replaced by session time and also keep name short):</string>
<string id="mediateActivitySimpleName">Meditating</string>
<string id="mediateActivityName">Meditating [time] 🙏</string>
</strings>
48 changes: 42 additions & 6 deletions Meditate/source/activity/MeditateActivity.mc
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,68 @@ class MediteActivity extends HrvAlgorithms.HrvAndStressActivity {

var fitSessionSpec;
var sessionTime = meditateModel.getSessionTime();
fitSessionSpec = HrvAlgorithms.FitSessionSpec.createCardio(createSessionName(sessionTime, "Meditating"));

// Retrieve activity name property from Garmin Express/Connect IQ
var activityNameProperty = Application.getApp().getProperty("activityName");

// If it is empty, use default name and save the property
if (activityNameProperty == null || activityNameProperty.length() == 0) {
activityNameProperty = Ui.loadResource(Rez.Strings.mediateActivityName);
Application.getApp().setProperty("activityName", activityNameProperty);
}

fitSessionSpec = HrvAlgorithms.FitSessionSpec.createCardio(createSessionName(sessionTime, activityNameProperty));

me.mMeditateModel = meditateModel;
HrvAlgorithms.HrvAndStressActivity.initialize(fitSessionSpec, meditateModel.getHrvTracking(), heartbeatIntervalsSensor);
}


protected function createSessionName(sessionTime, activityName) {

// Calculate session minutes and hours
var sessionTimeMinutes = Math.round(sessionTime / 60);
var sessionTimeHours = Math.round(sessionTimeMinutes / 60);
var sessionName;
var sessionTimeString;

// Create the Connect activity name showing the number of hours/minutes for the meditate session
if (sessionTimeHours == 0) {
sessionName = Lang.format("$1$ $2$min 🙏", [activityName, sessionTimeMinutes]);
sessionTimeString = Lang.format("$1$min", [sessionTimeMinutes]);
} else {
sessionTimeMinutes = sessionTimeMinutes % 60;
if (sessionTimeMinutes == 0){
sessionName = Lang.format("$1$ $2$h 🙏", [activityName, sessionTimeHours]);
sessionTimeString = Lang.format("$1$h 🙏", [sessionTimeHours]);
} else {
sessionTimeString = Lang.format("$1$h $2$min 🙏", [sessionTimeHours, sessionTimeMinutes]);
}
}

// Replace "[time]" string with the activity time
var finalActivityName = stringReplace(activityName,"[time]", sessionTimeString);

// If the generated name is too big, use only default simple name
if (finalActivityName.length() > 21) {
finalActivityName = Ui.loadResource(Rez.Strings.mediateActivitySimpleName);
}

return finalActivityName;
}

function stringReplace(str, oldString, newString)
{
var result = str;

while (true) {
var index = result.find(oldString);
if (index != null) {
var index2 = index+oldString.length();
result = result.substring(0, index) + newString + result.substring(index2, result.length());
} else {
sessionName = Lang.format("$1$ $2$h $3$min 🙏", [activityName, sessionTimeHours, sessionTimeMinutes]);
return result;
}
}

return sessionName;
return null;
}

protected function onBeforeStart(fitSession) {
Expand Down

0 comments on commit b4c0af4

Please sign in to comment.