using Toybox.Application as App;
using Toybox.ActivityRecording as Arc;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.WatchUi as Ui;
class TestMenuDelegate extends Ui.MenuInputDelegate
{
function onMenuItem(item) {
return true;
}
}
class TestDelegate extends Ui.InputDelegate
{
hidden var view;
hidden var activity;
hidden var state;
function initialize(view) {
self.view = view;
activity = null;
state = 1;
}
function onKey(evt) {
var key = evt.getKey();
if (key == Ui.KEY_ENTER) {
Sys.println("state="+state);
if (state & 1) {
// could push a self-removing progress bar here instead...
var menu = new Ui.Menu();
menu.setTitle("Menu");
menu.addItem("Test 1", :test1);
menu.addItem("Test 2", :test2);
menu.addItem("Test 3", :test3);
Ui.pushView(menu, new TestMenuDelegate(), Ui.SLIDE_IMMEDIATE);
view.setText("Press Enter");
}
else if (state == 2) {
activity = Arc.createSession({
:sport => Arc.SPORT_GENERIC,
:subSport => Arc.SUB_SPORT_GENERIC,
:name => "testing"
});
view.setText("Created\nPress Enter");
}
else if (state == 4) {
activity.start();
view.setText("Recording\nPress Enter");
}
else if (state == 6) {
activity.stop();
view.setText("Paused\nPress Enter");
}
else if (state == 8) {
activity.discard();
view.setText("Discarded\nPress Enter");
}
else if (state == 10) {
activity = null;
view.setText("Deallocated\nPress Enter");
}
else {
Ui.popView(Ui.SLIDE_IMMEDIATE);
}
++state;
}
return true;
}
}
class TestView extends Ui.View
{
var text;
function initialize() {
text = "Press Enter\nTo Start";
}
function setText(text) {
self.text = text;
Ui.requestUpdate();
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_WHITE);
dc.clear();
var cx = dc.getWidth() / 2;
var cy = dc.getHeight() / 2;
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.drawText(cx, cy, Gfx.FONT_LARGE,
text,
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
}
}
class TestApp extends App.AppBase
{
function getInitialView() {
var view = new TestView();
var delegate = new TestDelegate(view);
return [ view, delegate ];
}
}