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 .

  • Also, I'm curious what the exact use case is for this?

    Do you want to implement a "profile selection" drop-down, where selecting a profile will change a bunch of other values (like background color, etc.)?

  • Thank you for helping me with the pictures and yes, the code is only a short testing code. Every time the settings change (onSettingsChange) I switch aa to bbbb and after another change I switch it back to bbbb. I used this short code for testing purposes only and I used the example from Eclipse. I added only the settings and the short code.

  • Like I said, I believe you, but I thought you previously said that setting a string setting works fine for you.

    All I can do is suggest trying the very simple app that I tried above, which programmatically sets properties associated with a checkbox setting and a list setting. It works fine for me.

    I didn't try triggering the programmatic setting off of onSettingsChanged(), as you seem to be doing, but when trying to diagnose a problem like this, it might be best to try the simplest case possible.

    As the app that I tested is literally just 2 lines added to a default watchface app, I don't think it gets any simpler than that.

    Another advantage of doing a simple test is that if you have to report a bug, it's helpful to have a simple test case so they can reproduce it easily (and that way you don't have to email them your source code or whatever.)

  • Oh, and I see you've got the "Rebuild" checkbox checked. That will kill your app, rebuild it and restart it, which seems like it might interfere with what you're trying to test.

    Try doing your tests without the Rebuild checkbox.

  • The strings change works fine after uploading to IQ store, in the sim the changes don't work at all.

  • Right. Try clearing the Rebuild checkbox.

  • Didn't worked. After unchecking nothing changed. Then I stopped the application, closed the eclipse and simulator. After I started the eclipse and tried to run the app again, the eclipse failed to connect to the simulator. 

    Restarting eclipse doesn't help. Rebuilding the app Settings editor doesn't help. 

  • using Toybox.WatchUi;
    using Toybox.Graphics;
    using Toybox.System;
    using Toybox.Lang;
    using Toybox.Application;
    var setch= false;
    class TestView extends WatchUi.WatchFace {

    function initialize() {
    WatchFace.initialize();
    }
    function onLayout(dc) {
    setLayout(Rez.Layouts.WatchFace(dc));
    }
    function onShow() {
    }
    function onUpdate(dc) {
    if( setch == 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");
    setch = false;
    System.println (["prop>>"+prop]);

    }
    var timeFormat = "$1$:$2$";
    var clockTime = System.getClockTime();
    var hours = clockTime.hour;
    if (!System.getDeviceSettings().is24Hour) {
    if (hours > 12) {
    hours = hours - 12;
    }
    } else {
    if (Application.getApp().getProperty("UseMilitaryFormat")) {
    timeFormat = "$1$$2$";
    hours = hours.format("%02d");
    }
    }
    var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);
    var view = View.findDrawableById("TimeLabel");
    view.setColor(Application.getApp().getProperty("ForegroundColor"));
    view.setText(timeString);
    View.onUpdate(dc);
    }
    function onHide() {
    }
    function onExitSleep() {
    }
    function onEnterSleep() {
    }
    }

    //-----------and AppBase

    using Toybox.Application;
    using Toybox.WatchUi;

    class TestApp extends Application.AppBase {

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

    // onStart() is called on application start up
    function onStart(state) {
    }

    // onStop() is called when your application is exiting
    function onStop(state) {
    }

    var myview;
    // Return the initial view of your application here
    function getInitialView() {
    myview = new TestView();
    return [ myview ];
    }

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

    }

    the whole code... 

  • There is the complete project. It is a virus free - I double checked it. If you can, please look at this. Thanks a lot.

    www.uschovna.cz/.../