Skip to content

Commit

Permalink
Improved application screens layout. The meditation session now can b…
Browse files Browse the repository at this point in the history
…e paused/resumed using the back button (ex: you are meditating and a package arrives for you, just use the back button).
  • Loading branch information
dliedke committed Jul 17, 2022
1 parent f71460d commit 4b85261
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 28 deletions.
33 changes: 30 additions & 3 deletions HrvAlgorithms/sources/activity/HrActivity.mc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ module HrvAlgorithms {

protected function onBeforeStop() {
}

// Pause/Resume session, returns true is session is now running
function pauseResume() {
// Check if session is running
if (me.mFitSession.isRecording()) {

// Stop the timer and refresh the screen
// to show the pause text
me.mFitSession.stop();
me.mRefreshActivityTimer.stop();
me.mRefreshActivityTimer = null;
refreshActivityStats();
return false;

} else {

// Restart the timer for the session
me.mFitSession.start();
me.mRefreshActivityTimer = new Timer.Timer();
me.mRefreshActivityTimer.start(method(:refreshActivityStats), RefreshActivityInterval, true);
return true;
}
}

function isTimerRunning() {
return me.mFitSession.isRecording();
}

private function createMinHrDataField() {
me.mMinHrField = me.mFitSession.createField(
Expand All @@ -50,9 +77,9 @@ module HrvAlgorithms {
private var mMinHr;

function refreshActivityStats() {
if (me.mFitSession.isRecording() == false) {
return;
}
//if (me.mFitSession.isRecording() == false) {
// return;
//}

var activityInfo = Activity.getActivityInfo();
if (activityInfo == null) {
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="2.5.0">
<iq:application entry="MeditateApp" id="57843a03841b4410aff4e4c427c42caf" launcherIcon="@Drawables.launcherIcon" minSdkVersion="1.4.0" name="@Strings.AppName" type="watch-app" version="2.6.0">
<iq:products>
<iq:product id="fr235"/>
</iq:products>
Expand Down
6 changes: 3 additions & 3 deletions Meditate/resources/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<property id="summaryStressValueXPos" type="number">70</property>
<property id="summaryHrvIconsXPos" type="number">50</property>
<property id="summaryHrvValueXPos" type="number">70</property>
<property id="summaryLinesYOffset" type="number">20</property>
<property id="meditateActivityIconsXPos" type="number">80</property>
<property id="summaryLinesYOffset" type="number">10</property>
<property id="meditateActivityIconsXPos" type="number">86</property>
<property id="meditateActivityIconsYOffset" type="number">5</property>
<property id="meditateActivityXHrvTextOffset" type="number">20</property>
<property id="detailsModelLineHeight" type="number">32</property>
<property id="detailsModelLineHeight" type="number">27</property>
<property id="detailsModelIconHeight" type="number">32</property>
<property id="hmmTimePickerOutputXOffset" type="number">85</property>
<property id="mmssTimePickerOutputXOffset" type="number">75</property>
Expand Down
3 changes: 3 additions & 0 deletions Meditate/resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,7 @@
<string id="editIntervalAlertsMenu_title">Edit Interval Alerts</string>

<string id="activityDelayedFinishingText">Finishing...</string>

<string id="meditateActivityPaused">[Paused]</string>

</strings>
3 changes: 2 additions & 1 deletion Meditate/source/activity/MeditateActivity.mc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ class MediteActivity extends HrvAlgorithms.HrvAndStressActivity {
}

protected function onBeforeStart(fitSession) {
mMeditateModel.isTimerRunning = true;
HrvAlgorithms.HrvAndStressActivity.onBeforeStart(fitSession);
me.mVibeAlertsExecutor = new VibeAlertsExecutor(me.mMeditateModel);
}

protected function onRefreshHrvActivityStats(activityInfo, minHr, hrvSuccessive) {
if (activityInfo.elapsedTime != null) {
me.mMeditateModel.elapsedTime = activityInfo.elapsedTime / 1000;
me.mMeditateModel.elapsedTime = activityInfo.timerTime / 1000;
}
me.mMeditateModel.currentHr = activityInfo.currentHeartRate;
me.mMeditateModel.minHr = minHr;
Expand Down
5 changes: 3 additions & 2 deletions Meditate/source/activity/MeditateDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class MeditateDelegate extends Ui.BehaviorDelegate {
Ui.switchToView(me.mSessionPickerDelegate.createScreenPickerView(), me.mSessionPickerDelegate, Ui.SLIDE_RIGHT);
}

function onBack() {
//making sure the app doesn't exit during an activity until the user stops it
function onBack() {
// back button to pause/resume the activity
me.mMeditateModel.isTimerRunning = me.mMeditateActivity.pauseResume();
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Meditate/source/activity/MeditateModel.mc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MeditateModel {
me.minHr = null;
me.currentHr = null;
me.hrvSuccessive = null;
me.isTimerRunning = false;
}

private var mSession;
Expand All @@ -16,6 +17,7 @@ class MeditateModel {
var minHr;
var elapsedTime;
var hrvSuccessive;
var isTimerRunning;

function isHrvOn() {
return false;
Expand Down
30 changes: 16 additions & 14 deletions Meditate/source/activity/MeditateView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class MeditateView extends Ui.View {

private function renderHrStatusLayout(dc) {
var xPosText = dc.getWidth() / 2;
var yPosText = getYPosOffsetFromCenter(dc, 0);
me.mHrStatusText = createMeditateText(Gfx.COLOR_WHITE, TextFont, xPosText, yPosText, Gfx.TEXT_JUSTIFY_CENTER);
var yPosText = getYPosOffsetFromCenter(dc, 1);
me.mHrStatusText = createMeditateText(Gfx.COLOR_WHITE, TextFont, xPosText + 6, yPosText + 4, Gfx.TEXT_JUSTIFY_CENTER);

var hrStatusX = App.getApp().getProperty("meditateActivityIconsXPos");
var iconsYOffset = App.getApp().getProperty("meditateActivityIconsYOffset");
var hrStatusY = getYPosOffsetFromCenter(dc, 0) + iconsYOffset;
var hrStatusY = getYPosOffsetFromCenter(dc, 1) + iconsYOffset;
me.mHrStatus = new ScreenPicker.Icon({
:font => Gfx.FONT_SMALL,
:symbol => "HR",
:symbol => "HR:",
:color=>Graphics.COLOR_RED,
:xPos => hrStatusX,
:yPos => hrStatusY
Expand All @@ -75,7 +75,7 @@ class MeditateView extends Ui.View {
renderLayoutElapsedTime(dc);

var durationArcRadius = dc.getWidth() / 2;
var mainDurationArcWidth = dc.getWidth() / 4;
var mainDurationArcWidth = (dc.getWidth() / 4) - 10;
me.mMainDuationRenderer = new ElapsedDuationRenderer(me.mMeditateModel.getColor(), durationArcRadius, mainDurationArcWidth);

renderHrStatusLayout(dc);
Expand Down Expand Up @@ -113,7 +113,15 @@ class MeditateView extends Ui.View {
if (me.mMeditateIcon != null) {
mMeditateIcon.draw(dc);
}
me.mElapsedTime.setText(TimeFormatter.format(me.mMeditateModel.elapsedTime));

var timeText = "Time: " + TimeFormatter.format(me.mMeditateModel.elapsedTime);

// Check if activity is paused, render the [Paused] text
if (!me.mMeditateModel.isTimerRunning) {
timeText = Ui.loadResource(Rez.Strings.meditateActivityPaused);
}

me.mElapsedTime.setText(timeText);
me.mElapsedTime.draw(dc);

var alarmTime = me.mMeditateModel.getSessionTime();
Expand All @@ -122,15 +130,9 @@ class MeditateView extends Ui.View {
me.mHrStatusText.setText(me.formatHr(me.mMeditateModel.currentHr));
me.mHrStatusText.draw(dc);
me.mHrStatus.draw(dc);

if (me.mMeditateModel.isHrvOn() == true) {
me.mHrvIcon.draw(dc);
me.mHrvText.setText(me.formatHrv(me.mMeditateModel.hrvSuccessive));
me.mHrvText.draw(dc);
}

}



// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
Expand Down
4 changes: 2 additions & 2 deletions Meditate/source/sessionSettings/SessionPickerDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ class SessionPickerDelegate extends ScreenPicker.ScreenPickerDelegate {
details.titleColor = session.color;

if (session.time > 59) {
details.detailLines[2].value.text = " " + TimeFormatter.formatMinutes(session.time);
details.detailLines[1].value.text = " " + TimeFormatter.formatMinutes(session.time);
} else {
details.detailLines[2].value.text = " " + TimeFormatter.formatSeconds(session.time);
details.detailLines[1].value.text = " " + TimeFormatter.formatSeconds(session.time);
}

details.setAllIconsXPos(me.sessionDetailsIconsXPos);
Expand Down
2 changes: 1 addition & 1 deletion Meditate/source/summaryScreen/SummaryViewDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SummaryViewDelegate extends ScreenPicker.ScreenPickerDelegate {
details.titleColor = Gfx.COLOR_BLACK;

details.detailLines[1].value.color = Gfx.COLOR_BLACK;
details.detailLines[1].value.text = " " + TimeFormatter.format(me.mSummaryModel.elapsedTime);
details.detailLines[1].value.text = " Time: " + TimeFormatter.format(me.mSummaryModel.elapsedTime);

details.detailLines[2].value.color = Gfx.COLOR_BLACK;
details.detailLines[2].value.text = " Min: " + me.formatHr(me.mSummaryModel.minHr);
Expand Down
3 changes: 2 additions & 1 deletion UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- tracks the overall min, avg and max HR
- Stress
- HRV

- pause/resume session using the back button

![Session picker demo](userGuideScreenshots/sessionPickerDemo.gif)
![Session demo detailed](userGuideScreenshots/sessionDetailedDemo.gif)
Expand Down Expand Up @@ -57,6 +57,7 @@
- **to get good HRV readings you need to minimise wrist movement**

The meditation session finishes once you press the stop button.
The meditation session can be paused/resumed using the back button.

![Session in progress](userGuideScreenshots/sessionInProgressExplained.png)

Expand Down
Binary file modified userGuideScreenshots/CoverImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added userGuideScreenshots/CoverImage2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added userGuideScreenshots/CoverImage3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4b85261

Please sign in to comment.