//class SaveDelegate extends Ui.ConfirmationDelegate {
class SaveDelegate extends MyConfirmationDelegate {
//Ui.pushView(new Ui.Confirmation("Save result?"), new SaveDelegate(), Ui.SLIDE_IMMEDIATE);
Ui.pushView(new MyConfirmation("Save result?"), new SaveDelegate(), Ui.SLIDE_IMMEDIATE);
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
const CX = 105;
const CY = 110;
const XY = 53;
const CANCEL = "Cancel";
const CONFIRM = "Confirm";
class MyConfirmationDelegate extends Ui.InputDelegate {
function onKey(event) {
var key = event.getKey();
if(Ui.KEY_ENTER == key) {
enterEvent();
}
else if(Ui.KEY_ESC == key) {
escEvent();
}
return true;
}
function onTap(event)
{
var coords = event.getCoordinates();
var x = coords[0];
var y = coords[1];
if(y > CY - 15 && y < CY + 15) {
if(x > CX - XY - 40 && x < CX - XY + 40) {
escEvent();
}
else if(x > CX + XY - 40 && x < CX + XY + 40) {
enterEvent();
}
}
}
function enterEvent()
{
onResponse(true);
popView(SLIDE_IMMEDIATE);
}
function escEvent()
{
onResponse(false);
popView(SLIDE_IMMEDIATE);
}
}
class MyConfirmation extends Ui.View {
hidden var mMsgText;
//! Load your resources here
function onLayout(dc) {
onUpdate(dc);
}
function initialize(msgText) {
mMsgText = msgText;
}
//! Restore the state of the app and prepare the view to be shown
function onShow() {
}
function onUpdate(dc) {
var font = Gfx.FONT_MEDIUM;
var just = Gfx.TEXT_JUSTIFY_CENTER|Gfx.TEXT_JUSTIFY_VCENTER;
dc.setColor( Gfx.COLOR_TRANSPARENT, Gfx.COLOR_BLACK );
dc.clear();
dc.setColor( Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT );
dc.drawText( CX, CY - XY, font, mMsgText, just);
dc.drawText( CX - XY, CY, font, CANCEL, just);
dc.drawText( CX + XY, CY, font, CONFIRM, just);
}
}