Hello everybody,
I try (because it's fun) to develop my first watchface. Unfortunately, all the topics, help and tutorials are in English so it's quite complicated following the bug I could have ...
After some days, I finalized an watchface working on ConnectIQ, but after transferred the app on my Forerunner 245, I found a mistake. It seems that the bitmap is not loaded and each time I change what I want to see (go to a menu, an app or whatever) then come back to the clock screen, the last screen stay in font. I don't really understand what it happens. Do you have an idea ?
Thank's for your help.
My code :
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.Lang as Lang;
using Toybox.Application as App;
using Toybox.Time.Gregorian as Date;
using Toybox.ActivityMonitor as Act;
using Toybox.Activity as Acty;
class WFView extends Ui.WatchFace {
var myBitmap;
function initialize() {
WatchFace.initialize();
myBitmap = Ui.loadResource(Rez.Drawables.fondWF);
}
function onLayout(dc) {
dc.clear();
setLayout(Rez.Layouts.WatchFace(dc));
}
function onShow() {
}
function onUpdate(dc) {
dc.clear();
View.onUpdate(dc);
dc.drawBitmap(0, 0, myBitmap);
// Function ClockDisplay
var clockTime = Sys.getClockTime();
var timeStringHour = Lang.format("$1$", [clockTime.hour]);
var timeStringMin = Lang.format("$1$", [clockTime.min.format("%02d")]);
dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT);
dc.drawText(120, 20, Gfx.FONT_SYSTEM_NUMBER_HOT, timeStringHour, Graphics.TEXT_JUSTIFY_CENTER );
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(120, 130, Gfx.FONT_SYSTEM_NUMBER_HOT, timeStringMin, Graphics.TEXT_JUSTIFY_CENTER );
// Function DateDisplay
var now = Time.now();
var date = Date.info(now, Time.FORMAT_LONG);
var dateString = Lang.format("$1$ $2$", [date.day, date.month]);
var dayString = Lang.format("$1$", [date.day_of_week]);
dc.setColor(Graphics.COLOR_DK_GRAY, Graphics.COLOR_TRANSPARENT);
dc.drawText(120, 0, Gfx.FONT_XTINY, dateString, Gfx.TEXT_JUSTIFY_CENTER );
dc.setColor(Graphics.COLOR_DK_GRAY, Graphics.COLOR_TRANSPARENT);
dc.drawText(120, 15, Gfx.FONT_XTINY, dayString, Gfx.TEXT_JUSTIFY_CENTER );
// continued ...
// ... continued
// Function BatteryDisplay
var batteryinfo = Sys.getSystemStats().battery;
var stats = Sys.getSystemStats();
var pwr = stats.battery;
var battery = Lang.format("$1$%",[pwr.format("%2d")]);
dc.setColor(Graphics.COLOR_DK_GRAY, Graphics.COLOR_TRANSPARENT);
dc.drawText(120, 220, Gfx.FONT_XTINY, battery, Gfx.TEXT_JUSTIFY_CENTER );
// Function StepCountDisplay
var stepCount = Act.getInfo().steps.toString();
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(40, 100, Gfx.FONT_XTINY, stepCount, Gfx.TEXT_JUSTIFY_CENTER );
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(40, 120, Gfx.FONT_XTINY, "Step", Gfx.TEXT_JUSTIFY_CENTER );
// continued ...
// ... continued
// Function HeartrateDisplay
var heartRate = Activity.getActivityInfo().currentHeartRate;
if(heartRate==null) {
var HRH=Act.getHeartRateHistory(1, true);
var HRS=HRH.next();
if(HRS!=null && HRS.heartRate!= Act.INVALID_HR_SAMPLE){
heartRate = HRS.heartRate;
}
}
if(heartRate!=null) {
heartRate = heartRate.toString();
}
else{
heartRate = "--";
}
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(200, 100, Gfx.FONT_XTINY, heartRate, Gfx.TEXT_JUSTIFY_CENTER );
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(200, 120, Gfx.FONT_XTINY, "Bpm", Gfx.TEXT_JUSTIFY_CENTER );
}
}