From 13265d1b015346c99f26deefc6011d14d97e5e35 Mon Sep 17 00:00:00 2001 From: Michael Prager Date: Tue, 29 Mar 2011 17:33:44 +0200 Subject: [PATCH] - improve startup performance by calling init() in - improved battery life by not updating data when checking for screen rotation every 1 sec - fixed onShow not working properly (was window.widget.onshow instead of window.onshow) - added new function handleOnShow() which will call updateScreen() and check if displayed data needs to be updated. updateScreen() will no longer update data itself. --- comingNext/index.html | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/comingNext/index.html b/comingNext/index.html index 145ac24..19789fd 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -123,17 +123,13 @@ var entryFields = [ "InstanceEndTime" ]; -window.onload = init; -window.onresize = updateScreen; -window.onshow = updateScreen; - function isLeapYear( year ) { if (( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 ) return true; else return false; } - + function calcLeapYear(year, days) { if (isLeapYear(year)) @@ -816,8 +812,11 @@ function updateData() } } +// called by handleOnShow() and onResize events function updateScreen() { + log('updateScreen()'); + // check if opening fullscreen if( window.innerHeight > 91 && mode == 0) { mode = 1; @@ -832,10 +831,15 @@ function updateScreen() } if (mode == 0) - updateHomescreen(); + updateHomescreen(); // check for screen rotation else if (mode == 1) updateFullscreen(); - +} + +function handleOnShow() +{ + updateScreen(); + var time = new Date(); if (time.getTime() - lastUpdateTime.getTime() > config['updateDataInterval'].Value * 60 * 1000) { log('updateScreen(): force updateData() because last update was too long ago (' + (time.getTime() - lastUpdateTime.getTime()) / 1000 + 's)'); @@ -890,10 +894,21 @@ function init() updateScreen(); if (config['useBackgroundImage'].Value) // check for screen rotation every 1 secs - screenRotationTimer = window.setInterval('updateScreen()', 1000 * 1); + screenRotationTimer = window.setInterval('checkOrientation()', 1000 * 1); + + // call updateScreen() when widget changes from background to forground + window.widget.onshow = handleOnShow; + log("init(): finished..."); } +function checkOrientation() +{ + //updateScreen(); + if (mode == 0) + updateHomescreen(); // check for screen rotation +} + function setUpdateTimer() { updateTimer = window.setInterval('updateTimerCallback()', 1000 * 60 * config['updateDataInterval'].Value); @@ -1550,7 +1565,7 @@ hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; borde - +
-- 2.39.2