Can I write one widget with glance view for all watches

I plan to write simple widget, icon, progress (line) text - so it' can be maybe ciq 1.x app

If I implement getGlanceView(), will this widget run for all watches? If no glance system shows view?

By the way is any place to see what functionality are implemented on each watch? My widget will show stress but on my f6 there is widget with stress and if this widget is on all watches I don't want to spend time unproductive.

  • Here's an example of how you could do it.

    jungle file:

    fr245.excludeAnnotations = glance_live_updates

    fr245m.excludeAnnotations = no_glance_live_updates

    glance view class:

    (:glance) class YourGlanceView extends Ui.GlanceView {
        // other code goes here ...
    
        (:glance_live_updates) var timer = null;
        (:glance_live_updates) function onUpdate(dc) {
            // awesome code for displaying live data (once per second)
            // ...
            
            if (timer == null) {
                timer = new Timer.timer();
            }
            timer.start(method(:onTimerExpired), 1000, false);
        }
    
        (:glance_live_updates) function onTimerExpired() {
          WatchUi.requestUpdate();
        }
    
        (:no_glance_live_updates) function onUpdate(dc) {
            // lame code for displaying data that refreshes once per 30s
            // ...
        }
    }


    Or you could do what I do for my stopwatch widget, and not provide a glance view at all for non-live glance devices. (Then you just get the default view with the app name)

    app class:

    (:no_glance_live_updates) class YourApp extends Application.AppBase {
        // implement everything except getGlanceView()
        // ...
    }
    
    (:glance_live_updates :glance) class YourApp extends Application.AppBase {
        // everything except getGlanceView()
        // ...
    
        function getGlanceView() {
            return [ new YourGlanceView() ];
        }
    }

    (I don't claim this is a great way to do things. You could eliminate duplicate code by having common helper functions or by inheriting from a common base class, although that would increase memory usage slightly)

    This would probably be a better design (although I haven't tried it):

    class YourApp extends Application.AppBase {
        // implement everything except getGlanceView()
        // ...
    
        (:no_glance_live_updates :glance) function getGlanceView() {
            return Application.AppBase.getGlanceView();
        }
    
        (:glance_live_updates :glance) function getGlanceView() {
            return [ new YourGlanceView() ];
        }
    }

  • I user a helper class so most of the code for the glance view is shared with the main view.  Unless you're doing something like a stopwatch, if the glance view isn't updated every second, it may not be important.  For example with a background service for weather, a 30 sec delay isn't really noticeable on the device.

  • I use a couple of helper classes too (annotated with ":glance" of course).

    Since the OP asked for an example of how to display different things for live updates and non-live updates, I gave it to them.

  • I need every second update

    thx for cod

    how jungle file look? has annotation value or only exist or no so in code I can use if exist?

  • I already showed you an example of the jungle file:

    jungle file:

    fr245.excludeAnnotations = glance_live_updates

    fr245m.excludeAnnotations = no_glance_live_updates

    For each device/resource qualifier you're interested in, you specify the annotations that should be *excluded* for that device.

    e.g.

    fr245.excludeAnnotations = glance_live_updates;X;Y;Z

    ^ This means that for fr245, any code annotated with glance_live_updates, X, Y, or Z will *not* be included in the app.

    [https://developer.garmin.com/connect-iq/core-topics/build-configuration/#buildfileexclusions]

  • so it means that in mc code I always put full code with annotation and in jungle only exclude some of code

  • so it means that in mc code I always put full code with annotation and in jungle only exclude some of code

    Pretty much. But annotations can go on non-local variables, functions, classes and modules, so you have flexibility in how you want to structure things. It depends on whether you care about saving memory or writing maintainable code. (e.g. Save as memory as possible = write duplicate code. Write maintainable code = eliminate duplicate code, but consume slightly more memory.)

  • thx,

    and next question: preinstalled stress widget can draw icon in different colour depend on stress level but ciq widget has in this place static icon and dc is out of this region. Is it possible to change this behaviour?

  • Unless you have a device with glances, there are things you don't see in the sim or like on the device.  For one, you see 3 different widgets at the same time, and maybe displaying seconds in a glance isn't that critical, as the user can just go full screen.

    Just a "glance" with more details close at hand.

    I think even a reduced glance is better than the launcher icon and app name, which is what happens with no glance view.  Looks like something is missing in the app.