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 .

  • Actually I tried a modified/simplified version of your code. It works with a list, alphaNumeric and boolean setting.

    You're free to try it if you want.

    1) New Project > Watchface > Simple Watchface with Settings

    2) Make the following code changes

    In your *App.mc file, add the following global variable:

    var settingsChanged = false;

    Add the following  onSettingsChanged() implementation:

        // New app settings have been received so trigger a UI update
        function onSettingsChanged() {
            settingsChanged = true;  // new code
            WatchUi.requestUpdate();
        }

    Add the following to properties.xml:
        <property id="Str" type="string">abcd</property>

    Add the following to settings.xml:

    <setting propertyKey="@Properties.Str" title="@Strings.Str">
    <settingConfig type="alphaNumeric" />
    </setting>

    Add the following to strings.xml:

    <string id="Str">Str</string>

    Add the following code to your *View.mc file's onUpdate():

        function onUpdate(dc) {
            if (settingsChanged) {
                System.println("settings changed");
                Application.getApp().setProperty("BackgroundColor", 0xFFFFFF);
                Application.getApp().setProperty("UseMilitaryFormat", true);
                Application.getApp().setProperty("Str", "efgh");
                settingsChanged = false;
            }
    3) Run app in sim
     
    4) Select File > Reset all app data in the sim (just in case)
     
    5) Open app settings editor
    6) Without changing any settings, push settings (you don't have to close the app settings editor). Note that the background changes from black to white
    7) Reload settings by selecting the the same project (again) from the Project drop-down in the app settings editor (or you could just close and reopen the editor.)
    Note that Background Color, Use Military Format, and Str have all changed.
  • I tried your project and it works for me, too:

  • Yes, the conosle lines show me that the settings change, but the changes are not visible at the App Setting Editor

  • Yeah but they are for me. I'll upload a gif in a few minutes or so.

  • And like I said, checkbox and list settings work for me too (as in the sample code I provided above.)

  • OK, this works for me as well, but I need something else. I need the settings to change as a response to the button "send settings". please try to change the background color - then the "Color setting" value should change. And this is what I need.

  • OK, this works for me as well, but I need something else.

    ???? I thought you said that's what was *not* working for you.

    "Yes, the conosle lines show me that the settings change, but the changes are not visible at the App Setting Editor"

    need the settings to change as a response to the button "send settings".

    They *are* changing -- on the watch. If you want them to change in the UI (app settings editor or Garmin Connect phone app), you need to reload the settings. You do realize that the settings editor requires you to reload the settings (as shown in the gif) if you want to see changes made by the watch? Just like if you want to see changes on your phone, you'll have to exit settings and re-enter them.

    Anyway, I tried changing the background color at the same time, and it worked. You're just gonna have to trust me on this, as it's 4:40 am where I live and I don't want to record another GIF.

    I realize that you're trying to do a "profile" thing (or whatever), where you expect to change one setting, and have other settings change in response. Like maybe the color dropdown is supposed to change a CSS code field or something. But if you want to see the changes made by the watch, you have to reload the settings.

    It would really help if you would explain exactly what your use case is -- i.e. what do you need this for and exactly how you want it to work.

  • Ok, you are right that I confused you but it was not on purpose. I appologize and I'm very grateful for your help and trust you. The one gif was enough for me.

    1) I didn't know how to refresh the App Settings editor - your last gif helped me very much, so thank you and now I'm going to test my big application. This could be the answer to my very first question. Why the settings in the Settings editor don't change.

    So: after each "send settings" it necessary to "reload" the settings, while the checkbox "rebuild" is not checked.

    Which is something, that I didn't know because there is no report about that behavior of App settings editor.

    2) Now I'm going to test my big application and if this will not work for some settings, then it is probably the memory issue. Anyway I will report the result and thank you again very much.

  • t would really help if you would explain exactly what your use case is -- i.e. what do you need this for and exactly how you want it

    I have many settings in my app and for the case that that user gets confused and sets the values in a weird way, I want him to have the possibility to get back to the default values in one step. And because the values are diferent for each size of display, I can't do it in the code by some default variables, because the default values are stored in  resources. So I load them from the resources (no problem) and try to set the values to the default. And the dafault values are not necessay the default, they can be for example any other set of values that it also stored in my resources, but the principle is the same. Load and put.

    After uploading to the IQ store, the "strings" settings change to the default (or desired) values as I need, but the others don't. There is one possibility - the colors. Maybe there is a problem that I pass decimal and not the Hexa values. But I have to check what's wrong with the booleans, there is only true and false or "true" and "false".

    This is the best description that I can do. :-)