I have three items that I want to update more frequently than once a minute. They are :-
The Secondhand (once a second)
A Steps counter (once every 2 seconds and only when it changes - next to 9 o'clock)
A Heart Rate display (once every 15 seconds and only when it changes - next to 3 o'clock)
My understanding of the processing logic is that there are, essentially, two canvases, one which is the watchface itself and which is updated once per minute by onUpdate() and the other, which is a clipped portion of the watchface canvas and which is updated each second. The clips are additive with the whole clip as defined at that point being updated each second. Any data written outside of the current clipped area is just ignored.
I want to be able to show the items as described above but in the order:-
Steps counter and Heart Rate
Hour & Minute hands
Central boss and secondhand
so that, effectively the minute and hour hands sit over the counters but under the secondhand.
The problem I'm having is that the Steps and heart rate counters are only being written to the clip canvas which is active at that second. In between times they are blank although they do appear as the secondhand's clip area passes over each counter. I can solve the problem by creating all three clips every second but that will give an even greater hit to average power consumed.
Here is my onPartialUpdate() code (note that min/hourPolyPoints are calculated in onUpdate())
function onPartialUpdate( dc ) { // If we're not doing a full screen refresh we need to re-draw the background // before drawing the updated second hand position. Note this will only re-draw // the background in the area specified by the previously computed clipping region. if(!fullScreenRefresh) { drawBackground(dc); } //---------- Initialise all variables ----------------- var width = dc.getWidth(); var height = dc.getHeight(); var clockTime = System.getClockTime(); var newHR = Activity.getActivityInfo().currentHeartRate; var newSteps = ActivityMonitor.getInfo().steps; //------- Calculate all necessary clipping areas ---------- //---------- Next is Heart Rate are we updating it? ---------------- if (null != newHR && newHR != HR && clockTime.sec % 10 == 0) { dc.setClip(width*0.75-(HRDims[0]/2),height*0.4,HRDims[0],HRDims[1]); dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_TRANSPARENT); // probably redundent // dc.clear(); HR = newHR; dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_TRANSPARENT); dc.drawText(width*0.75,height*0.4, Graphics.FONT_TINY, HR.toString(), Graphics.TEXT_JUSTIFY_CENTER); } //----------- Finally check to see if we are updating Steps --------- if (newSteps > Steps && clockTime.sec % 2 == 0) { dc.setClip(width*0.25-(StepsDims[0]/2),height*0.4,StepsDims[0],StepsDims[1]); dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_BLACK); dc.clear(); Steps = newSteps; dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_TRANSPARENT); dc.drawText(width*0.25, height*0.4, Graphics.FONT_TINY, Steps.toString(), Graphics.TEXT_JUSTIFY_CENTER); } //------- First off is the secondhand which is required every second ---------- var secondHand = (clockTime.sec / 60.0) * Math.PI * 2; var secondHandPoints = generateHandCoordinates(screenCenterPoint, secondHand, 90, 20, 2); curClip = getBoundingBox( secondHandPoints ); var bboxWidth = curClip[1][0] - curClip[0][0] + 1; var bboxHeight = curClip[1][1] - curClip[0][1] + 1; dc.setClip(curClip[0][0], curClip[0][1], bboxWidth, bboxHeight); //----------- Having established the full clipping area, now clear it to Black ----- dc.setColor(Graphics.COLOR_TRANSPARENT, Graphics.COLOR_TRANSPARENT); dc.clear(); //----------- Now redraw the entire clipping area ------------ dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_TRANSPARENT); //----------- Heart Rate ---------- dc.drawText(width*0.75,height*0.4, Graphics.FONT_TINY, HR.toString(), Graphics.TEXT_JUSTIFY_CENTER); //----------- Steps ------------ dc.drawText(width*0.25, height*0.4, Graphics.FONT_TINY, Steps.toString(), Graphics.TEXT_JUSTIFY_CENTER); //----------- Hour and Minute hands ---------------- dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT); dc.fillPolygon(hourPolyPoints); dc.fillPolygon(minPolyPoints); //----------- The central boss (arbor) ---------------- dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT); dc.fillCircle(width / 2, height / 2, 7); dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_TRANSPARENT); dc.drawCircle(width / 2, height / 2, 7); //----------- and, finally, the secondhand ---------------- dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT); dc.fillPolygon(secondHandPoints); }
In essence, how can I get an item written to a previous clip continue to be displayed on the watchface canvas?