dbrillha

Static Content

Dec 6th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Toybox.System;
  2. using Toybox.Application;
  3. using Toybox.Graphics;
  4. using Toybox.WatchUi;
  5.  
  6. //////////////////////////////////////////////////////////////////////////
  7. class StaticContentApp extends Application.AppBase
  8. {
  9.     function initialize() { AppBase.initialize(); }
  10.     function getInitialView() { return [ new MyView() ]; }
  11. }
  12.  
  13. /////////////////////////////////////////////////////////////////////////
  14. class MyView extends WatchUi.DataField
  15. {
  16.     hidden var paintScreen = true; // start with screen painting
  17.     hidden var width, height;
  18.  
  19.     function initialize() { DataField.initialize(); }
  20.     function compute(dc) { }
  21.     function onLayout(dc) { width = dc.getWidth(); height = dc.getHeight(); }
  22.  
  23.     function onShow() { paintScreen = true; return true; } // repaint the static screen content in onUpdate
  24.  
  25.     function onUpdate(dc) {
  26.  
  27.         // paint the static content once, don't waste compute cycles doing this every second
  28.         if (paintScreen) {
  29.             dc.setColor(Graphics.COLOR_YELLOW,Graphics.COLOR_TRANSPARENT);
  30.             dc.fillRoundedRectangle(20, 20, width -40, height - 40, 15);
  31.         }
  32.  
  33.         // write dynamic content to screen - update every second
  34.         dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_TRANSPARENT);
  35.         dc.drawText(width * 0.5, 40, Graphics.FONT_LARGE, System.getTimer(), Graphics.TEXT_JUSTIFY_CENTER);
  36.  
  37.         paintScreen = false; // don't recreate static content until onShow runs again
  38.         return true; // tell parent we've handled onUpdate
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment