Noob questions regarding low power mode handling on different devices

Hey guys!

I'm new to Garmin watchface development, just started monkeying around with it. But I have some questions regarding the best way to handle the low power mode for watchfaces.

I was thinking to hide different elements from the UI that I defined in layout xml, but I do not know how to do that.

Another way is to create a different layout for low power mode, but I do not know how to load the new layout when the power mode changes.

Also. there is the option to draw every icon and text programatically in the onUpdate() function and decide what to draw or not and where to draw it, depending of the device the watchface is running on, but I'm not a big fan of this idea...

Any tips and trick regarding these issues for noobs? Slight smile

Thanks.

  • Ok, you convinced me :) I will draw the elements I need instead of relying on layouts. Thanks!

  • I never use layouts for  things liek WFs, but what I do, is in onLayout, I determine the x/y for everything, usually basing that on things like the width/height of the display, along with the height of fonts.

    That way, in onUpdate, you don't wind up with spaghetti code with a bunch of tests that really only need to be done once.  Easier to maintain and more efficient.

  • I also wanted to choose method 3, but I don't know how to do that from monkey C, how to remove a label or how to change an image source etc.

    A layout is just an Array of Drawables. You can tweak it as you see fit.


    hidden var refreshLayout;
    hidden var drawableHidden;
    
    function onLayout(dc) {
        var layout = Rez.Layouts.myLayout(dc);
        
        setLayout(layout);
        
        // remove the drawable if it is supposed to be hidden
        if (drawableHidden) {
            var drawable = findDrawableById("drawable");
            layout.remove(drawable);
        }
    }
    
    function onUpdate(dc) {
        if (updateLayout) {
            onLayout(dc);
            updateLayout = false;
        }
        
        View.onUpdate(dc);
    }
    
    function onSettingsChanged() {
        drawableHidden = Properties.getValue("DrawableHidden");
        
        // refresh the layout the next time we update
        updateLayout = true;
        
        // ask the system for a refresh
        WatchUi.requestUpdate();
    }

    Assuming the AppBase calls onSettingsChagned() on your view, this should handle when the user changes the option to show or hide the given drawable.

    Option 4 is similar, you just don't need to actually re-load the layout or do the trickery with the refreshLayout flag.

    hidden var layout;
    hidden var drawable;
    hidden var drawableHidden;
    
    function onLayout(dc) {
        var layout = Rez.Layouts.myLayout(dc);
        setLayout(layout);
    
        drawable = findDrawableById("drawable");
    }
    
    function onUpdate(dc) {
        // we're not calling View.onUpdate(dc), so we should really clear the
        // background.. unless you have a drawable for that.
        dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);
        dc.clear();
    
        for (var i = 0; i < layout.size(); ++i) {
            var d = layout[i];
    
            // draw all drawables except `drawable`, only drawing that
            // one if the flag says we should
            if (d != drawable || !drawableHidden) {
                d.draw(dc);
            }
        }
    }
    
    function onSettingsChanged() {
        drawableHidden = Properties.getValue("DrawableHidden");
        WatchUi.requestUpdate();
    }