Class: Toybox::WatchUi::Bitmap

Former Member
Former Member
Hi Connectors,

I am looking for a bit of tutoring on implementing this class. Assuming I have defined:

In drawables.xml:
<drawables>
<bitmap id="BtRound" x="113" y="26" filename="../images/btRound.png" dithering="none" >
<palette disableTransparency="false">
<color>FFFFFF</color>
<color>0000FF</color>
</palette>
</bitmap>
</drawables>


And in my main code:
class MyView extends Ui.WatchFace {

hidden var btImage = null;

//! Constructor
function initialize() {
WatchFace.initialize();
btImage = new Rez.Drawables.BtRound();
}

//! Load your resources here
function onLayout(dc) {
}

function onShow() {
}

//! Update the view
function onUpdate(dc) {
btImage.draw(dc);
}

}


I see the following error, yet this is exactly how it is implemented in the SDK samples. The only difference is that I have defined my bitmap inside drawables.xml instead of in its own file.
Failed invoking <symbol>
UnexpectedTypeException: Expected Class definition, given Number
initialize in C:\Users\Jeff\_my_garmin_workspace\Circulos\source\CirculosView.mc:49
getInitialView in C:\Users\Jeff\_my_garmin_workspace\Circulos\source\CirculosApp.mc:23
Unhandled Exception
  • It looks like you're trying to copy the pattern used in the Drawables example. Here is the source (trimmed for brevity).

    class MyWatchView extends Ui.View {

    var train;

    function initialize() {
    train = new Rez.Drawables.train();
    }

    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_BLUE, Gfx.COLOR_BLACK);
    dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight());
    train.draw(dc);
    }
    }


    In this sample Rez.Drawables.train() is a drawable-list element defined in resources/drawables/train.xml. In your example, Rez.Drawables.BtRound is a resource identifier.

    If you are trying to draw a bitmap, defined as you have, you should look to one of the other examples (the C64Face example is pretty simple).

    Travis
  • Additionally, I don't believe you can have x and y attributes on a bitmap. You should probably read over the programmers guide ({SDKROOT}\ProgrammersGuide.html) to be sure what you're doing is legal.
  • Former Member
    Former Member over 9 years ago
    Thanks Travis,

    This all makes sense; I can work with it. I do have a follow up question:

    Is there a standard recipe that dictates which resources should be defined in which XML files? Some are obvious such as fonts and settings but others, such as bitmaps, I have seen in more than one flavor of XML. For example, in the C64 sample <bitmap id="id_c64" filename="images/logo.png"/> is defined in resources/resources.xml but I wrote a watch face where I have defined .PNG files inside resources/drawables/drawables.xml with no ill effects.

    Thanks again,
    Jeff
  • Former Member
    Former Member over 9 years ago
    To add to my confusion, take a look ad this example from the SDK Programmer's Guide

    <resources>
    <bitmap id="bitmap_id" filename="path/for/image" />
    <font id="font_id" filename="path/to/fnt" />
    <string id="string_id">Hello World!</string>
    </resources>


    You see three different classes of resource all defined under one XML tag. Again, I have successfully written, compiled and run watch faces where I have defined these types of resource in many different places (resources/drawables/drawables.xml, resources/fonts/fonts.xml, resources/strings/strings.xml respectively).
  • Former Member
    Former Member over 9 years ago
    Sorry for the spam but I found another discrepancy in the C64 example:

    From resources/resources.xml:
    <resources>
    <bitmaps>
    <bitmap id="id_c64" filename="images/logo.png"/>
    </bitmaps>
    <fonts>
    <font id="id_font_c64" filename="fonts/commodore.fnt" filter="READY0123456789:." />
    </fonts>
    </resources>


    And from resources/bitmaps.xml:
    <resources>
    <bitmap id="LauncherIcon" filename="images/icon.png" />
    </resources>


    Why, in this example, are the .PNG resources defined in two different places? Seems like a disorganized manner with which to define resources. In other words, it is not tidy.
  • It doesn't matter which resource file you define them in. If you want it all in one file, you can do that. The reason you'd typically split it up is to support multiple languages or device profiles.

    For instance, to support multiple languages, you may create resources/strings.xml for all string resources in your primary language. When you get around to supporting German and French, you'd create resources-deu/strings.xml and resources-fre/strings.xml respectively.

    If you want to support multiple device profiles, you may put all of your bitmaps into resources/bitmaps and create resources/bitmaps.xml to reference all bitmap resources on your primary device (the one you initially create the app on). When you add support for the fenix3 and fr920xt, you'd create resources-fenix3 and resources-fr920xt folders with appropriately sized bitmaps for those devices, and resources-fenix3/bitmaps.xml and resources-fr920xt/bitmaps.xml to reference those images.

    Again, this is all covered in the programmer's guide.
  • Former Member
    Former Member over 9 years ago
    Thanks Travis. Food for thought. I am good for now.