mirror of
https://github.com/dyuri/garmin-repafield.git
synced 2025-12-16 19:24:01 +00:00
refactor
This commit is contained in:
parent
10f31ffb96
commit
2eaae26106
BIN
repafield1.png
BIN
repafield1.png
Binary file not shown.
|
Before Width: | Height: | Size: 293 KiB After Width: | Height: | Size: 292 KiB |
@ -23,10 +23,6 @@
|
||||
<!-- time/timer -->
|
||||
<label id="timerHM" x="132" y="258" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_MEDIUM" />
|
||||
<label id="timerS" x="134" y="278" color="Graphics.COLOR_LT_GRAY" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_XTINY" />
|
||||
<label id="timeS1" x="212" y="330" color="0x0088FF" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_LARGE" />
|
||||
<label id="timeS2" x="214" y="330" color="0x0088FF" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_LARGE" />
|
||||
<label id="timeS3" x="213" y="328" color="0x0088FF" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_LARGE" />
|
||||
<label id="timeS4" x="213" y="332" color="0x0088FF" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_LARGE" />
|
||||
<label id="time" x="213" y="330" color="0x000000" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_LARGE" />
|
||||
|
||||
<!-- distance/pace/avg pace -->
|
||||
@ -54,12 +50,24 @@
|
||||
<!-- Layouts used for the for the four quadrants. -->
|
||||
<layout id="TopLayout">
|
||||
<drawable class="Background" />
|
||||
<label id="label" x="14" y="75" color="0x888888" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_TINY" />
|
||||
<label id="value" x="14" y="42" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_LARGE" />
|
||||
<drawable class="HeartRate" id="HeartRate">
|
||||
<param name="y">64</param>
|
||||
</drawable>
|
||||
|
||||
<!-- hr labels -->
|
||||
<label id="hr" x="center" y="6" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_MEDIUM" />
|
||||
<label id="ahr" x="32%" y="18" color="0x888888" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_TINY" />
|
||||
<label id="mhr" x="68%" y="18" color="0x888888" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_TINY" />
|
||||
</layout>
|
||||
<layout id="BottomLayout">
|
||||
<drawable class="Background" />
|
||||
<label id="label" x="95" y="10" color="0x888888" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_TINY" />
|
||||
<label id="value" x="95" y="27" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_LARGE" />
|
||||
<drawable class="HeartRate" id="HeartRate">
|
||||
<param name="y">64</param>
|
||||
</drawable>
|
||||
|
||||
<!-- hr labels -->
|
||||
<label id="hr" x="center" y="72" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_MEDIUM" />
|
||||
<label id="ahr" x="32%" y="72" color="0x888888" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_TINY" />
|
||||
<label id="mhr" x="68%" y="72" color="0x888888" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_TINY" />
|
||||
</layout>
|
||||
</layouts>
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
<properties>
|
||||
<property id="appVersion" type="string">0.8.0</property>
|
||||
<property id="themeColor" type="string">0088FF</property>
|
||||
<property id="themeColor2" type="string">0088FF</property>
|
||||
<property id="themeColor3" type="string">FFFF00</property>
|
||||
</properties>
|
||||
@ -6,5 +6,11 @@
|
||||
<setting propertyKey="@Properties.themeColor" title="@Strings.ThemeColorTitle">
|
||||
<settingConfig type="alphaNumeric" />
|
||||
</setting>
|
||||
<setting propertyKey="@Properties.themeColor2" title="@Strings.ThemeColor2Title">
|
||||
<settingConfig type="alphaNumeric" />
|
||||
</setting>
|
||||
<setting propertyKey="@Properties.themeColor3" title="@Strings.ThemeColor3Title">
|
||||
<settingConfig type="alphaNumeric" />
|
||||
</setting>
|
||||
|
||||
</settings>
|
||||
@ -1,7 +1,7 @@
|
||||
<strings>
|
||||
<string id="AppName">RepaField</string>
|
||||
<string id="AppVersionTitle">Version</string>
|
||||
<string id="ThemeColorTitle">Theme Color</string>
|
||||
|
||||
<string id="label">My Value</string>
|
||||
<string id="ThemeColorTitle">Primary Theme Color</string>
|
||||
<string id="ThemeColor2Title">Secondary Theme Color</string>
|
||||
<string id="ThemeColor3Title">Clock Color</string>
|
||||
</strings>
|
||||
|
||||
@ -8,15 +8,37 @@ import Toybox.Application;
|
||||
|
||||
class RepaFieldView extends WatchUi.DataField {
|
||||
|
||||
// settings
|
||||
hidden var themeColor as Numeric;
|
||||
|
||||
hidden var hrValue as Numeric;
|
||||
hidden var ahrValue as Numeric;
|
||||
hidden var mhrValue as Numeric;
|
||||
hidden var themeColor2 as Numeric;
|
||||
hidden var themeColor3 as Numeric;
|
||||
hidden var hrZones as Array<Numeric>;
|
||||
hidden var hrZoneColors as Array<Numeric>;
|
||||
hidden var cadenceZones as Array<Numeric>;
|
||||
hidden var cadenceZoneColors as Array<Numeric>;
|
||||
|
||||
// fields
|
||||
hidden var fBgOverlay;
|
||||
hidden var fTrack;
|
||||
hidden var fPace;
|
||||
hidden var fAPace;
|
||||
hidden var fElevation;
|
||||
hidden var fElevationGain;
|
||||
hidden var fElevationLoss;
|
||||
hidden var fCadence;
|
||||
hidden var fDistance;
|
||||
hidden var fTime;
|
||||
hidden var fTimer;
|
||||
hidden var fTimerSec;
|
||||
hidden var fHr;
|
||||
hidden var fAHr;
|
||||
hidden var fMHr;
|
||||
hidden var fHrGraph;
|
||||
|
||||
// values
|
||||
hidden var hrValue as Numeric;
|
||||
hidden var ahrValue as Numeric;
|
||||
hidden var mhrValue as Numeric;
|
||||
hidden var toDestination as Float;
|
||||
hidden var distance as Float;
|
||||
hidden var timer as Numeric;
|
||||
@ -33,6 +55,8 @@ class RepaFieldView extends WatchUi.DataField {
|
||||
DataField.initialize();
|
||||
|
||||
themeColor = Application.Properties.getValue("themeColor").toNumberWithBase(16);
|
||||
themeColor2 = Application.Properties.getValue("themeColor2").toNumberWithBase(16);
|
||||
themeColor3 = Application.Properties.getValue("themeColor3").toNumberWithBase(16);
|
||||
|
||||
hrValue = 0;
|
||||
ahrValue = 0;
|
||||
@ -78,39 +102,46 @@ class RepaFieldView extends WatchUi.DataField {
|
||||
function onLayout(dc as Dc) as Void {
|
||||
var obscurityFlags = DataField.getObscurityFlags();
|
||||
|
||||
// TODO ?
|
||||
// Top layout
|
||||
if (obscurityFlags == (OBSCURE_TOP | OBSCURE_LEFT | OBSCURE_RIGHT)) {
|
||||
View.setLayout(Rez.Layouts.TopLayout(dc));
|
||||
return;
|
||||
|
||||
// Bottom layout
|
||||
} else if (obscurityFlags == (OBSCURE_BOTTOM | OBSCURE_LEFT | OBSCURE_RIGHT)) {
|
||||
View.setLayout(Rez.Layouts.BottomLayout(dc));
|
||||
return;
|
||||
}
|
||||
|
||||
// Use the generic, centered layout
|
||||
} else {
|
||||
View.setLayout(Rez.Layouts.MainLayout(dc));
|
||||
}
|
||||
View.setLayout(Rez.Layouts.MainLayout(dc));
|
||||
|
||||
// TODO remove
|
||||
var label = View.findDrawableById("label") as Text;
|
||||
if (label != null) {
|
||||
label.setText(Rez.Strings.label);
|
||||
}
|
||||
// fields
|
||||
fBgOverlay = View.findDrawableById("BgOverlay") as BgOverlay;
|
||||
fTrack = View.findDrawableById("Track") as Track;
|
||||
fPace = View.findDrawableById("pace") as Text;
|
||||
fAPace = View.findDrawableById("apace") as Text;
|
||||
fElevation = View.findDrawableById("elevation") as Text;
|
||||
fElevationGain = View.findDrawableById("elevationGain") as Text;
|
||||
fElevationLoss = View.findDrawableById("elevationLoss") as Text;
|
||||
fTime = View.findDrawableById("time") as Text;
|
||||
fTimer = View.findDrawableById("timerHM") as Text;
|
||||
fTimerSec = View.findDrawableById("timerS") as Text;
|
||||
fCadence = View.findDrawableById("cadence") as Text;
|
||||
fDistance = View.findDrawableById("distance") as Text;
|
||||
fHr = View.findDrawableById("hr") as Text;
|
||||
fAHr = View.findDrawableById("ahr") as Text;
|
||||
fMHr = View.findDrawableById("mhr") as Text;
|
||||
fHrGraph = View.findDrawableById("HeartRate") as HeartRate;
|
||||
|
||||
// theme color
|
||||
var bgo = View.findDrawableById("BgOverlay") as BgOverlay;
|
||||
bgo.setColor1(darken(themeColor, 4));
|
||||
bgo.setColor2(darken(themeColor, 2));
|
||||
|
||||
var elevationField = View.findDrawableById("elevation") as Text;
|
||||
elevationField.setColor(themeColor);
|
||||
var elevationGainField = View.findDrawableById("elevationGain") as Text;
|
||||
elevationGainField.setColor(themeColor);
|
||||
var elevationLossField = View.findDrawableById("elevationLoss") as Text;
|
||||
elevationLossField.setColor(themeColor);
|
||||
var aPaceField = View.findDrawableById("apace") as Text;
|
||||
aPaceField.setColor(themeColor);
|
||||
// theme setup
|
||||
fBgOverlay.setColor1(darken(themeColor, 4));
|
||||
fBgOverlay.setColor2(darken(themeColor, 2));
|
||||
fAPace.setColor(themeColor);
|
||||
fElevation.setColor(themeColor2);
|
||||
fElevationGain.setColor(themeColor2);
|
||||
fElevationLoss.setColor(themeColor2);
|
||||
fTime.setColor(themeColor3);
|
||||
}
|
||||
|
||||
function compute(info as Activity.Info) as Void {
|
||||
@ -189,60 +220,36 @@ class RepaFieldView extends WatchUi.DataField {
|
||||
// Display the value you computed here. This will be called
|
||||
// once a second when the data field is visible.
|
||||
function onUpdate(dc as Dc) as Void {
|
||||
// Set the background color - don't ;)
|
||||
// (View.findDrawableById("Background") as Background).setColor(getBackgroundColor());
|
||||
|
||||
// HR value
|
||||
var hrColor = calculateZoneColor(hrValue, hrZones, hrZoneColors);
|
||||
var hr = View.findDrawableById("hr") as Text;
|
||||
hr.setColor(hrColor);
|
||||
hr.setText(hrValue.format("%d"));
|
||||
var ahr = View.findDrawableById("ahr") as Text;
|
||||
ahr.setColor(darken(calculateZoneColor(ahrValue, hrZones, hrZoneColors), 2));
|
||||
ahr.setText(ahrValue.format("%d"));
|
||||
var mhr = View.findDrawableById("mhr") as Text;
|
||||
mhr.setColor(darken(calculateZoneColor(mhrValue, hrZones, hrZoneColors), 2));
|
||||
mhr.setText(mhrValue.format("%d"));
|
||||
var hrGraph = View.findDrawableById("HeartRate") as HeartRate;
|
||||
if (hrGraph != null) {
|
||||
hrGraph.setHRColor(hrColor);
|
||||
hrGraph.setHRZones(hrZones);
|
||||
hrGraph.setHRValue(hrValue);
|
||||
fHr.setColor(hrColor);
|
||||
fHr.setText(hrValue.format("%d"));
|
||||
fAHr.setColor(darken(calculateZoneColor(ahrValue, hrZones, hrZoneColors), 2));
|
||||
fAHr.setText(ahrValue.format("%d"));
|
||||
fMHr.setColor(darken(calculateZoneColor(mhrValue, hrZones, hrZoneColors), 2));
|
||||
fMHr.setText(mhrValue.format("%d"));
|
||||
if (fHrGraph != null) {
|
||||
fHrGraph.setHRColor(hrColor);
|
||||
fHrGraph.setHRZones(hrZones);
|
||||
fHrGraph.setHRValue(hrValue);
|
||||
}
|
||||
|
||||
// track
|
||||
var track = View.findDrawableById("Track") as Track;
|
||||
if (track != null) {
|
||||
track.setToDestination(toDestination);
|
||||
track.setDistance(distance);
|
||||
track.setOffCourse(offCourse);
|
||||
if (fTrack != null) {
|
||||
fTrack.setToDestination(toDestination);
|
||||
fTrack.setDistance(distance);
|
||||
fTrack.setOffCourse(offCourse);
|
||||
}
|
||||
|
||||
// time
|
||||
var time = System.getClockTime();
|
||||
var tstr = time.hour.format("%02d") + ":" + time.min.format("%02d");
|
||||
var timeField = View.findDrawableById("time") as Text;
|
||||
if (timeField != null) {
|
||||
timeField.setText(tstr);
|
||||
if (fTime != null) {
|
||||
var time = System.getClockTime();
|
||||
var tstr = time.hour.format("%02d") + ":" + time.min.format("%02d");
|
||||
fTime.setText(tstr);
|
||||
}
|
||||
// TODO ?
|
||||
var ts1 = View.findDrawableById("timeS1") as Text;
|
||||
var ts2 = View.findDrawableById("timeS2") as Text;
|
||||
var ts3 = View.findDrawableById("timeS3") as Text;
|
||||
var ts4 = View.findDrawableById("timeS4") as Text;
|
||||
ts1.setColor(themeColor);
|
||||
ts1.setText(tstr);
|
||||
ts2.setColor(themeColor);
|
||||
ts2.setText(tstr);
|
||||
ts3.setColor(themeColor);
|
||||
ts3.setText(tstr);
|
||||
ts4.setColor(themeColor);
|
||||
ts4.setText(tstr);
|
||||
|
||||
// timer
|
||||
var timerField = View.findDrawableById("timerHM") as Text;
|
||||
var timerSecField = View.findDrawableById("timerS") as Text;
|
||||
if (timerField != null) {
|
||||
if (fTimer != null) {
|
||||
var trh = timer / 3600;
|
||||
var trm = (timer % 3600) / 60;
|
||||
var trs = timer % 60;
|
||||
@ -252,90 +259,72 @@ class RepaFieldView extends WatchUi.DataField {
|
||||
} else if (timerState == Activity.TIMER_STATE_PAUSED) {
|
||||
timerColor = Graphics.COLOR_YELLOW;
|
||||
}
|
||||
timerField.setColor(timerColor);
|
||||
fTimer.setColor(timerColor);
|
||||
if (trh > 0) {
|
||||
timerField.setText(trh.format("%d") + ":" + trm.format("%02d"));
|
||||
fTimer.setText(trh.format("%d") + ":" + trm.format("%02d"));
|
||||
} else {
|
||||
timerField.setText(trm.format("%02d"));
|
||||
fTimer.setText(trm.format("%02d"));
|
||||
}
|
||||
if (timerSecField != null) {
|
||||
timerSecField.setColor(darken(timerColor, 1.5));
|
||||
timerSecField.setText(trs.format("%02d"));
|
||||
if (fTimerSec != null) {
|
||||
fTimerSec.setColor(darken(timerColor, 1.5));
|
||||
fTimerSec.setText(trs.format("%02d"));
|
||||
}
|
||||
}
|
||||
|
||||
// distance
|
||||
var dstField = View.findDrawableById("distance") as Text;
|
||||
if (dstField != null) {
|
||||
if (fDistance != null) {
|
||||
if (distance >= 10000) {
|
||||
dstField.setText((distance / 1000).format("%.1f"));
|
||||
fDistance.setText((distance / 1000).format("%.1f"));
|
||||
} else {
|
||||
dstField.setText((distance / 1000).format("%.2f"));
|
||||
fDistance.setText((distance / 1000).format("%.2f"));
|
||||
}
|
||||
}
|
||||
|
||||
// pace
|
||||
var paceField = View.findDrawableById("pace") as Text;
|
||||
if (paceField != null) {
|
||||
if (fPace != null) {
|
||||
if (speed != 0) {
|
||||
var pace = 1000 / 60 / speed; // mps -> min/km
|
||||
var pmin = pace.toNumber();
|
||||
var psec = (pace - pmin) * 60;
|
||||
paceField.setText(pmin.format("%2d") + ":" + psec.format("%02d"));
|
||||
fPace.setText(pmin.format("%2d") + ":" + psec.format("%02d"));
|
||||
} else {
|
||||
paceField.setText("--:--");
|
||||
fPace.setText("--:--");
|
||||
}
|
||||
}
|
||||
var apaceField = View.findDrawableById("apace") as Text;
|
||||
if (apaceField != null) {
|
||||
if (fAPace != null) {
|
||||
if (aspeed != 0) {
|
||||
var apace = 1000 / 60 / aspeed; // mps -> min/km
|
||||
var apmin = apace.toNumber();
|
||||
var apsec = (apace - apmin) * 60;
|
||||
apaceField.setText(apmin.format("%2d") + ":" + apsec.format("%02d"));
|
||||
fAPace.setText(apmin.format("%2d") + ":" + apsec.format("%02d"));
|
||||
} else {
|
||||
apaceField.setText("--:--");
|
||||
fAPace.setText("--:--");
|
||||
}
|
||||
}
|
||||
|
||||
// alt/egain/edrop
|
||||
var altField = View.findDrawableById("elevation") as Text;
|
||||
if (altField != null) {
|
||||
if (fElevation != null) {
|
||||
// draw icon
|
||||
altField.setText(altitude.format("%.0f"));
|
||||
fElevation.setText(altitude.format("%.0f"));
|
||||
}
|
||||
var eGainField = View.findDrawableById("elevationGain") as Text;
|
||||
if (eGainField != null) {
|
||||
eGainField.setText(egain.format("%d"));
|
||||
if (fElevationGain != null) {
|
||||
fElevationGain.setText(egain.format("%d"));
|
||||
}
|
||||
var eDropField = View.findDrawableById("elevationLoss") as Text;
|
||||
if (eDropField != null) {
|
||||
eDropField.setText(edrop.format("%d"));
|
||||
if (fElevationLoss != null) {
|
||||
fElevationLoss.setText(edrop.format("%d"));
|
||||
}
|
||||
|
||||
// cadence
|
||||
var cadenceColor = darken(calculateZoneColor(cadence, cadenceZones, cadenceZoneColors), 1.5);
|
||||
var cadenceField = View.findDrawableById("cadence") as Text;
|
||||
cadenceField.setColor(cadenceColor);
|
||||
if (cadenceField != null) {
|
||||
if (fCadence != null) {
|
||||
var cadenceColor = darken(calculateZoneColor(cadence, cadenceZones, cadenceZoneColors), 1.5);
|
||||
fCadence.setColor(cadenceColor);
|
||||
if (cadence != 0) {
|
||||
cadenceField.setText(cadence.format("%d"));
|
||||
fCadence.setText(cadence.format("%d"));
|
||||
} else {
|
||||
cadenceField.setText("-");
|
||||
fCadence.setText("-");
|
||||
}
|
||||
}
|
||||
|
||||
// Set the foreground color and value
|
||||
var value = View.findDrawableById("value") as Text;
|
||||
if (value != null) {
|
||||
if (getBackgroundColor() == Graphics.COLOR_BLACK) {
|
||||
value.setColor(Graphics.COLOR_WHITE);
|
||||
} else {
|
||||
value.setColor(Graphics.COLOR_BLACK);
|
||||
}
|
||||
value.setText(hrValue.format("%d"));
|
||||
}
|
||||
|
||||
// Call parent's onUpdate(dc) to redraw the layout
|
||||
View.onUpdate(dc);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user