getProperty and settings - random numbers

As of my understanding, this is not related to the value type, as of "new developers FAQ 10".
I am able to get a number, and I don't get a string/number error. But I do get a weird number.

I cannot seem to pass the property value to my code when I first launch the simulator. It work for when setting are in place, but the first time, with blank settings, I receive an error.

This is the code for my property values and settings. Used to define colors.
(Property values are 0,1,2,3. It did not work, so I tested with alternative options, including Hex.)

<property id="clHl" type="number">0x555555</property>
<property id="cl1" type="number">0x000000</property>
<property id="cl2" type="number">0</property>
<property id="cl3" type="number">11</property>

<setting propertyKey="@Properties.clBg" title="@Strings.clBgTitle">
<settingConfig type="list">
<listEntry value="0">@Strings.UI_COLOR_White</listEntry>
<listEntry value="1">@Strings.UI_COLOR_Gray</listEntry>
<listEntry value="2">@Strings.UI_COLOR_Dark_Gray</listEntry>
<listEntry value="3">@Strings.UI_COLOR_Black</listEntry>
</settingConfig>
</setting>



My println return these values for those properties...:
43775
5592405
11184810
11184810

- How does it translate this? I actually need simple numbers (e.g.1) to use on a color array.
- Does the simulator behave differently than the watch, as you are forced to populate the settings before running it? I tried to use setProperty, but it still returns the same value.

I am a bit lost as I don't understand the logic of what is happening.

  • I'm not sure what you're doing or seeing, but this works exactly as I'd expect.

    Here is my properties.xml...

    <resources>
    <properties>
    <property id="clBg" type="number">0</property>
    <property id="clHl" type="number">0x555555</property>
    <property id="cl1" type="number">0x000000</property>
    <property id="cl2" type="number">0</property>
    <property id="cl3" type="number">11</property>
    </properties>

    <strings>
    <string id="clBgTitle">Background Color</string>
    <string id="clHlTitle">Foreground Color</string>
    <string id="cl1Title">Setting 1</string>
    <string id="cl2Title">Setting 2</string>
    <string id="cl3Title">Setting 3</string>
    <string id="UI_COLOR_White">White</string>
    <string id="UI_COLOR_Gray">Gray</string>
    <string id="UI_COLOR_Dark_Gray">Dark Gray</string>
    <string id="UI_COLOR_Black">Black</string>
    </strings>

    <settings>
    <setting propertyKey="@Properties.clBg" title="@Strings.clBgTitle">
    <settingConfig type="list">
    <listEntry value="0">@Strings.UI_COLOR_White</listEntry>
    <listEntry value="1">@Strings.UI_COLOR_Gray</listEntry>
    <listEntry value="2">@Strings.UI_COLOR_Dark_Gray</listEntry>
    <listEntry value="3">@Strings.UI_COLOR_Black</listEntry>
    </settingConfig>
    </setting>

    <setting propertyKey="@Properties.clHl" title="@Strings.clHlTitle">
    <settingConfig type="list">
    <listEntry value="0">@Strings.UI_COLOR_White</listEntry>
    <listEntry value="1">@Strings.UI_COLOR_Gray</listEntry>
    <listEntry value="2">@Strings.UI_COLOR_Dark_Gray</listEntry>
    <listEntry value="3">@Strings.UI_COLOR_Black</listEntry>
    </settingConfig>
    </setting>

    <setting propertyKey="@Properties.cl1" title="@Strings.cl1Title">
    <settingConfig type="numeric" />
    </setting>

    <setting propertyKey="@Properties.cl2" title="@Strings.cl2Title">
    <settingConfig type="numeric" />
    </setting>

    <setting propertyKey="@Properties.cl3" title="@Strings.cl3Title">
    <settingConfig type="numeric" />
    </setting>
    </settings>
    </resources>


    Here is my application code...

    using Toybox.Application;
    using Toybox.WatchUi;
    using Toybox.Graphics;

    class ObjectStoreView extends WatchUi.View {

    hidden var mProperties;
    hidden var mPropertyNames;

    function initialize(properties) {
    View.initialize();

    mProperties = properties;
    mPropertyNames = [
    "clBg",
    "clHl",
    "cl1",
    "cl2",
    "cl3"
    ];
    }

    function onUpdate(dc) {
    dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
    dc.clear();

    var font = Graphics.FONT_XTINY;

    var cx = dc.getWidth() / 2;
    var cy = dc.getHeight() / 2;
    var dy = dc.getFontHeight(font);

    cy -= (mPropertyNames.size() * dy) / 2;

    for (var i = 0; i < mPropertyNames.size(); ++i) {
    var propertyName = mPropertyNames;
    var propertyValue = mProperties.getProperty(propertyName);

    var text = Lang.format("$1$: $2$", [ propertyName, propertyValue ]);
    dc.drawText(cx, cy, font, text, Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);

    cy += dy;
    }
    }
    }

    class ObjectStore extends Application.AppBase {

    function initialize() {
    AppBase.initialize();
    }

    function getInitialView() {
    return [ new ObjectStoreView(self) ];
    }

    function onSettingsChanged() {
    WatchUi.requestUpdate();
    }
    }
    [/code]

    When I run it, I see...

    clBg: 0
    clHl: 5592405
    cl1: 0
    cl2: 0
    cl3: 11


    The value 0x555555 is 5592405, so everything is good as far as I can tell.

    Travis
  • Thanks for your help, and sorry I posted an incomplete code.

    I think I found the issue, thanks to your help. It does not look like a coding issue, more like a simulator/watch behaviour.
    I had to reset the settings, in order for the new value to show.

    I was under the impression that when you launch an app, it would read the properties first and use whichever value finds there.
    Instead it reads whichever value it had in memory of the simulator before, and won't change if the property file is changed.
    Am I correct?
  • Properties are used for the initial values in your app's .set file (it's in garmin\apps\settings, both on a device as well as in the sim's temp directory). The .set can then be changed with app settings (phone or GE on a store load app, "App Settings Editor" in Eclipse), or can be changed in your code. (setProperty()).
    When you delete the .set or use "Reset App Settings" in the sim, the .set gets recreated with the default values for the properties.