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
  • 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 :)


    Oh sorry, maybe I misunderstood you. You did say "ever being true", making me think the bt was always showing on your watch and you wanted it to disappear. But I guess you meant "never" :)

    For some watches both BT on phone needs to be on and GM on phone needs to be open and running. Can be backgrounded but not killed/closed.

    What phone do you use and what watch do you have? Give us some versions etc.
  • Former Member
    Former Member over 9 years ago
    I have the new FR235 and I am using an iPhone 6S+ with latest iOS.

    The code is in a watch face, and in the onUpdate() method, does:
    var ds = Sys.getDeviceSettings();
    if ( hasPhoneConnected == true && ds.phoneConnected == true ) {
    dc.drawBitmap( 3, 80, Ui.loadResource( Rez.Drawables.icon ) );
    }


    hasPhoneConnected is set in initialize(), thusly:
    var hasPhoneConnected = false;

    function initialize() {

    WatchFace.initialize();

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


    I install the watch face on the watch (Build for device...), kill GC on my phone, then restart it. When I restart GC I see it do a successful sync with the watch. I leave the watch and phone next to each other for several minutes, the icon never displays. If I change the condition above to == false, the icon displays and does not go away. So phoneConnected is always false.

    In the Bluetooth settings on the watch, it reports that it is connected to the phone (as evidenced by the sync, in any case).

    This all works great in the simulator, I can toggle Settings->Phone Connected back and forth and a minute later the face updates appropriately.

    Pretty stumped at this point.

    Thanks,
    Ron
  • That's weird.

    I just tried this

    has :phoneConnected

    on my physical 230 and it works great.

    Maybe if you care to share more code I could take a further look? Trimmed down version of your project could help.
    Perhaps also make sure that there is no problem with the actual icon?

    If file format is not correct you may get unexpected results.

    I once had issues with bitmap not displaying, only to realise that I saved the image in photoshop as a photoshop (psd) formatted file with a png extension.
  • Former Member
    Former Member over 9 years ago
    Thanks for the reply -- if I take the if statement out the icon displays perfectly, and stays displaying perpetually, even on the hardware. Do you still think there might be a problem?

    As for the code, I've put all relevant pieces in here. It's really quite a simple face (see Step Light in the Garmin store). I have nothing in onShow or onHide, only using onUpdate and initialize(). The code to test phoneConnected comes right after I call View.onUpdate(dc) in my onUpdate() call, and are the last lines of code in onUpdate().

    Thanks,
    Ron
  • Thanks for the reply -- if I take the if statement out the icon displays perfectly, and stays displaying perpetually, even on the hardware. Do you still think there might be a problem?

    As for the code, I've put all relevant pieces in here. It's really quite a simple face (see Step Light in the Garmin store). I have nothing in onShow or onHide, only using onUpdate and initialize(). The code to test phoneConnected comes right after I call View.onUpdate(dc) in my onUpdate() call, and are the last lines of code in onUpdate().

    Thanks,
    Ron


    I wanted to suggest you removing the has check and see what happens.

    It is weird and also hard to believe that there could be a bug with the 235 (as discovered by you) but not with the 230 (as tested by me).

    But who knows. Brandon will surely log this for investigation.
  • Former Member
    Former Member over 9 years ago
    Thanks -- I think I had removed the 'has' at some point, but I did it again just now and sadly no change.

    Happy to send Brandon or anyone from Garmin my full source code if that helps.

    Thanks again,
    Ron
  • Thanks -- I think I had removed the 'has' at some point, but I did it again just now and sadly no change.

    Happy to send Brandon or anyone from Garmin my full source code if that helps.

    Thanks again,
    Ron


    No problem, you are welcome.
  • Try this watchface on your 235 and see if you get the BT icon.

    It uses "has" for phoneConnected, and works fine on a 230.

    Make sure that within Garmin Connect Mobile it's got a "connected" state for the watch, and like all watchfaces, usually only updates every minute, so give it time.

    https://apps.garmin.com/en-US/apps/3d8dd9a3-a90c-45b0-8170-043161dfc26f
  • Former Member
    Former Member over 9 years ago
    Fantastic idea. I installed the face you linked and the Better Original watch face, both of which show BT status icons.

    I was able to sync the faces to my watch and make them active. Neither display a BT icon with the Garmin Connect app on the phone in the foreground.

    Perhaps I should un-pair my watch and repair it. This is really strange.

    Thanks,
    Ron
  • Fantastic idea. I installed the face you linked and the Better Original watch face, both of which show BT status icons.

    I was able to sync the faces to my watch and make them active. Neither display a BT icon with the Garmin Connect app on the phone in the foreground.

    Perhaps I should un-pair my watch and repair it. This is really strange.

    Thanks,
    Ron


    The one I linked to uses "has" for phoneConnected. I don't know about the other one. In Garmin Connect Mobile, not only is GCM open, but when you go to "Garmin Devices" does it show that your 235 is connected? You don't have the 235 paired BT wise in your phone's setting, but only in GCM, correct?