Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Toybox.Graphics;
- import Toybox.Lang;
- import Toybox.System;
- import Toybox.WatchUi;
- using Toybox.ActivityMonitor as Act;
- using Toybox.Activity as Acty;
- using Toybox.Time.Gregorian;
- class DigitalElegantView extends WatchUi.WatchFace {
- var BG;
- function initialize() {
- WatchFace.initialize();
- BG=WatchUi.loadResource(Rez.Drawables.BG);
- }
- var customFont = null;
- var dateFont = null;
- var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
- var dateString = Lang.format(
- "$1$ $2$ $3$",
- [
- today.day_of_week,
- today.month,
- today.day,
- ]
- );
- // Load your resources here
- function onLayout(dc as Dc) as Void {
- setLayout(Rez.Layouts.WatchFace(dc));
- customFont = WatchUi.loadResource(Rez.Fonts.customFont);
- dateFont = WatchUi.loadResource(Rez.Fonts.dateFont);
- }
- // 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() as Void {}
- // Update the view
- function onUpdate(dc as Dc) as Void {
- dc.clear();
- var clockTime = System.getClockTime();
- var hour = clockTime.hour;
- if (!System.getDeviceSettings().is24Hour) {
- hour = hour % 12;
- if (hour == 0) {
- hour = 12;
- }
- }
- dc.drawBitmap(0, 0, BG);
- if (Act has: getHeartRateHistory) {
- 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 = "--";
- }
- }
- // Get and show the current time
- dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT);
- dc.drawText(dc.getWidth() / 2.1, 175, customFont, hour.toString(), Graphics.TEXT_JUSTIFY_RIGHT);
- dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
- dc.drawText(dc.getWidth() / 2.1, 175, customFont, ":" + Lang.format("$1$", [clockTime.min.format("%02d")]), Graphics.TEXT_JUSTIFY_LEFT);
- dc.drawText(dc.getWidth() / 2, 104, dateFont, dateString, Graphics.TEXT_JUSTIFY_CENTER);
- }
- // Called when this View is removed from the screen. Save the
- // state of this View here. This includes freeing resources from
- // memory.
- }
- function onHide() as Void {}
- // The user has just looked at their watch. Timers and animations may be started here.
- function onExitSleep() as Void {}
- // Terminate any active timers and prepare for slow updates.
- function onEnterSleep() as Void {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement