Help with Bitmap Watchface + Digital Display (or Analog Display)

Hi!

I am trying to create a simple watch face. A simple picture plus showing the time. I would prefer analog, but having a digital format as well will be ideal for diversity.

The bitmap seems to be an issue when I try to run the app.

This is the notification it provides:

Error: Unexpected Type Error

Details: Failed invoking <symbol>

Stack: 

  - onUpdate() at /Users/ramirezla/eclipse-workspace/RUTA/source/RUTAView.mc:51 0x10000191 

Can someone help shed some light on this?

The View.mc file: 

using Toybox.WatchUi;

using Toybox.Graphics;

using Toybox.System;

using Toybox.Lang;

using Toybox.Application;

class TestView extends WatchUi.WatchFace {

    var bitmap;

    function initialize() {

        WatchFace.initialize();

    }

    // Load your resources here

    function onLayout(dc) {

        bitmap = WatchUi.loadResource(Rez.Drawables.TestView);

    }

    // Called when this View is brought to the foreground. Restore

    // the state of this View and prepare it to be shown. This includes

    // loading resources into memory.

    function onShow() {

    }

    // Update the view

    function onUpdate(dc) {

        // Get the current time and format it correctly

        

        dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);

        dc.clear();

        dc.drawBitmap(50, 50, bitmap);

        

        var timeFormat = "$1$:$2$";

        var clockTime = System.getClockTime();

        var hours = clockTime.hour;

        if (!System.getDeviceSettings().is24Hour) {

            if (hours > 12) {

                hours = hours - 12;

            }

        } else {

            if (Application.getApp().getProperty("UseMilitaryFormat")) {

                timeFormat = "$1$$2$";

                hours = hours.format("%02d");

            }

        }

        var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);

        // Update the view

        var view = View.findDrawableById("TimeLavel");

        view.setColor(Application.getApp().getProperty("ForegroundColor"));

        view.setText(timeString);

        // Call the parent onUpdate function to redraw the layout

        View.onUpdate(dc);

    }

    // Called when this View is removed from the screen. Save the

    // state of this View here. This includes freeing resources from

    // memory.

    function onHide() {

    }

    // The user has just looked at their watch. Timers and animations may be started here.

    function onExitSleep() {

    }

    // Terminate any active timers and prepare for slow updates.

    function onEnterSleep() {

    }

}

  • When you do the view.onUpdate(), it displays the layout after clearing the screen, so the bitmap is lost.

    What you want to do is remove all reference to the layout, and just use dc,drawText() to display the time, or make the bitback the background in the layout.

  • I have unsuccessfully tried to update based on your suggestion. I may be doing incorrectly?

    - I have removed the view.onUpdate() reference.

    - When you say remove all reference to the layout, I also deleted

            // Call the parent onUpdate function to redraw the layout

            View.onUpdate(dc);

    - I have shifted this around all throughout the code to see if it works, but I still get the error...

            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);

            dc.clear();

            dc.drawBitmap(50, 50, bitmap);

    - I continue to get this error:

    Error: Unexpected Type Error

    Details: Failed invoking <symbol>

    Stack: 

      - onUpdate() at /Users/ramirezla/eclipse-workspace/RUTA/source/RUTAView.mc:47 0x10000143 

  • what is line 47?  I suspect it's the drawBitmap.

    are you sure the bitmap variable you set is the bitmap, and not something like a new local variable?

  • Line 47 is:         var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);

    Line  32 is:        dc.drawBitmap(50, 50, bitmap);

    Re: the variable... not sure really. I started with a ConnectIQ template provided by Garmin help desk. They had that same bitmap on line 30, but did not include a way to show the time in digital or analog.

    That is my hangup. I can display the bitmap picture alone, but no time is displayed.

  • So what is "timeFormat"?  The error is on line 47 per the stack trace.

  • line 34 and 43 as 

           var timeFormat = "$1$:$2$";

  • Put a System.println right before what's now line 47 and display all the values you are using.  There's something there that's causing the crash per the stack trace.

  • So I managed to figure out (I hope) how to use the system.printin. (Now sure if am missing any value)

    Line 48 now has        System.println("TimeLabel");

    But an error came back with the following:

    --------

    TimeLabel

    Error: Unexpected Type Error

    Details: Failed invoking <symbol>

    Stack: 

      - onUpdate() at /Users/ramirezla/eclipse-workspace/RUTA/source/RUTAView.mc:54 0x100001a6 

    Line 54 has         view.setColor(Application.getApp().getProperty("ForegroundColor"));

  • If you're no longer using a layout, you don't want that on line 54.

    You want to use dc.setColor()

  • re: layout, yes...I am still in need to use the picture (bitmap). 

    I tried using the dc.setColor() on line 54 but still have that same error message.

    Error Message

    TimeLabel

    Error: Unexpected Type Error

    Details: Failed invoking <symbol>

    Stack: 

      - onUpdate() at /Users/ramirezla/eclipse-workspace/RUTA/source/RUTAView.mc:54 0x100001a6 

    -------

    I also tried using "UseMilitaryFormat" from line42 on line 54...but it did not work. 

    42            if (Application.getApp().getProperty("UseMilitaryFormat")) {

    43                timeFormat = "$1$$2$";

    44               hours = hours.format("%02d");

    45            }

    46        }

    47        

    48        System.println("TimeLabel");       

    49        

    50           var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);

    51

    52        // Update the view

    53        var view = View.findDrawableById("TimeLabel");

    54        view.setColor(Application.getApp().getProperty("ForegroundColor"));

    55       view.setText(timeString);