Conditional widget layout based on watch type

Is it possible to retrieve the watch type in the ConnectIQ API? I'd like to add something as below in my view:

[FONT=Courier New]var device_type = ???; //not sure how to retrieve the device type

if ( device_type == "Fenix 3" ) {
// insert Fenix 3 specific layout here
}
else {
// insert generic layout that works on different watch types here
}[/FONT]
  • Not currently, but it's something we've talked about adding.

    To do what you want, however, you can use the layout system to tailor the layout for each device. Take a look at the User Interface section starting on page 42 of the Monkey C Programmer's Guide, or the User Interface info available on developer.garmin.com.
  • If you are using layouts, you don't need a variable that describes the device. You simply need to take advantage of the provided resource compiler. The Monkey C Developer's Guide discusses how the resource compiler allows you to provide device and language specific resource files.

    You will end up with different resource folders for devices that don't use the default behavior, something like this...

    \---Project
    +---bin
    | Project.prg
    | Project.prg.debug.xml
    |
    +---resources
    | layout.xml
    |
    +---resources-fenix3
    | layout.xml
    |
    +---source
    ProjectApp.mc
    ProjectView.mc


    The resources-fenix3\layout.xml file specifies anything from resources\layout.xml that needs to be overwritten to look right on the fenix3 device.
  • Brandon! You are too fast. :)

    If you really feel that you need to know what device you are on, you can still leverage the layout system to tell you. I'm currently using this to work around what I believe to be a bug in the Vivoactive and 920XT. See the bottom of this post for information on how to do it.

    Travis
  • If you are using layouts, you don't need a variable that describes the device. You simply need to take advantage of the provided resource compiler. The Monkey C Developer's Guide discusses how the resource compiler allows you to provide device and language specific resource files.

    You will end up with different resource folders for devices that don't use the default behavior, something like this...

    \---Project
    +---bin
    | Project.prg
    | Project.prg.debug.xml
    |
    +---resources
    | layout.xml
    |
    +---resources-fenix3
    | layout.xml
    |
    +---source
    ProjectApp.mc
    ProjectView.mc


    The resources-fenix3\layout.xml file specifies anything from resources\layout.xml that needs to be overwritten to look right on the fenix3 device.


    Thanks Travis! How do I call the resources/layout.xml vs resources-fenix3/layout.xml from my view? In other words, how does the correct layout get chosen for the correct type of watch?
  • The resource compiler takes care of it. If you define a layout resource named MainLayout in resources\layout.xml and in resources-fenix3\layout.xml, you will get the definition from resources-fenix3 when using a fenix3, and all other devices will use the definition from resources\layouts.xml.

    This is all discussed in the Developer's Guide and the Layout example shows it in action.

    Travis