Recognize the device

I have a maybe silly question:

Some devices have the same screen resolution (e.g. Edge 530 and Edge 540) but are different to handle because of different fontsizes.

I do it by testing a teststring length by pixel to check which device it is. That works but I wonder:
is there no other possibility to ask which device it is?
All I found is DeviceSettings.partNumber, but that returns a string which (at first sight) has nothing to do with the device name.

  • While partNumber can be used, it's something you need to maintained and you also get into cases where there are multiple part numbers for WW and APAC versions of the devices.  The part numbers for a devices can be found in the compiler.json file for a device.

    You can also load your own string for the device my using jungles, but again, maybe a bit of maintenance..

    I tend to use width, height, and the height of one of the fonts I use and figure out things at runtime

  • Ok, thanks for confirmation!

  • Another workaround is defining device-specific properties via strings.xml for some exceptional devices. Let's say, for 540 Edge you need to create file "resources-edge540/strings/strings.xml" file and define there a string property for your font size:

    <strings>
        <!-- FONT_MEDIUM -->
        <string id="topBarFontIndex">3</string>
    </strings>

    For other non-specific devices define the default property value in the "resources/strings/strings.xml" file:

    <strings>
        <!-- FONT_SMALL -->
        <string id="topBarFontIndex">2</string>
    </strings>

    Then in your code do

    _topBarFont = Application.loadResource(Rez.Strings.topBarFontIndex).toNumber() as FontType;

    Hence, you will get different fonts in runtime based on concrete device model.

  • Thank you very much for your contribution!

    My problem was to find out which device of the compiled package the user is using. For devices with the same screen size, you can't distinguish just by screen height and width. Jim does it by checking the font height and I do it by checking the pixel length of a test string for always the same font.

    This worked for all my data fields - until yesterday, when I noticed that the length of the test string in the simulation is completely different than on the real device: 64 to 57. So I asked....

  • Which device?  On the f7s. I found the height of FONT_NUMBER_MEDIUM was 68 in the sim while on a real f7s. it was 67

    Are all your device files for the sim current?

  • Yeah, this is eternal Garmin's problem that sim font characteristics never match a real device. The workaround with string properties helps to hardcode any property for a specific device model. If your switch logic is more complicated than just checking one property then you can even directly hardcode the device model in strings and do everything else in Monkey-C code:

    <strings>
        <string id="deviceModel">edge-540</string>
    </strings>

    var deviceModel = Application.loadResource(Rez.Strings.deviceModel);
    switch(deviceModel) {
    case "edge-540":
    ...
    case "fenix-7"
    ...
    default:
    ...
    }
  • Have you tested this case statement?  I'm not sure if that works with strings (a case/switchactually gets compiled as if statements. and

    if(deviceModel=="edge-540") {}

    is much different than

    if(deviceModel.equals("edge-540")) {}

  • For Java, the string-switch works in the following way:


    The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using the String.equals method; consequently, the comparison of String objects in switch statements is case sensitive. The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.

    I believe, for Monkey C it works in the same way but I haven't tested that since this is just a pseudo-code to show the general idea.

  • This isn't java or python, where you can do

    if(str="aBc")

    in both. I happen do be doing a bunch of Java and python right now. In Monkey C, to compare strings you need to use equal().  Kind of like of like C where you use something like strcmp()

  • I believe Monkey C designers were not so poor at making string comparisons in the switch by reference, not by actual value. With comparison by reference, it has pretty much no sense.

    So, I believe, the string switch in Monkey C works the same way as in most of OOP languages, exactly like 

    if(deviceModel.equals("edge-540")) {}

    But, anyway, the main question was about getting the device model in runtime, not about if-else vs switch.