How can I find the current background/foreground color?

It seems strange that there is not a specific get function to determine the current background color of a device.  How can this be accomplished when creating a widget and widget glance.  Specifically I have multiple devices with different glance backgrounds.  If I want to stay consistent with the overall look and feel I need to know what current is.  I'm not talking about night mode, I'm asking about simple standard displays.  Fenix 6 glances are black background with white lettering not to mention title in caps, Edge 1050 is white background with black lettering in lower case.  This really seems fundamental to me!  I am not able to find where I could find the current background color or for that matter even the device the widget is running on. Thanks for your help in advance.

  • you do override getGlanceView similar to how you override getInitialView

  • you do override getGlanceView similar to how you override getInitialView

    Sorry, I mistyped. I meant getGlanceTheme(), which @bram.d referred to in his post.  I’ve corrected my original post.

    On Edge if you set the GLANCE_THEME_XXX by implementing getGlanceTheme() in your AppBase subclass then
  • Hmm, I think it needs to be tested, and then according to what we see it really does a "bug report" could be made to improve the documentation. When I read the docs I 1st thought it's like the getGlanceView: the app can tell the system which theme it wants to be displayed with. But I read it again now and I can also read it the way you did. For sure a clarification would be needed.

  • When I read the docs I 1st thought it's like the getGlanceView: the app can tell the system which theme it wants to be displayed with. But I read it again now and I can also read it the way you did. For sure a clarification would be needed.

    Yes, the documentation on this is quite limited. I tested it and overriding does work.

    At first I tried it in the simulator with the Edge 850, but it seems this is not implemented there. However, when using the Fenix 8 Pro in the simulator, the glance is rendered differently. Below is GLANCE_THEME_GOLD:

  • Sorry I was busy with other things. Yes you can override getGlanceTheme(), I don't recall where I read that. Garmin's documentation quality is abysmal to my standards (40 yrs professional SE). I include a boilerplate code for a Glance.  It also includes handling of day/night mode and a link to the documentation for that. As to fonts, you are right - the system glance font is not italics and indeed many glances provided by Garmin apply italics. Personally I don't mind but if you insist to have italics you will need to make custom fonts.

    import Toybox.Application;
    import Toybox.Lang;
    import Toybox.WatchUi;
    import Rez.Styles;
    
    
    (:glance)
    class MyApp extends Application.AppBase {
    
        private function setTheme() {
            // Test for night mode
            if (Styles.device_info.hasNightMode
            &&  System.DeviceSettings has :isNightModeEnabled) {
                _theme = System.getDeviceSettings().isNightModeEnabled ? :nighttime : :daytime;
            } else {
                _theme = :daytime;
            }
        }
    
    
        function initialize() {
            AppBase.initialize();
            
            setTheme();
    
        }
    
        // onStart() is called on application start up
        function onStart(state as Dictionary?) as Void {
        }
    
        // onStop() is called when your application is exiting
        function onStop(state as Dictionary?) as Void {
        }
    
        // Return the glance theme to set
        function getGlanceTheme(){
            return GLANCE_THEME_RED;
        }
    
        // Return the glance view
        function getGlanceView() {
            return [ new MyGlanceView() ];
        }
    
        // Return the initial view of your application here
        function getInitialView() {
            return [ new MyView(), new MyViewDelegate() ];
        }
    
        // Application handler for changes in day/night mode
        function onNightModeChanged() {
            setTheme();
            WatchUi.requestUpdate();
        }
    
        // Mode accessor
        function getTheme() as Theme {
            return _theme;
        }
    
        // Return night mode state as boolean
        function isNightModeEnabled() as Boolean {
            return (_theme == :nighttime);
        }
    
    }
    
    (:glance)
    function getApp() as MyApp {
        return Application.getApp() as MyApp;
    }

    import Toybox.Graphics;
    import Toybox.Lang;
    import Toybox.WatchUi;
    import Rez.Styles;
    
    (:glance)
    class MyGlanceView extends GlanceView {
    
        hidden var _glanceText = "Hello, World";
    
        
        //! constructor
        function initialize(){
            GlanceView.initialize();
    //        _glancetext = MyData.getGlanceString(); // returns the content for the Glance
        }
    
        //! onLayout
        function onLayout(dc as Dc) as Void {
            // set layout here
        }
    
        //! onUpdate
        function onUpdate(dc as Dc) as Void {
            // For understanding the following refer to:
            // https://developer.garmin.com/connect-iq/personality-library/colors/
            // Full coding example given in that link
            // Set foreground color
            if ($.getApp().isNightModeEnabled()) {      // We're in night mode
                dc.setColor(system_color_dark__text.color, system_color_dark__text.background);
            } else {                                    // We're in daylight mode
                dc.setColor(system_color_light__text.color, system_color_light__text.background);
            }
    
            // Update your content here
    //        _glanceText = MyData.getGlanceString();
    
            // Draw foreground
            dc.drawText(
                0,
                dc.getHeight()/2,
                Graphics.FONT_SMALL, 
                _glanceText,
                Graphics.TEXT_JUSTIFY_LEFT|Graphics.TEXT_JUSTIFY_VCENTER
            );
        }
        
    }

  • After reviewing your code, I have one suggestion:

    For the background color, I recommend using Graphics.COLOR_TRANSPARENT instead of the system color. Do that if you want the gradient background that some devices have to work properly. You can see this in the Fenix 8 Pro screenshot I posted above.

  • Also interesting: when using these styles in a glance with the strictest type checking level (3), the project does not compile. The compiler reports that they are not available “in all function scopes.”

    To make it compile, you need to disable the scope check by adding the (:typecheck(disableGlanceCheck)) annotation to the function where you want to use them.