// Author: cirakg & claude ai // Summary: Input on the list (README 13.4): scroll with UP/DOWN or swipes, open with START or a tap, menu (MENU or long press), back exits. import Toybox.Lang; import Toybox.WatchUi; class ListDelegate extends WatchUi.BehaviorDelegate { private var _view as ListView; function initialize(view as ListView) { BehaviorDelegate.initialize(); _view = view; } function onNextPage() as Boolean { if (!Gesture.recent()) { AppState.activity(); _view.move(1); } return true; } function onPreviousPage() as Boolean { if (!Gesture.recent()) { AppState.activity(); _view.move(-1); } return true; } // The Forerunner 70 sends no page behaviour for a vertical swipe, so the // swipe and the drag scroll here; Gesture makes a gesture count once. function onSwipe(event as WatchUi.SwipeEvent) as Boolean { if (!Gesture.isVertical(event)) { return BehaviorDelegate.onSwipe(event); } var step = Gesture.swipeStep(event); if (step != 0) { AppState.activity(); _view.move(step); } return true; } // A drag scrolls by the rows it covered, at least one. function onDrag(event as WatchUi.DragEvent) as Boolean { var step = Gesture.dragStep(event, _view.rowHeight()); if (step == 0) { return false; } AppState.activity(); _view.move(step); return true; } // On touch screens a tap arrives as the select behaviour first; returning // false passes it on to onTap, which opens the row under the finger. The // START button then comes through onKey. function onSelect() as Boolean { if (Ui.isTouch()) { return false; } openFocused(); return true; } function onKey(event as WatchUi.KeyEvent) as Boolean { if (Ui.isTouch() && event.getKey() == WatchUi.KEY_ENTER) { openFocused(); return true; } return false; } private function openFocused() as Void { AppState.activity(); var id = _view.focusedId(); if (id != null) { Nav.openEntry(id); } } // A tap opens the row under the finger. function onTap(event as WatchUi.ClickEvent) as Boolean { AppState.activity(); if (Gesture.tapIgnored()) { return true; } var index = _view.rowAt(event.getCoordinates()[1]); if (index < 0) { return true; } _view.focus = index; var id = _view.focusedId(); if (id != null) { Nav.openEntry(id); } return true; } // A long press opens the menu too: watches without a MENU button // (Venu X1) have no other way to reach it (README 13.4). function onHold(event as WatchUi.ClickEvent) as Boolean { AppState.activity(); Nav.openMenu(); return true; } function onMenu() as Boolean { AppState.activity(); Nav.openMenu(); return true; } // BACK leaves the app; onStop locks everything. function onBack() as Boolean { return false; } }