User settings - font !?

If I wanted to offer different fonts for users should where shuld I load them? In the layout function as usual? Or in the onshow?

If I load in the layout function will that get called again if the user changes the setting in the garmin app?

If I load in the onshore wont that mean the font will get loaded again and again?

Ta.
  • If I wanted to offer different fonts for users should where shuld I load them?

    You can load them wherever you want. Typically you'd do it in onLayout since that function is not called when your view becomes visible after the first time, but this may not be a concern for your application. I typically use onLayout.

    If I load in the layout function will that get called again if the user changes the setting in the garmin app?

    The only function that gets called when the user changes settings is AppBase.onSettingsChanged. If you want the current view to reload, you need to write some code so that the app object notifies the view that some state has changed, and the view object will need to do the right thing.

    If I load in the onshore wont that mean the font will get loaded again and again?

    Yes. Every time the view is shown. i.e., If your view is active and you call pushView and the pushed view is popped (either explicitly or automatically), onShow will be called. This is why I personally think you should put it into onLayout.

    If you are implementing a data field or watch face, the solution is pretty simple.

    class MyApp extends App.AppBase
    {
    hidden var observer;

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

    function getInitialView() {
    var view = new MyWatchFace();
    setObserver(view);
    return [view];
    }

    function onSettingsChanged() {
    self.broadcast(:settingsChanged);
    }

    function setObserver(observer) {
    self.observer = observer;
    }

    hidden function broadcast(symbol) {
    observer.notify(symbol);
    }

    function getUserSelectedFont() {
    return getProperty("UserSelectedFont");
    }
    }

    class MyWatchFace extends Ui.WatchFace
    {
    hidden var font;
    hidden var dirty = false;

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

    function notify(symbol) {
    if (symbol == :settingsChanged) {
    dirty = true;
    Ui.requestUpdate();
    }
    }

    function onLayout(dc) {
    font = App.getApp().getUserSelectedFont();

    // layout stuff
    }

    function onUpdate(dc) {

    if (dirty) {
    dirty = false;
    onLayout(dc);
    }

    // draw the watch face stuff
    }
    }


    If you are writing an app or widget, and you _never_ have more than one of your view classes on the view stack at a time, this model can work as well. You just need the delegate or the view to register the view with the app. You could do this in View.onShow() or View.onHide() to keep it simple.

    If you potentially have multiple views on the view stack and you want each of them to be able to respond to changes, the App would need to maintain a collection of registered observers, and the delegate would need to register views as they are pushed onto the view stack, and deregister them when they are removed (the View.onShow and View.onHide functions don't tell you if the view is going away, just that it is no longer visible).

    Travis
  • Ta, will give it a go.

    Of course the other option is to tell the user to switch to another screen and reload?
  • Yes. You could tell them to exit the app.
  • Erm, could you explain that code !?
  • Former Member
    Former Member over 9 years ago
    Travis' code is pretty self explanatory....

    Observer (the view) gets notified of a change. In this case the change being that the settings have changed (hence the symbol). Observer reacts on that notification by declaring itself "dirty", meaning the layout has to be refreshed on the next update.
  • yup it works but I still dont get it to be honest!

    is this all covered in the monkey c docs cos dont remember seeing it.
  • Former Member
    Former Member over 9 years ago
    It's basicly the same as:

    class MyApp extends App.AppBase
    {
    var view;

    function getInitialView() {
    view = new MyWatchView();
    return [view];
    }

    function onSettingsChanged() {
    view.onSettingsChanged(<new settings data>);
    }
    }

    class MyWatchView extends Ui.WatchFace
    {
    function onSettingsChanged(<new settings data>) {
    //Adjust the layout ......

    Ui.requestUpdate();
    }
    }


    But nicer coded.
  • It's basicly the same as..

    I think I'd use this code for apps with just one view (all data fields, all watch faces, and only simple widgets and apps). If you have a bigger app with multiple views active (on the view stack), you might want to use a system like what I provided, but tweaked to allow multiple views to be registered for notification.

    But nicer coded.

    Thanks. I stole it from one of my projects.
  • Hello,

    I try to implement a program like this.
    So i made a simpledatafield, define properties and add the code in this subject.
    I generate the prg file and put in my fenix 3 but when I don't see the setting option in the garmin connect app.
    Moreover when i use eclipse app user setting and select my project i don't see the params setting.

    Do I add other configuration file or code to make my program ok ?
    Something escape me

    Thank you.

    Sorry for my poor english.

    I could send my code if you want.
  • I think I'd use this code for apps with just one view (all data fields, all watch faces, and only simple widgets and apps). If you have a bigger app with multiple views active (on the view stack), you might want to use a system like what I provided, but tweaked to allow multiple views to be registered for notification.


    Thanks. I stole it from one of my projects.


    Hello,
    I try to implement a program like this with a property in properties.xml and call it with App.getApp()....
    I also add the code define in this thread but i have questions :

    I never see my property when i use the user setting eclipse plugin ?
    Moreover when i put the prg file in my watch i don't see the settings ?

    So i would like to know what i forget to implement an user setting. An other config file ? else ??

    Thank you