Advertisement
Guest User

Untitled

a guest
Oct 1st, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. import Toybox.Graphics;
  2. import Toybox.Lang;
  3. import Toybox.System;
  4. import Toybox.WatchUi;
  5. using Toybox.ActivityMonitor as Act;
  6. using Toybox.Activity as Acty;
  7. using Toybox.Time.Gregorian;
  8.  
  9. class DigitalElegantView extends WatchUi.WatchFace {
  10.  
  11. var BG;
  12. function initialize() {
  13. WatchFace.initialize();
  14. BG=WatchUi.loadResource(Rez.Drawables.BG);
  15. }
  16.  
  17. var customFont = null;
  18. var dateFont = null;
  19. var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
  20. var dateString = Lang.format(
  21. "$1$ $2$ $3$",
  22. [
  23. today.day_of_week,
  24. today.month,
  25. today.day,
  26.  
  27. ]
  28. );
  29.  
  30.  
  31. // Load your resources here
  32. function onLayout(dc as Dc) as Void {
  33. setLayout(Rez.Layouts.WatchFace(dc));
  34. customFont = WatchUi.loadResource(Rez.Fonts.customFont);
  35. dateFont = WatchUi.loadResource(Rez.Fonts.dateFont);
  36. }
  37. // Called when this View is brought to the foreground. Restore
  38. // the state of this View and prepare it to be shown. This includes
  39. // loading resources into memory.
  40. function onShow() as Void {}
  41.  
  42. // Update the view
  43. function onUpdate(dc as Dc) as Void {
  44. dc.clear();
  45. var clockTime = System.getClockTime();
  46. var hour = clockTime.hour;
  47. if (!System.getDeviceSettings().is24Hour) {
  48. hour = hour % 12;
  49. if (hour == 0) {
  50. hour = 12;
  51. }
  52.  
  53. }
  54.  
  55. dc.drawBitmap(0, 0, BG);
  56.  
  57. if (Act has: getHeartRateHistory) {
  58. var heartRate = Activity.getActivityInfo().currentHeartRate;
  59. if (heartRate == null) {
  60. var HRH = Act.getHeartRateHistory(1, true);
  61. var HRS = HRH.next();
  62. if (HRS != null && HRS.heartRate != Act.INVALID_HR_SAMPLE) {
  63. heartRate = HRS.heartRate;
  64. }
  65. }
  66. if (heartRate != null) {
  67. heartRate = heartRate.toString();
  68. } else {
  69. heartRate = "--";
  70. }
  71. }
  72. // Get and show the current time
  73. dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT);
  74. dc.drawText(dc.getWidth() / 2.1, 175, customFont, hour.toString(), Graphics.TEXT_JUSTIFY_RIGHT);
  75. dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
  76. dc.drawText(dc.getWidth() / 2.1, 175, customFont, ":" + Lang.format("$1$", [clockTime.min.format("%02d")]), Graphics.TEXT_JUSTIFY_LEFT);
  77. dc.drawText(dc.getWidth() / 2, 104, dateFont, dateString, Graphics.TEXT_JUSTIFY_CENTER);
  78. }
  79. // Called when this View is removed from the screen. Save the
  80. // state of this View here. This includes freeing resources from
  81. // memory.
  82. }
  83.  
  84. function onHide() as Void {}
  85.  
  86. // The user has just looked at their watch. Timers and animations may be started here.
  87. function onExitSleep() as Void {}
  88.  
  89. // Terminate any active timers and prepare for slow updates.
  90. function onEnterSleep() as Void {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement