User application settings

For most wanted watchface feature - look into a new ObjectStore sample how to define default properies and setting options.

Here is a color configuration example:
<resources>

<properties>
<property id="PROP_COLOR" type="number">1</property>
</properties>

<strings>
<string id="title_color">Color</string>

<string id="opt_color_1">Blue</string>
<string id="opt_color_2">Red</string>
<string id="opt_color_3">Green</string>
</strings>

<settings>
<setting propertyKey="@Properties.PROP_COLOR" title="@Strings.title_color">
<settingConfig type="list">
<listEntry value="1">Rez.Strings.opt_color_1</listEntry>
<listEntry value="2">Rez.Strings.opt_color_2</listEntry>
<listEntry value="3">Rez.Strings.opt_color_3</listEntry>
</settingConfig>
</setting>
</settings>

</resources>


Please note that property must be a number if you can use the list of options.

Then, just load your property in the code, for example:

function onSettingsChanged() {
var color = App.getApp().getProperty("PROP_COLOR");
handleYourColorChangesHere(color);
Ui.requestUpdate();
}
  • Look at the "Object Store" sample in the 1.2.0 SDK to see how simple it can be. It's got user settings...
  • it is great idea. I have prepared watch face with different hands and different backgrounds.

    https://apps.garmin.com/en-US/apps/dd2ae2b7-8d29-4769-8a5d-409975415214
  • Hi guys,

    I have an issue when using the simulator and applying changes to App Settings.



    When clicking "Send Settings", I get "Error in onSettingsChanged()" and "System Error" messages in console and the simulation stops.


    1/ Making changes via the ConnectIQ/App Settings Editor/Send Settings actually work. Although I get this error code that stops simulation, when starting a new simulation, updated parameters will be used.
    2/ This error message appears if I completely remove onSettingsChanged function.
    3/ onSettingsChanged is never entered, as proved by the println message not being displayed on the console.

    Do you guys get the same error?
    Thanks
  • What is the "Error in onSettingsChanged()"? Undefined variable? If you post the console log and your "onSettingsChanged()" code, that could help.
  • All this is in the attached picture in the middle of my previous post.
    Thanks in advance!
    I get the error regardless of whether or not there is a onSettingsChange() at all!
  • If you used code blocks, this would be easier to explain

    In your onSettingsChanged(), a couple of things.

    1) you don't need to have "app".. You're already in the app

    2) is Sys defined at this point with a "using"? I notice your println isn't in your console output

    3) at this point you should "getProperty()" and not setProperty, as I'm assuming got want to get the new settings... Or are you using the OS to flag the view and have it reload stuff? Why not just use a global boolean?
  • Hi Jim,

    Thanks for your help. Sorry, a code block would have been better, here it is.

    using Toybox.Graphics as Gfx;
    using Toybox.Application as App;
    using Toybox.System as Sys;
    using Toybox.Lang as Lang;
    using Toybox.Math as Math;
    using Toybox.Time as Time;
    using Toybox.Time.Gregorian as Calendar;
    using Toybox.WatchUi as Ui;
    using Toybox.ActivityMonitor as ActMon;
    using Toybox.Activity as Act;


    class ClarityApp extends App.AppBase {

    //! onStart() is called on application start up
    function onStart() {
    var app = App.getApp();
    app.setProperty(0, 0);
    }

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

    //! Return the initial view of your application here
    function getInitialView() {
    return [ new ClarityView() ];
    }

    function onSettingsChanged() {
    Sys.println("onSettingsChanged 1");
    var app = App.getApp();
    app.setProperty(0, 1);
    Ui.requestUpdate();
    }
    }

    class ClarityView extends Ui.WatchFace {
    //bunch of code here
    }


    1/ Didn't realize that, thanks.
    2/ yes, Sys is defined with "using" and works in other parts of the code (you see "here1", "here2", "here3" and "don't have to do calcs...", that's all Sys.println).
    3/ I use the object store to flag the view and/or exchange data among classes, for instance between a view and a delegate. Here, this property is also used in ClarityView. I didn't know global variables were possible across classes (never saw it in example). I use them with c++, but I didn't know they were allowed in Monkey C. You just declare them under the list of "using"?
  • Yes, globals can come in handy. I use them for things like change page numbers from a delegate too.. One the of samples (primates?) does this too..

    Here's how I do it for one of my watchfaces.
    using Toybox.Application as App;
    using Toybox.WatchUi as Ui;
    using Toybox.System as Sys;

    var updateSettings=false;

    class SimpleWatchApp extends App.AppBase {

    function onSettingsChanged() {
    updateSettings=true;
    //Sys.println("settings change2");
    Ui.requestUpdate();
    }

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

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

    //! Return the initial view of your application here
    function getInitialView() {
    return [ new SimpleWatchView() ];
    }

    }


    Then in onUpdate() in the view, the first thing I do is check the boolean and reload the settings if needed.
  • Thanks Jim for the support.

    Even after making those changes, I still get the error messages "Error in onSettingsChanged()" and "System Error" in console.
  • Thanks Jim for the support.

    Even after making those changes, I still get the error messages "Error in onSettingsChanged()" and "System Error" in console.


    Maybe try reinstall etc.
    To me it seems your environment is not right any more.

    For me everything works. Your code shows no obvious problems, so maybe try and do clean install and not mess up the SDK versions etc.