dmrrlc
dmrrlc

Reputation: 201

How to check if the watch is round or square

Is there a possibility from the connectIQ API to check if the watch is round or square?

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

Upvotes: 3

Views: 875

Answers (3)

user3053231
user3053231

Reputation:

The class Toybox::System::DeviceSettings has the method screenShape().

With the following possible return values:

  • SCREEN_SHAPE_ROUND = 1
  • SCREEN_SHAPE_SEMI_ROUND = 2
  • SCREEN_SHAPE_RECTANGLE = 3

Upvotes: 4

Connect IQ
Connect IQ

Reputation: 81

It is possible to use the resource compiler to specify resources for different screen geometry. This can be leveraged to identify on which device an app is running.

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).

Next, create a string resource in the resources.xml file within each devices' resource directory 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, do a simple check to get the device on which the app is running:

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

Then, check the deviceType whenever if you need to do something unique for a particular device:

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

You could abstract this a little if you prefer, buy using more generic deviceTypes like 'round', 'square', etc., so you wouldn't have to write logic to handle every unique device model.

Upvotes: 2

Perttu Haliseva
Perttu Haliseva

Reputation: 977

There doesn't seem to be a direct function but you can always check for watch face's width and height:

dc.getWidth(), dc.getHeight()

If they're equal, say, 218px, you have a Fenix 3 and obviously a round face. If they're 205px x 148px, you're dealing with a square-faced vívoactive.

Maybe write a function you can call from onLayout:

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

Upvotes: 1

Related Questions