SetPropperty() - unable to set value defined in properties as a list

Hi, I'm not able to set propperties that are not a number, but as a list.

example:

This is how I defined the properties:

<setting propertyKey="@Properties.BackgroundColor" title="@Strings.BackgroundColorTitle">

<settingConfig type="list">
<listEntry value="0x000000">@Strings.ColorBlack</listEntry>
<listEntry value="0x555555">@Strings.ColorDarkGray</listEntry>
<listEntry value="0xAAAAAA">@Strings.ColorLightGray</listEntry>
<listEntry value="0xFFFFFF">@Strings.ColorWhite</listEntry>
<listEntry value="0xFFFFAA">@Strings.ColorSand</listEntry>

</settingConfig>
</setting>

//in my code I have something like this

var bgColor = 0x000000;

apProperties.setProperty("BackgroundColor", bgColor );

but it doesn't work.

I need to set the value in settings programmaticaly.

Have you anyone some hint? There is no info in the documentation how to manage the settings.

second question:

Why the simulator doesn't change the settings values (I tested numbers), It works in my watch, but not in the simulator .

  • Thank you very much, this is a very usefull information. The short names sem to be a pretty good hint! I'll try it.

  • Do all 30 of your apps programmatically set a numerical property and expect the associated list setting to be updated?

    Because that's what the OP is talking about here. Not the other way around (which is what's normally done.)

  • There is no way that could possibly happen.  The settings.json lives on the app store and you can't change the list itself.  It's pulled down as needed.  It will show the current setting in a list with setting.  Yes, I use that all the time.

  • Nobody is talking about changing the list itself.

    The OP is trying to set a property value programmatically, and expecting that when they look at settings, the corresponding list item is selected.

    e.g. They have a list like this associated with a number property (this is just an example):

    "Blue": 1
    "Red: 2
    "Green": 3

    And when they call setProperty(..., 3) (again just an example), and look at app settings in GCM or the sim app settings editor, they expect to see "Green" selected, but they don't.

    What they are seeing is that it works for string settings, but not boolean or list settings.

    What I see (in the sim app settings editor) is that it works fine for booleans and lists.

    Granted, I tried it for a data field and not a watchface like they did.

  • I tried this with a watchface in Eclipse. I created a watchface from scratch:

    1) Selected New Project > Watchface > Simple Watchface with Settings

    The properties/settings look like this:

    <properties>
    
        <property id="BackgroundColor" type="number">0x000000</property>
        <property id="ForegroundColor" type="number">0xFF0000</property>
        <property id="UseMilitaryFormat" type="boolean">false</property>
    
    </properties>
    
    <settings>
    
        <setting propertyKey="@Properties.BackgroundColor" title="@Strings.BackgroundColorTitle">
            <settingConfig type="list">
                <listEntry value="0x000000">@Strings.ColorBlack</listEntry>
                <listEntry value="0x555555">@Strings.ColorDarkGray</listEntry>
                <listEntry value="0xAAAAAA">@Strings.ColorLightGray</listEntry>
                <listEntry value="0xFFFFFF">@Strings.ColorWhite</listEntry>
            </settingConfig>
        </setting>
    
        <setting propertyKey="@Properties.ForegroundColor" title="@Strings.ForegroundColorTitle">
            <settingConfig type="list">
                <listEntry value="0x000000">@Strings.ColorBlack</listEntry>
                <listEntry value="0x0000FF">@Strings.ColorBlue</listEntry>
                <listEntry value="0xFF0000">@Strings.ColorRed</listEntry>
                <listEntry value="0xFFFFFF">@Strings.ColorWhite</listEntry>
            </settingConfig>
        </setting>
    
        <setting propertyKey="@Properties.UseMilitaryFormat" title="@Strings.MilitaryFormatTitle">
            <settingConfig type="boolean" />
        </setting>
    
    </settings>
    

    2) Ran the app and open the settings editor (which ofc showed all the defaults):

    3) Added the following 2 lines to View::onUpdate():

        function onUpdate(dc) {
        	Application.getApp().setProperty("BackgroundColor", 0x555555);
        	Application.getApp().setProperty("UseMilitaryFormat", true);
    

    4) Ran the app

    5) Looked at settings again (without even stopping/restarting the app):

    I'll see what happens if I push the app the store and try it with Garmin Connect Mobile.

  • So I tried the following:

    1) Uploaded the WF app described above to the store

    2) Installed WF

    3) Opened settings in Garmin Connect Mobile (iOS). The programmatically set settings were displayed, not the default settings

    The only missing thing is I never tested the default settings (as the WF was selected as soon as it was installed, and the programmatic settings were triggered on onUpdate(), so there was no way to see the default settings.) However, I'm pretty confident there would be no way to see Background Color = Dark Gray and Military Format = true unless the programmatic settings had worked.

  • So I don't know what to say, except that you could try this very simple case (creating an WF app from the "Simple Watchface with Settings" template and adding two lines).

    Also, are you using GCM on iOS or Android?

  • I tried this:

    //----------------------
    <properties>
    <property id="timeBgValBkp" type="string">11111</property>
    <property id="BackgroundColor" type="number">0x000000</property>
    <property id="ForegroundColor" type="number">0xFF0000</property>
    <property id="UseMilitaryFormat" type="boolean">false</property>
    </properties>

    //-------------------
    <settings>
    <setting propertyKey="@Properties.timeBgValBkp" title="@Strings.BCTitle">
    <settingConfig type="alphaNumeric" >
    </settingConfig>
    </setting>

    <setting propertyKey="@Properties.BackgroundColor" title="@Strings.BackgroundColorTitle">
    <settingConfig type="list">
    <listEntry value="0x000000">@Strings.ColorBlack</listEntry>
    <listEntry value="0x555555">@Strings.ColorDarkGray</listEntry>
    <listEntry value="0xAAAAAA">@Strings.ColorLightGray</listEntry>
    <listEntry value="0xFFFFFF">@Strings.ColorWhite</listEntry>
    </settingConfig>
    </setting>
    //------------------------
    <string id="AppName">Test</string>
    <string id="BCTitle">Color</string>
    <string id="BackgroundColorTitle">Background Color</string>
    <string id="ForegroundColorTitle">Foreground Color</string>
    <string id="MilitaryFormatTitle">Military Format for 24 Hour Time</string>
    <string id="ColorBlack">Black</string>
    <string id="ColorDarkGray">Dark Gray</string>
    <string id="ColorLightGray">Light Gray</string>
    <string id="ColorWhite">White</string>
    <string id="ColorBlue">Blue</string>
    <string id="ColorRed">Red</string>
    </strings>
    //---------------------------------------

    function onUpdate(dc) {
    if( settingsChanged == true ){
    var apProperties = Application.getApp();
    var prop = apProperties.getProperty("timeBgValBkp");
    if(apProperties.getProperty("timeBgValBkp").equals("bbbbb"))
    {
    apProperties.setProperty("timeBgValBkp", "aa");
    }
    else
    {
    apProperties.setProperty("timeBgValBkp", "bbbbb");
    }
    prop = apProperties.getProperty("timeBgValBkp");
    settingsChanged = false;
    System.println (["prop>>"+prop]);
    }
    }

    and my settings in the Eclipse and App Settings Editor don't change. I use Windows7 and android. 

  • I use android and Windows7 and I don't know how to inset picture as a reply, sorry.

  • Yeah, I believe you, the screenshots aren't necessary. If you do want to post images in these forums, you can:

    - copy and paste

    - drag and drop

    - Use Insert > Image and upload an image, or link to one from an external host like https://postimages.org/ or https://imgbb.com/

    - If you get an error message about quotas, you can just paste a regular link from an external host

    Anyway, I had a long reply typed up, but I guess it got deleted when you deleted one of your duplicate comments. Terribad Garmin forums strike again. ¯\_(ツ)_/¯

    1) I don't understand the sample code posted above. How is settingsChanged set to true? Is it when onSettingsChange() is triggered?

    Consider this scenario:

    - onUpdate(), settingsChanged = true, and timeBgValBkp = "bbbbbb". Your code will set it to "aa"

    - onUpdate(), settingsChanged = true, and timeBgValBkp = "aa". Your code will set it back to "bbbbbb"

    - onUpdate(), settingsChanged = true, and timeBgValBkp = "bbbbbb". Your code will set it to "aa"

    This could go on indefinitely if the user never changes timeBgValBkp, but they keep triggering settingsChanged (somehow). Is this intentional? Like just a way of testing the code?

    2) I don't see an example of trying to change a list setting in the above code, only a string (alphaNumeric) setting. I thought you said changing a string setting works fine.

    3) Why don't you just try the very simple test case I posted above? It's literally creating a new watchface using New Project > Watchface > Simple Watchface with Settings, and adding two lines.

    I can't recreate your exact problem because I don't have all your code. But you can try to recreate what I saw very easily. If it works, then you'll have to look into your code. If it doesn't work, then something is different about our environments/devices.