Skip to content

Commit

Permalink
Revert constants to numeric literals for 16K devices because the BETA…
Browse files Browse the repository at this point in the history
… compiler which can optimise them won't yet generate a production build package
  • Loading branch information
wwarby committed Jun 22, 2022
1 parent ad66260 commit d23083d
Showing 1 changed file with 52 additions and 52 deletions.
104 changes: 52 additions & 52 deletions source-memory16K/WalkerView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class WalkerView extends Ui.DataField {
var stepsUnits = Ui.loadResource(Rez.Strings.stepsUnits);

// Create FIT contributor fields
stepsActivityField = createField(stepsLabel, 0, Fit.DATA_TYPE_UINT32, { :mesgType => Fit.MESG_TYPE_SESSION, :units => stepsUnits });
stepsLapField = createField(stepsLabel, 1, Fit.DATA_TYPE_UINT32, { :mesgType => Fit.MESG_TYPE_LAP, :units => stepsUnits });
stepsActivityField = createField(stepsLabel, 0, 6 /* Fit.DATA_TYPE_UINT32 */, { :mesgType => Fit.MESG_TYPE_SESSION, :units => stepsUnits });
stepsLapField = createField(stepsLabel, 1, 6 /* Fit.DATA_TYPE_UINT32 */, { :mesgType => Fit.MESG_TYPE_LAP, :units => stepsUnits });

// Set initial steps FIT contributions to zero
stepsActivityField.setData(0);
Expand Down Expand Up @@ -127,10 +127,10 @@ class WalkerView extends Ui.DataField {
showHeartRateZone = app.getProperty("z");
showSpeedInsteadOfPace = app.getProperty("s");

kmOrMileInMetersDistance = deviceSettings.distanceUnits == System.UNIT_METRIC ? 1000.0f : 1609.34f;
kmOrMileInKmPace = deviceSettings.paceUnits == System.UNIT_METRIC ? 1.0f : 1.60934f;
distanceUnitsLabel = deviceSettings.distanceUnits == System.UNIT_METRIC ? "km" : "mi";
averagePaceOrSpeedUnitsLabel = showSpeedInsteadOfPace ? "/hr" : "/" + (deviceSettings.paceUnits == System.UNIT_METRIC ? "km" : "mi");
kmOrMileInMetersDistance = deviceSettings.distanceUnits == 0 /* System.UNIT_METRIC */ ? 1000.0f : 1609.34f;
kmOrMileInKmPace = deviceSettings.paceUnits == 0 /* System.UNIT_METRIC */ ? 1.0f : 1.60934f;
distanceUnitsLabel = deviceSettings.distanceUnits == 0 /* System.UNIT_METRIC */ ? "km" : "mi";
averagePaceOrSpeedUnitsLabel = showSpeedInsteadOfPace ? "/hr" : "/" + (deviceSettings.paceUnits == 0 /* System.UNIT_METRIC */ ? "km" : "mi");
}

// Handle activity timer events
Expand Down Expand Up @@ -266,11 +266,11 @@ class WalkerView extends Ui.DataField {
// Background colour
var backgroundColour =
darkModeFromSetting
? Gfx.COLOR_BLACK
? 0x000000 /* Gfx.COLOR_BLACK */
: WalkerView has :getBackgroundColor
? getBackgroundColor()
: Gfx.COLOR_WHITE;
var darkMode = backgroundColour == Gfx.COLOR_BLACK;
: 0xFFFFFF /* Gfx.COLOR_WHITE */;
var darkMode = backgroundColour == 0x000000 /* Gfx.COLOR_BLACK */;

// Choose the colour of the battery based on it's state
var battery = System.getSystemStats().battery;
Expand All @@ -281,44 +281,44 @@ class WalkerView extends Ui.DataField {
: battery <= 20
? 2
: 3;
batteryTextColour = Gfx.COLOR_WHITE;
batteryTextColour = 0xFFFFFF /* Gfx.COLOR_WHITE */;
if (batteryState == 0) {
batteryIconColour = Gfx.COLOR_DK_GREEN;
batteryIconColour = 0x00AA00 /* Gfx.COLOR_DK_GREEN */;
} else if (batteryState == 1) {
batteryIconColour = Gfx.COLOR_RED;
batteryIconColour = 0xFF0000 /* Gfx.COLOR_RED */;
} else if (batteryState == 2) {
batteryIconColour = Gfx.COLOR_YELLOW;
batteryTextColour = Gfx.COLOR_BLACK;
batteryIconColour = 0xFFAA00 /* Gfx.COLOR_YELLOW */;
batteryTextColour = 0x000000 /* Gfx.COLOR_BLACK */;
} else {
batteryIconColour = darkMode ? Gfx.COLOR_LT_GRAY : Gfx.COLOR_DK_GRAY;
if (darkMode) { batteryTextColour = Gfx.COLOR_BLACK; }
batteryIconColour = darkMode ? 0xAAAAAA /* Gfx.COLOR_LT_GRAY */ : 0x555555 /* Gfx.COLOR_DK_GRAY */;
if (darkMode) { batteryTextColour = 0x000000 /* Gfx.COLOR_BLACK */; }
}

// Choose the colour of the heart rate icon based on heart rate zone
heartRateZoneTextColour = Gfx.COLOR_WHITE;
heartRateZoneTextColour = 0xFFFFFF /* Gfx.COLOR_WHITE */;
if (heartRateZone == '-') {
if (darkMode) {
heartRateIconColour = Gfx.COLOR_DK_GRAY;
heartRateIconColour = 0x555555 /* Gfx.COLOR_DK_GRAY */;
} else {
heartRateIconColour = Gfx.COLOR_LT_GRAY;
heartRateZoneTextColour = Gfx.COLOR_BLACK;
heartRateIconColour = 0xAAAAAA /* Gfx.COLOR_LT_GRAY */;
heartRateZoneTextColour = 0x000000 /* Gfx.COLOR_BLACK */;
}
} else if (heartRateZone == 1) {
if (darkMode) {
heartRateIconColour = Gfx.COLOR_LT_GRAY;
heartRateZoneTextColour = Gfx.COLOR_BLACK;
heartRateIconColour = 0xAAAAAA /* Gfx.COLOR_LT_GRAY */;
heartRateZoneTextColour = 0x000000 /* Gfx.COLOR_BLACK */;
} else {
heartRateIconColour = Gfx.COLOR_DK_GRAY;
heartRateIconColour = 0x555555 /* Gfx.COLOR_DK_GRAY */;
}
} else if (heartRateZone == 2) {
heartRateIconColour = Gfx.COLOR_BLUE;
heartRateIconColour = 0x00AAFF /* Gfx.COLOR_BLUE */;
} else if (heartRateZone == 3) {
heartRateIconColour = Gfx.COLOR_DK_GREEN;
heartRateIconColour = 0x00AA00 /* Gfx.COLOR_DK_GREEN */;
} else if (heartRateZone == 4) {
heartRateIconColour = Gfx.COLOR_YELLOW;
heartRateZoneTextColour = Gfx.COLOR_BLACK;
heartRateIconColour = 0xFFAA00 /* Gfx.COLOR_YELLOW */;
heartRateZoneTextColour = 0x000000 /* Gfx.COLOR_BLACK */;
} else {
heartRateIconColour = Gfx.COLOR_RED;
heartRateIconColour = 0xFF0000 /* Gfx.COLOR_RED */;
}

// Max width values for layout debugging
Expand Down Expand Up @@ -362,7 +362,7 @@ class WalkerView extends Ui.DataField {
dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight());

// Render horizontal lines
dc.setColor(Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT);
dc.setColor(0xAAAAAA /* Gfx.COLOR_LT_GRAY */, -1 /* Gfx.COLOR_TRANSPARENT */);
for (var x = 0; x < (layout[3] /* lines[3] */ > 0 ? 4 : 3); x++) {
dc.drawLine(0, layout[x] /* lines[x] */, dc.getWidth(), layout[x]);
}
Expand All @@ -373,12 +373,12 @@ class WalkerView extends Ui.DataField {

// Render step goal progress bar
if (stepGoalProgress != null && stepGoalProgress > 0) {
dc.setColor(darkMode ? Gfx.COLOR_GREEN : Gfx.COLOR_DK_GREEN, Gfx.COLOR_TRANSPARENT);
dc.setColor(darkMode ? Gfx.COLOR_GREEN : 0x00AA00 /* Gfx.COLOR_DK_GREEN */, -1 /* Gfx.COLOR_TRANSPARENT */);
dc.drawRectangle(layout[4] /* stepGoalProgressOffsetX */, layout[2] /* lines[2] */ - 1, (dc.getWidth() - (layout[4] /* stepGoalProgressOffsetX */ * 2)) * stepGoalProgress, 3);
}

// Set text rendering colour
dc.setColor(darkMode ? Gfx.COLOR_WHITE : Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.setColor(darkMode ? 0xFFFFFF /* Gfx.COLOR_WHITE */ : 0x000000 /* Gfx.COLOR_BLACK */, -1 /* Gfx.COLOR_TRANSPARENT */);

// Render clock
var currentTime = System.getClockTime();
Expand All @@ -389,22 +389,22 @@ class WalkerView extends Ui.DataField {
+ ":"
+ currentTime.min.format("%02d")
+ (is24Hour ? "" : currentTime.hour >= 12 ? "pm" : "am"),
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render average pace or speed
dc.drawText(halfWidth - layout[5] /* centerOffsetX */, layout[8] /* topRowY */, layout[27] /* topRowFont */,
(showSpeedInsteadOfPace ? formatDistance(averagePaceOrSpeed) : formatTime(averagePaceOrSpeed, true)) + averagePaceOrSpeedUnitsLabel,
Gfx.TEXT_JUSTIFY_RIGHT | Gfx.TEXT_JUSTIFY_VCENTER);
0 /* Gfx.TEXT_JUSTIFY_RIGHT */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render distance
dc.drawText(halfWidth + layout[5] /* centerOffsetX */, layout[8] /* topRowY */, layout[27] /* topRowFont */,
formatDistance(distance) + distanceUnitsLabel, Gfx.TEXT_JUSTIFY_LEFT | Gfx.TEXT_JUSTIFY_VCENTER);
formatDistance(distance) + distanceUnitsLabel, 2 /* Gfx.TEXT_JUSTIFY_LEFT */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render heart rate text
var heartRateText = (heartRate == null ? 0 : heartRate).format("%d");
var heartRateWidth = dc.getTextDimensions(heartRateText, layout[28] /* heartRateFont */)[0];
dc.drawText(halfWidth, layout[17] /* heartRateTextY */, layout[28] /* heartRateFont */,
heartRateText, Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
heartRateText, 1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render heart rate icon
var hrIconY;
Expand All @@ -419,7 +419,7 @@ class WalkerView extends Ui.DataField {
hrIconWidth = layout[13] /* heartRateIconWidth */;
hrIconXOffset = layout[15] /* heartRateIconXOffset */;
}
dc.setColor(heartRateIconColour, Gfx.COLOR_TRANSPARENT);
dc.setColor(heartRateIconColour, -1 /* Gfx.COLOR_TRANSPARENT */);
dc.fillCircle(halfWidth - (hrIconWidth / 4.7), hrIconY + (hrIconWidth / 3.2), hrIconWidth / 3.2);
dc.fillCircle(halfWidth + (hrIconWidth / 4.7), hrIconY + (hrIconWidth / 3.2), hrIconWidth / 3.2);
dc.fillPolygon([
Expand All @@ -429,63 +429,63 @@ class WalkerView extends Ui.DataField {
]);

if (showHeartRateZone && heartRateZone != null) {
dc.setColor(heartRateZoneTextColour, Gfx.COLOR_TRANSPARENT);
dc.drawText(halfWidth, hrIconY + (hrIconWidth / 2) - 3, Gfx.FONT_XTINY,
heartRateZone.toString(), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
dc.setColor(heartRateZoneTextColour, -1 /* Gfx.COLOR_TRANSPARENT */);
dc.drawText(halfWidth, hrIconY + (hrIconWidth / 2) - 3, 0 /* Gfx.FONT_XTINY */,
heartRateZone.toString(), 1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);
}

// Reset text rendering colour
dc.setColor(darkMode ? Gfx.COLOR_WHITE : Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.setColor(darkMode ? 0xFFFFFF /* Gfx.COLOR_WHITE */ : 0x000000 /* Gfx.COLOR_BLACK */, -1 /* Gfx.COLOR_TRANSPARENT */);

// Render current pace or speed
dc.drawText((halfWidth / 2) - (heartRateWidth / 2) + 5, layout[9] /* middleRowLabelY */, layout[29] /* middleRowLabelFont */,
Ui.loadResource(showSpeedInsteadOfPace ? Rez.Strings.speed : Rez.Strings.pace),
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);
dc.drawText(
(halfWidth / 2) - (heartRateWidth / 2) + 5,
layout[10] /* middleRowValueY */,
shrinkMiddleText ? layout[30] /* middleRowValueFontShrunk */ : layout[31] /* middleRowValueFont */,
paceOrSpeedText,
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render timer
dc.drawText((halfWidth * 1.5) + (heartRateWidth / 2) - 5, layout[9] /* middleRowLabelY */, layout[29] /* middleRowLabelFont */,
Ui.loadResource(Rez.Strings.timer), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
Ui.loadResource(Rez.Strings.timer), 1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);
dc.drawText(
(halfWidth * 1.5) + (heartRateWidth / 2) - 5,
layout[10] /* middleRowValueY */,
shrinkMiddleText ? layout[30] /* middleRowValueFontShrunk */ : layout[31] /* middleRowValueFont */,
timeText,
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render steps
dc.drawBitmap(layout[20] /* bottomRowIconX */, layout[21] /* bottomRowIconY */, stepsIcon);
dc.drawText(halfWidth - layout[5] /* centerOffsetX */, layout[18] /* bottomRowUpperTextY */, layout[32] /* bottomRowFont */,
(steps == null ? 0 : steps).format("%d"), Gfx.TEXT_JUSTIFY_RIGHT | Gfx.TEXT_JUSTIFY_VCENTER);
(steps == null ? 0 : steps).format("%d"), 0 /* Gfx.TEXT_JUSTIFY_RIGHT */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render calories
dc.drawBitmap(dc.getWidth() - layout[20] /* bottomRowIconX */ - caloriesIcon.getWidth(), layout[21] /* bottomRowIconY */, caloriesIcon);
dc.drawText(halfWidth + layout[5] /* centerOffsetX */, layout[18] /* bottomRowUpperTextY */, layout[32] /* bottomRowFont */,
(calories == null ? 0 : calories).format("%d"), Gfx.TEXT_JUSTIFY_LEFT | Gfx.TEXT_JUSTIFY_VCENTER);
(calories == null ? 0 : calories).format("%d"), 2 /* Gfx.TEXT_JUSTIFY_LEFT */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Set grey colour for day counts
dc.setColor(Gfx.COLOR_DK_GRAY, Gfx.COLOR_TRANSPARENT);
dc.setColor(0x555555 /* Gfx.COLOR_DK_GRAY */, -1 /* Gfx.COLOR_TRANSPARENT */);

// Render day steps
dc.drawText(halfWidth - layout[5] /* centerOffsetX */, layout[19] /* bottomRowLowerTextY */, layout[32] /* bottomRowFont */,
(daySteps == null ? 0 : daySteps).format("%d"), Gfx.TEXT_JUSTIFY_RIGHT | Gfx.TEXT_JUSTIFY_VCENTER);
(daySteps == null ? 0 : daySteps).format("%d"), 0 /* Gfx.TEXT_JUSTIFY_RIGHT */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render day calories
dc.drawText(halfWidth + layout[5] /* centerOffsetX */, layout[19] /* bottomRowLowerTextY */, layout[32] /* bottomRowFont */,
(dayCalories == null ? 0 : dayCalories).format("%d"), Gfx.TEXT_JUSTIFY_LEFT | Gfx.TEXT_JUSTIFY_VCENTER);
(dayCalories == null ? 0 : dayCalories).format("%d"), 2 /* Gfx.TEXT_JUSTIFY_LEFT */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);

// Render battery
dc.setColor(batteryIconColour, Gfx.COLOR_TRANSPARENT);
dc.setColor(batteryIconColour, -1 /* Gfx.COLOR_TRANSPARENT */);
dc.fillRoundedRectangle(halfWidth - (layout[24] /* batteryWidth */ / 2) + 2 + layout[23] /* batteryX */, layout[22] /* batteryY */ - (layout[25] /* batteryHeight */ / 2), layout[24] /* batteryWidth */ - 4, layout[25] /* batteryHeight */, 2);
dc.fillRoundedRectangle(halfWidth - (layout[24] /* batteryWidth */ / 2) + 2 + layout[23] /* batteryX */ + layout[24] /* batteryWidth */ - 7, layout[22] /* batteryY */ - (layout[25] /* batteryHeight */ / 2) + 4, 7, layout[25] /* batteryHeight */ - 8, 2);
dc.setColor(batteryTextColour, Gfx.COLOR_TRANSPARENT);
dc.setColor(batteryTextColour, -1 /* Gfx.COLOR_TRANSPARENT */);
dc.drawText(halfWidth + layout[23] /* batteryX */, layout[22] /* batteryY */ - 1, layout[33] /* batteryFont */,
battery.format("%d") + "%", Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
battery.format("%d") + "%", 1 /* Gfx.TEXT_JUSTIFY_CENTER */ | 4 /* Gfx.TEXT_JUSTIFY_VCENTER */);
}

function formatTime(milliseconds, short) {
Expand Down

0 comments on commit d23083d

Please sign in to comment.