Drawing a drawable

Former Member
Former Member
For my watch face, I have a file, BlueTooth.xml in the resources/drawables folder of my project. It contains the following:

<drawables>
<bitmap id="icon" x="25" y="125" filename="../../bitmaps/bt.png" />
</drawables>


I have tried many ways to load and draw this icon, and I've not found anything that works. The code I think should load and draw it is:

var bticn = Rez.BlueTooth.icon();
bticn.draw( dc );


I've also tried:

var bticn = Rez.Drawables.icon();
bticn.draw( dc );


I get various runtime errors about expecting a Method but an Object being given, etc.

Can anyone suggest the proper way to load and display a bitmap at runtime, conditionally? I have no problem getting it to draw as part of a layout, but I really need to determine at runtime whether to display it.

Thanks for any and all suggestions.
Ron
  • This is covered in the programmers guide and in several of the sample programs.
  • Former Member
    Former Member over 9 years ago
    This is covered in the programmers guide and in several of the sample programs.


    I should have mentioned that of course I've read the docs -- I've tried everything listed there and it does not work. Completely possible that I've messed something up, but I've stared at those docs for a long time trying to figure out where I am going wrong.

    Thanks,
    Ron
  • I should have mentioned that of course I've read the docs -- I've tried everything listed there and it does not work. Completely possible that I've messed something up, but I've stared at those docs for a long time trying to figure out where I am going wrong.

    Thanks,
    Ron


    Try something like:

    Ui.loadResource( Rez.Drawables.icon ).draw( dc );

    or
    dc.drawBitmap(x,y, Ui.loadResource( Rez.Drawables.icon ));
  • I've tried everything listed there and it does not work.


    Ron,

    It is covered in the second paragraph of the second section (The Resource Module) of the programmer's guide that I linked you to above...

    The code can use the Rez class to reference the resources at run time. For example, let&#8217;s say you have a bitmap you want to use in your view. Before it can be used by the app, it must be loaded from the resource file...

    image = Ui.loadResource( Rez.Drawables.id_monkey );


    Now the bitmap can be drawn in the update handler:

    dc.drawBitmap( 50, 50, image );



    Additionally, the C64Face, MO2Display, and Primates sample programs all demonstrate how to do this.
  • The issue is that Rez.Drawables.icon is just a symbol, it is not a drawable. You need to create a Ui.Bitmap from that, then you will have a drawable. Once you know this, the documentation for Ui.Bitmap should get you where you need to go (if you really want a drawable).

    var drawable = new Ui.Bitmap({
    :rezId => Rez.Drawables.icon,
    :locX => 5,
    :locY => 5
    });

    // then somewhere else...
    drawable.draw(dc);
  • Former Member
    Former Member over 9 years ago
    W howard st

    Thanks to everyone for their thoughtful and detailed responses, I really appreciate it. I ended up going with:

    var ds = Sys.getDeviceSettings();
    if ( ds has :phoneConnected ) {

    if ( ds.phoneConnected == true ) {
    dc.drawBitmap( 3,80, Ui.loadResource( Rez.Drawables.icon ) );
    }
    }


    However, it's important to note that if you're drawing in the onUpdate() call, and you're using layouts, the above code MUST come after:

    View.onUpdate( dc );


    As that wipes the screen and draws the layout. Took me a couple of minutes to figure that out.

    Now I am just having trouble with phoneConnected ever being true on my watch (works fine on the simulator), but I'll poke at that some more and post in a different thread if I can't figure it out.

    Thank you all again.
    Ron
  • However, it's important to note that if you're drawing in the onUpdate() call, and you're using layouts, the above code MUST come after

    Now I am just having trouble with phoneConnected ever being true on my watch (works fine on the simulator), but I'll poke at that some more and post in a different thread if I can't figure it out.

    Ron


    Correct, glad you could figure it out.

    No need to check for has : phoneConnected.
    It has always been present in all versions of SDK, and is a redundant check.

    I'm sure uou killed GCM on your phone and disabled the BT on your phone too?
  • Former Member
    Former Member over 9 years ago
    It has always been present in all versions of SDK, and is a redundant check.

    I'm sure uou killed GCM on your phone and disabled the BT on your phone too?


    Good to know on the redundant check.

    I've tried killing Garmin Connect on my phone for sure, and then start it again (other threads indicate it needs to be running), nothing.

    I am curious what you mean by "disabled BT on your phone" -- you mean to see the icon disappear? Because I can't even get it to show up :)

    Thanks,
    Ron
  • Actually, while "phoneConnected" has been in the SDK all along, it hasn't been on all devices. When I started with the vivoactive, phoneConnected worked fine in the simulator, but caused a hard crash of the vivoactive itself as the VM didn't handle it. (that was back in 2.50-2.60 FW days)

    I still have the "has" check in much of my stuff, but I do it only once during initialize() and set a boolean I use elsewhere, because I read that "has" was a fairy expensive call in CIQ, while checking a boolean isn't.
  • Actually, while "phoneConnected" has been in the SDK all along, it hasn't been on all devices. When I started with the vivoactive, phoneConnected worked fine in the simulator, but caused a hard crash of the vivoactive itself as the VM didn't handle it. (that was back in 2.50-2.60 FW days)

    I still have the "has" check in much of my stuff, but I do it only once during initialize() and set a boolean I use elsewhere, because I read that "has" was a fairy expensive call in CIQ, while checking a boolean isn't.



    Ah ok, I wasn't aware of this.
    But I'm sure it would be pretty safe now?