Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Toybox.System;
- using Toybox.Application;
- using Toybox.Graphics;
- using Toybox.WatchUi;
- //////////////////////////////////////////////////////////////////////////
- class StaticContentApp extends Application.AppBase
- {
- function initialize() { AppBase.initialize(); }
- function getInitialView() { return [ new MyView() ]; }
- }
- /////////////////////////////////////////////////////////////////////////
- class MyView extends WatchUi.DataField
- {
- hidden var paintScreen = true; // start with screen painting
- hidden var width, height;
- function initialize() { DataField.initialize(); }
- function compute(dc) { }
- function onLayout(dc) { width = dc.getWidth(); height = dc.getHeight(); }
- function onShow() { paintScreen = true; return true; } // repaint the static screen content in onUpdate
- function onUpdate(dc) {
- // paint the static content once, don't waste compute cycles doing this every second
- if (paintScreen) {
- dc.setColor(Graphics.COLOR_YELLOW,Graphics.COLOR_TRANSPARENT);
- dc.fillRoundedRectangle(20, 20, width -40, height - 40, 15);
- }
- // write dynamic content to screen - update every second
- dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_TRANSPARENT);
- dc.drawText(width * 0.5, 40, Graphics.FONT_LARGE, System.getTimer(), Graphics.TEXT_JUSTIFY_CENTER);
- paintScreen = false; // don't recreate static content until onShow runs again
- return true; // tell parent we've handled onUpdate
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment