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();
}
  • function onSettingsChanged() {
    Sys.println("onSettingsChanged 1");
    var app = App.getApp();
    app.setProperty(0, 1);
    Ui.requestUpdate();
    }


    I can't explain why you're not seeing the println, but it seems like it might be a bad idea to change a property from within onSettingsChanged(). If the call to setProperty() results in a call to onSettingsChanged(), you will probably not like the result.

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


    I can't explain why you're not seeing the println, but it seems like it might be a bad idea to change a property from within onSettingsChanged(). If the call to setProperty() results in a call to onSettingsChanged(), you will probably not like the result.

    Travis


    Changing a setting using setProperty() is ok inside of onSettingsChanged(). onSettingsChanged() only gets called after an app is configured with GCM while the app is running. So at this point it's safe to modify any settings.
  • Thanks Jim for the support.

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


    Also try deleting the settings and data file for the app from the respective folders.
    Maybe something is corrupt.
  • onSettingsChanged() only gets called after an app is configured with GCM while the app is running.

    Thanks! It wasn't clear from the reference docs when this was supposed to get called. Perhaps a docs update?
  • Thanks! It wasn't clear from the reference docs when this was supposed to get called. Perhaps a docs update?


    Yep, I'll get those docs updated.
  • Former Member
    Former Member over 9 years ago
    So I'm having trouble getting the user setting to work in GCM/GE on a test widget I created. I used the example from the start of this thread to make a widget that can change background color based on user choice. With the widget running in the simulator I can go to connect iq/app settings editor and change the color and see it change on the widget. So far so good, but when I build the widget for my vivoactive and sideload it there is no setting options in GE or in GCM. I get the exact same behavior from the Object store sample. I can make changes in the simulator but not on the device. Vivoactive is running 3.3 and Eclipse is using 1.2.1. Not sure what I'm missing here. Can other people sideload the object store example and make changes on GCM?
  • Sorry, but as of today, "user settings" is not available when sideloading something. It's got to come from the app store for GCM and GE to allow user settings.If you look in your project's "bin" directory, there is a ".json" file there if you have user settings. When you build a package for the store, that file is included, and GCM/GE get that file by way of the app store to do the user settings. (the one in the bin directory is used by eclipse and the simulator)

    So right now, you can only test them in the simulator.
  • Former Member
    Former Member over 9 years ago
    Ahhh. Thanks Jim. That's kind of a disappointment, but I guess it makes sense. This was really for a personal project of mine where I set up a widget to control a couple GPIO pins on my raspberry pi, and through out the code I have json calls to a specific IP address. Thing is I mostly use it at home but sometimes I bring it in to work and tinker with it over lunch so the IP address is different. I was hoping I could just modify the address via the user setting function and not have to physically go in and change the code. Oh well. Thanks again for the help.
  • Ahhh. Thanks Jim. That's kind of a disappointment, but I guess it makes sense. This was really for a personal project of mine where I set up a widget to control a couple GPIO pins on my raspberry pi, and through out the code I have json calls to a specific IP address. Thing is I mostly use it at home but sometimes I bring it in to work and tinker with it over lunch so the IP address is different. I was hoping I could just modify the address via the user setting function and not have to physically go in and change the code. Oh well. Thanks again for the help.


    I have a "me only" app that uses two different IP addresses, and what I did is allow toggling them from within the app. It's for a vivoactive, and I use one of the 9 screen regions to toggle with a tap. You could also use a menu to pick one of the two, or even a "confimation" with "use home IP yes/no".
  • Former Member
    Former Member over 9 years ago
    I have a "me only" app that uses two different IP addresses, and what I did is allow toggling them from within the app. It's for a vivoactive, and I use one of the 9 screen regions to toggle with a tap. You could also use a menu to pick one of the two, or even a "confimation" with "use home IP yes/no".


    All good ideas. I think I might try out the menu option. Not sure why I didn't think of that before. It's probably an easier option than the user setting. Thanks again.