Dear Garmin Developers,
I am working on a new watch face and I would like to implement always on seconds by using onPartialUpdate(). I implemented the code so far, but for some reason, the seconds freeze after two minutes. Can someone help? Heres the code:
using Toybox.WatchUi;
using Toybox.Graphics;
using Toybox.System;
using Toybox.Lang;
using Toybox.Application;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
class OneHerzTestView extends WatchUi.WatchFace {
function initialize() {
WatchFace.initialize();
}
// Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.WatchFace(dc));
}
// 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
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("TimeLabel");
view.setColor(Application.getApp().getProperty("ForegroundColor"));
view.setText(timeString);
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
DoSeconds(dc);
}
function onPartialUpdate(dc) {
DoSeconds(dc);
}
function DoSeconds(dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.fillRectangle(160, 110,35,20);
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
dc.drawText(160, 120,0,":"+Sys.getClockTime().sec.format("%02d"), 2 | 4);
}
// 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() {
}
}
Thanks a lot.
Greetings,
GreanBean.