function onPartialUpdate(dc as Dc) as Void {
System.println("partial update!");
var clockTime = System.getClockTime();
var timeString2 = clockTime.sec.format("%02d");
var heartString=doHeartrate();
var info = System.getDeviceSettings();
doTime(dc,timeString2,heartString,info.phoneConnected,false);
}
function doTime(dc,time,hart,phone,isFull) {
//here is where real things happen.
//if it's a full update, just carry on, but if it's a partial, use setClip
if(!isFull) {
//set the clip so it's just the time. To keep it simple, I do the entire screen width
dc.setClip(130, 148, 100, 26);
dc.setColor(bgColor,bgColor);
//clear anything that might show through from the previous time
dc.clear();
}
dc.setColor(timeColor,Graphics.COLOR_TRANSPARENT);
dc.drawText(180,160,timeFont,time,Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
dc.drawText(130,160,hartFont,hart,Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
if (phone) {
dc.drawBitmap(210,150, BT);
}
//doing the clearClip() here doesn't work, so I did it in onUpdate()
//instead!
//dc.clearClip();
}
function initialize()内でWatchFaceDelegete.initialize()としてまず初期化し、function onPowerBudgetExceed(powerinfo)として関数を書いて、その中にコメントを記述します。powerinfo.executionTimeAverageは実際に1回のパーシャルアップデートの処理にかかった1分間の平均。powerinfo.executionTimeLimitがパーシャルアップデートの1回当たりの処理に許されている時間です。
ただ、これだけは動いてくれなくて、今まで何のためにあるのだろうと思っていたもう一つのファイルXXXXapp.mcを修正する必要があります。修正するのはこの中のgetInitialViewの部分です。デフォルトでは次のようになっているはずです。
function getInitialView() as Array<Views or InputDelegates>? {
return [ new XXXXView() ] as Array<Views or InputDelegates>;
}
これをサンプルプログラムに倣って次のように書き換えます。
function getInitialView() {
if( Toybox.WatchUi.WatchFace has :onPartialUpdate ) {
//Sys.println("del");
return [ new XXXXView(), new XXXXDelegate() ];
} else {
return [ new XXXXView() ];
}
}
function onPartialUpdate(dc as Dc) as Void {
System.println("partial update!");
var clockTime = System.getClockTime();
var timeString = Lang.format("$1$", [clockTime.sec.format("%02d")]);
var view = View.findDrawableById("TimeLabel2") as Text;
view.setText(timeString);
View.onUpdate(dc);
}
function onPartialUpdate(dc as Dc) as Void {
System.println("partial update!");
var clockTime = System.getClockTime();
var timeString = clockTime.sec.format("%02d");
dc.drawText(120,190,timeFont,timeString,Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
}
function doTime(dc,time,isFull) {
//here is where real things happen.
//if it's a full update, just carry on, but if it's a partial, use setClip
if(!isFull) {
var y=centerH-(timeHeight/2);
//set the clip so it's just the time. To keep it simple, I do the entire screen width
dc.setClip(0, y, width, timeHeight+1);
dc.setColor(bgColor,bgColor);
//clear anything that might show through from the previous time
dc.clear();
}
dc.setColor(timeColor,Gfx.COLOR_TRANSPARENT);
dc.drawText(centerW,centerH,timeFont,time,Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
//doing the clearClip() here doesn't work, so I did it in onUpdate()
//instead!
//dc.clearClip();
}
class partialupdateView extends WatchUi.WatchFace {
var timeFont;
var bgColor=Graphics.COLOR_BLACK;
var timeColor=Graphics.COLOR_WHITE;
function initialize() {
WatchFace.initialize();
}
// Load your resources here
function onLayout(dc as Dc) as Void {
setLayout(Rez.Layouts.WatchFace(dc));
timeFont=Graphics.FONT_LARGE;
}
// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() as Void {
}
// Update the view
function onUpdate(dc as Dc) as Void {
// Get and show the current time
System.println("full update!");
var clockTime = System.getClockTime();
var timeString = Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%02d")]);
var view = View.findDrawableById("TimeLabel") as Text;
var timeString2 = clockTime.sec.format("%02d");
view.setText(timeString);
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
doTime(dc,timeString2,true);
}
function onPartialUpdate(dc as Dc) as Void {
System.println("partial update!");
var clockTime = System.getClockTime();
var timeString = clockTime.sec.format("%02d");
doTime(dc,timeString,false);
}
function doTime(dc,time,isFull) {
//here is where real things happen.
//if it's a full update, just carry on, but if it's a partial, use setClip
if(!isFull) {
//set the clip so it's just the time. To keep it simple, I do the entire screen width
dc.setClip(185, 128, 30, 25);
dc.setColor(bgColor,bgColor);
//clear anything that might show through from the previous time
dc.clear();
}
dc.setColor(timeColor,Graphics.COLOR_TRANSPARENT);
dc.drawText(200,140,timeFont,time,Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
//doing the clearClip() here doesn't work, so I did it in onUpdate()
//instead!
//dc.clearClip();
}