Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources-eng/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string id="hr">HR</string>
<string id="distance">DIST</string>
<string id="duration">DURATION</string>
<string id="hrZoneTitle">HR ZONES</string>
</resources>
3 changes: 3 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<properties>
<property id="hrZones" type="string">120,132,148,162,178</property>
</properties>
5 changes: 5 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<settings>
<setting propertyKey="@Properties.hrZones" title="@Strings.hrZoneTitle">
<settingConfig type="alphaNumeric" required="true" />
</setting>
</settings>
1 change: 1 addition & 0 deletions resources/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string id="hr">HR</string>
<string id="distance">DIST</string>
<string id="duration">DURATION</string>
<string id="hrZoneTitle">HR ZONES</string>
</resources>
61 changes: 51 additions & 10 deletions source/RunnersField.mc
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,47 @@ class RunnersView extends Ui.DataField {

hidden var avgSpeed= 0;
hidden var hr = 0;
hidden var maxHeartRate = 0;
hidden var averageHeartRate = 0;
hidden var distance = 0;
hidden var elapsedTime = 0;
hidden var gpsSignal = 0;

hidden var currentCadence = 0;
hidden var averageCadence = 0;
hidden var maxCadence = 0;

hidden var hrZones = [ 122,134,149,163,182 ];

hidden var hasBackgroundColorOption = false;

function initialize() {
DataField.initialize();
var str = Application.getApp().getProperty("hrZones");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract that block as a method with a speaking method name that returns the zones, so that the code doesn't get too complex. Would that be ok for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's easy enough.

I also realized the zones are off by one for color. (Zone 2 is blue, etc).
So I'll fix both while I'm at it.

-Andrew
925-875-8728

On Jan 1, 2016, at 18:22, Konrad Paumann notifications@github.com wrote:

In source/RunnersField.mc
#8 (comment):

 hidden var hasBackgroundColorOption = false;

 function initialize() {
     DataField.initialize();
  •    var str = Application.getApp().getProperty("hrZones");
    

Could you extract that block as a method with a speaking method name that
returns the zones, so that the code doesn't get too complex. Would that be
ok for you?


Reply to this email directly or view it on GitHub
https://github.com/kopa/RunnersField/pull/8/files#r48676766.

var loc = str.find(",");
var zones = [ 0, 0, 0, 0 ];
var i = 0;
try {
for(i = 0; i <= 3; i++) {
loc = str.find(",");
if (loc == null) {
loc = str.length();
}
var substr = str.substring(0, loc);
if (substr.length() < 2) {
throw new Exception();
}
zones[i] = substr.toNumber();
str = str.substring(loc+1, str.length());
}
}
catch (ex) {
}
finally {
if (i >= 4) {
hrZones = zones;
}
}
}

//! The given info object contains all the current workout
Expand All @@ -69,6 +98,8 @@ class RunnersView extends Ui.DataField {
avgSpeed = info.averageSpeed != null ? info.averageSpeed : 0;
elapsedTime = info.elapsedTime != null ? info.elapsedTime : 0;
hr = info.currentHeartRate != null ? info.currentHeartRate : 0;
maxHeartRate = info.maxHeartRate != null ? info.maxHeartRate : 0;
averageHeartRate = info.averageHeartRate != null ? info.averageHeartRate : 0;
distance = info.elapsedDistance != null ? info.elapsedDistance : 0;
gpsSignal = info.currentLocationAccuracy;
maxCadence = info.maxCadence != null ? info.maxCadence : 0;
Expand Down Expand Up @@ -152,11 +183,10 @@ class RunnersView extends Ui.DataField {

//pace
dc.setColor(textColor, Graphics.COLOR_TRANSPARENT);
dc.drawText(50, 70, VALUE_FONT, getMinutesPerKmOrMile(computeAverageSpeed()), CENTER);
dc.drawText(57, 70, VALUE_FONT, getMinutesPerKmOrMile(computeAverageSpeed()), CENTER);

//hr
//hr
dc.setColor(hrColor, Graphics.COLOR_TRANSPARENT);
dc.drawText(109, 70, VALUE_FONT, hr.format("%d"), CENTER);
//dc.setColor(hrColor, Graphics.COLOR_TRANSPARENT);
//dc.drawText(109, 70, VALUE_FONT, hr.format("%d"), CENTER);

Expand All @@ -168,6 +198,19 @@ class RunnersView extends Ui.DataField {
drawCadenceZone(dc, currentCadence, maxCadence-0.5, maxCadence+0.5, Graphics.COLOR_WHITE);
drawCadenceZone(dc, currentCadence, averageCadence-0.5, averageCadence+0.5, Graphics.COLOR_DK_RED);
drawCadenceZone(dc, currentCadence, currentCadence-0.5, currentCadence+0.5, Graphics.COLOR_BLACK);

//dc.setColor(hrColor, Graphics.COLOR_TRANSPARENT);
//dc.drawText(109, 70, VALUE_FONT, hr.format("%d"), CENTER);

drawHRZone(dc, hr, 000, hrZones[0], Graphics.COLOR_LT_GRAY);
drawHRZone(dc, hr, hrZones[0], hrZones[1], Graphics.COLOR_BLUE);
drawHRZone(dc, hr, hrZones[1], hrZones[2], Graphics.COLOR_GREEN);
drawHRZone(dc, hr, hrZones[2], hrZones[3], Graphics.COLOR_ORANGE);
drawHRZone(dc, hr, hrZones[3], 250, Graphics.COLOR_RED);

drawHRZone(dc, hr, maxHeartRate-0.5, maxHeartRate+0.5, Graphics.COLOR_WHITE);
drawHRZone(dc, hr, averageHeartRate-0.5, averageHeartRate+0.5, Graphics.COLOR_DK_RED);
drawHRZone(dc, hr, hr-0.5, hr+0.5, Graphics.COLOR_BLACK);

//apace
dc.setColor(textColor, Graphics.COLOR_TRANSPARENT);
Expand Down Expand Up @@ -232,13 +275,11 @@ class RunnersView extends Ui.DataField {
}

// headers:
dc.setColor(headerColor, Graphics.COLOR_TRANSPARENT);
dc.drawText(50, 38, HEADER_FONT, paceStr, CENTER);
dc.drawText(57, 160, HEADER_FONT, avgPaceStr, CENTER);
dc.drawText(109, 38, HEADER_FONT, hrStr, CENTER);
dc.drawText(170, 38, HEADER_FONT, distanceStr, CENTER);
dc.drawText(158, 160, HEADER_FONT, durationStr, CENTER);

dc.setColor(headerColor, Graphics.COLOR_TRANSPARENT);
dc.drawText(50, 43, HEADER_FONT, paceStr, CENTER);
dc.drawText(170, 43, HEADER_FONT, distanceStr, CENTER);
dc.drawText(50, 160, HEADER_FONT, avgPaceStr, CENTER);
dc.drawText(170, 160, HEADER_FONT, durationStr, CENTER);

//grid
dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
Expand Down