As far as I can tell my resource file is written correctly, and my .getProperty("maxhr_prop") call in the initialise() function correctly retrieves the default value defined in the resource file as confirmed with a console output "println" and displayed on the datafield in the simulator. Actually I've noticed that modifying the value in the resouce file isn't always updated. The old value seems somewhat sticky. This is on mac.
My datafield code also does a .getProperty call in the compute() function, however the value that I output using both a console output and displayed on my datafield on the simulator never changes from the default value in the resources file (properties.xml).
Here's the resource file
<resources>
<properties>
<property id="maxhr_prop" type="number">165</property>
</properties>
<strings>
<string id="maxhr_title">Maximum Heart Rate</string>
<string id="hr_out_of_range_msg">Max HR must be between 100 and 230</string>
</strings>
<settings>
<setting propertyKey="maxhr_prop" title="maxhr_title">
<settingConfig type="numeric" required="true" min="100" max="230" errorMessage="hr_out_of_range_msg"/>
</setting>
</settings>
</resources>
and the code (this is the "app" class, there is a separate "view" class):
using Toybox.System as System;
using Toybox.Application as App;
class hr_tiz_data {
// public data
var timertime;
var maxHr;
var hr;
var hr_pmax;
var ave_hr;
var ave_hr_pmax;
var zone;
var timer_paused;
const NumZones = 5;
hidden var zoneLowerBound = [NumZones];
var secondsInZone = [NumZones];
function initialize() {
//maxHr = 182;
maxHr = App.getApp().getProperty("maxhr_prop");
System.println("\nMax HR=" + maxHr.format("%d"));
zoneLowerBound = [0, maxHr * 0.77, maxHr * 0.88, maxHr * 0.92, maxHr * 0.95];
secondsInZone = [0, 0, 0, 0, 0];
timertime = 0;
timer_paused = true;
}
function compute(info) {
maxHr = App.getApp().getProperty("maxhr_prop");
System.println("\nMax HR=" + maxHr.format("%d"));
if (info.timerTime != null) {
// Check if user has paused the timer
timer_paused = (info.timerTime == timertime);
if (!timer_paused) {
timertime = info.timerTime;
}
}
- should I be calling "onSettingsChanged()" or is that only for apps and widgets?
- is it expected that datafield App settings are modified while running (i.e. user with GC mobile app), and changes need to be checked for, or should datafields just get the values once at the start?
- if App settings should be checked while running, is there a better place than the compute() function?
Confused - thanks for your help!