How to check if a clock is round or square

Is it possible from the connectIQ API to check if the clock is round or square?

My app draws a progress bar for a timer and I could make it generic if I can find a way to tell if the screen is round or square

+3


source to share


3 answers


In a class: Toybox::System::DeviceSettings

is a method screenShape()

that looks like what you want.



+3


source


There seems to be no direct function, but you can always check the width and height of the face:

dc.getWidth(), dc.getHeight()

      

If they are equal, say 218px, you have a Fenix ​​3 and obviously a round face. If they are 205px x 148px, you are dealing with a vivvoactive with a square layout.



Maybe write a function that you can call from onLayout:

function isRoundFace (dc) {
    return dc.getWidth() == dc.getHeight();
}

      

+2


source


You can use the resource compiler to specify resources for different screen geometries. This can be used to determine which device the application is running on.

In your project, specify a unique set of resources (which includes things like strings, images, and menus) for each device you intend to support by creating device-specific directories in the root of the project (e.g. resources-vivoactive or resources- fenix3).

Then create a string resource in the resources.xml file in the resource directory of each device that specifies the device type:

<resources>
    <bitmap id="LauncherIcon" filename="images/launcher_icon.png" />
    <string id="AppName">MyApp</string>
    <string id="deviceType">vivoactive</string>
</resources>

      

When the app starts up, do a simple check to get the device the app is running on:

function onStart() {
    deviceType = Ui.loadResource(Rez.Strings.deviceType);
}

      

Then check the device type every time you need to do something unique for a specific device:

function drawProgressBar() {
    if (deviceType.equals("vivoactive")) {
        // Do vivoactive-specific stuff here
        ...
    }
}

      

You can take this a bit if you want to buy using more generic device types like "round", "square", etc., so you don't have to write logic to handle each unique device model.

+2


source







All Articles