diff --git a/resources/layouts/layout.xml b/resources/layouts/layout.xml index c17a018..935f00e 100644 --- a/resources/layouts/layout.xml +++ b/resources/layouts/layout.xml @@ -1,3 +1,4 @@ + - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/source/Delegates/AdvancedViewDelegate.mc b/source/Delegates/AdvancedViewDelegate.mc index edf4782..a6ea95d 100644 --- a/source/Delegates/AdvancedViewDelegate.mc +++ b/source/Delegates/AdvancedViewDelegate.mc @@ -25,10 +25,18 @@ class AdvancedViewDelegate extends WatchUi.BehaviorDelegate { function onKey(keyEvent as WatchUi.KeyEvent){ var key = keyEvent.getKey(); + // Scroll down to SimpleView (completing the loop) + if(key == WatchUi.KEY_DOWN) { + WatchUi.switchToView( + new SimpleView(), + new SimpleViewDelegate(), + WatchUi.SLIDE_DOWN + ); + return true; + } - //back to simpleView - if(key == WatchUi.KEY_UP) - { + // Up button still goes back + if(key == WatchUi.KEY_UP) { WatchUi.popView(WatchUi.SLIDE_UP); } return true; @@ -54,7 +62,7 @@ class AdvancedViewDelegate extends WatchUi.BehaviorDelegate { } function onBack(){ - WatchUi.popView(WatchUi.SLIDE_BLINK); + // Back button disabled - no input return true; } diff --git a/source/Delegates/SettingsDelegates/WatchFaceMenuDelegate.mc b/source/Delegates/SettingsDelegates/WatchFaceMenuDelegate.mc new file mode 100644 index 0000000..1b26e8d --- /dev/null +++ b/source/Delegates/SettingsDelegates/WatchFaceMenuDelegate.mc @@ -0,0 +1,53 @@ +import Toybox.Lang; +import Toybox.System; +import Toybox.WatchUi; + +// WatchFaceMenuDelegate handles user interactions with the watch face view selection menu. +// It allows users to choose between different view options (Simple View, Time View) and +// manages the navigation between these views. +class WatchFaceMenuDelegate extends WatchUi.Menu2InputDelegate { + + // Initialize the delegate with the provided menu. + function initialize(menu as WatchUi.Menu2) { + Menu2InputDelegate.initialize(); + } + + // Handle menu item selection by the user. + // Routes the selection to the appropriate view switching method based on the menu item ID. + function onSelect(item as WatchUi.MenuItem) as Void { + var id = item.getId(); + + if (id == :simple_view) { + System.println("Selected: Simple View"); + switchToSimpleView(); + } else if (id == :time_view) { + System.println("Selected: Time View"); + switchToTimeView(); + } + } + + // Handle back button press by closing the menu and returning to the previous view. + function onBack() as Void { + WatchUi.popView(WatchUi.SLIDE_RIGHT); + } + + // Switch the current view to the Simple View by popping the menu layers and pushing the new view. + // Pops two views to clear the menu and settings layers, then displays the Simple View. + private function switchToSimpleView() as Void { + WatchUi.popView(WatchUi.SLIDE_DOWN); + WatchUi.popView(WatchUi.SLIDE_DOWN); + var view = new SimpleView(); + var delegate = new SimpleViewDelegate(); + WatchUi.pushView(view, delegate, WatchUi.SLIDE_IMMEDIATE); + } + + // Switch the current view to the Time View by popping the menu layers and pushing the new view. + // Pops two views to clear the menu and settings layers, then displays the Time View. + private function switchToTimeView() as Void { + WatchUi.popView(WatchUi.SLIDE_DOWN); + WatchUi.popView(WatchUi.SLIDE_DOWN); + var view = new TimeView(); + var delegate = new TimeViewDelegate(); + WatchUi.pushView(view, delegate, WatchUi.SLIDE_IMMEDIATE); + } +} diff --git a/source/Delegates/SimpleViewDelegate.mc b/source/Delegates/SimpleViewDelegate.mc index be21c43..ed41885 100644 --- a/source/Delegates/SimpleViewDelegate.mc +++ b/source/Delegates/SimpleViewDelegate.mc @@ -52,10 +52,10 @@ class SimpleViewDelegate extends WatchUi.BehaviorDelegate { } if (key == WatchUi.KEY_DOWN) { - _currentView = new AdvancedView(); - WatchUi.pushView( + _currentView = new TimeView(); + WatchUi.switchToView( _currentView, - new AdvancedViewDelegate(_currentView), + new TimeViewDelegate(), WatchUi.SLIDE_DOWN ); return true; @@ -97,7 +97,7 @@ class SimpleViewDelegate extends WatchUi.BehaviorDelegate { } function onBack() as Boolean { - // Prevent accidental app exit + // Back button disabled - no input return true; } } diff --git a/source/Delegates/SummaryViewDelegate.mc b/source/Delegates/SummaryViewDelegate.mc index 85e15bd..f76d704 100644 --- a/source/Delegates/SummaryViewDelegate.mc +++ b/source/Delegates/SummaryViewDelegate.mc @@ -15,10 +15,8 @@ class SummaryViewDelegate extends WatchUi.BehaviorDelegate { return true; } - // BACK button to dismiss + // BACK button disabled - no input function onBack() as Boolean { - System.println("[SUMMARY] Back pressed, returning to main view"); - WatchUi.popView(WatchUi.SLIDE_DOWN); return true; } diff --git a/source/Delegates/TimeViewDelegate.mc b/source/Delegates/TimeViewDelegate.mc new file mode 100644 index 0000000..7a315a7 --- /dev/null +++ b/source/Delegates/TimeViewDelegate.mc @@ -0,0 +1,54 @@ +import Toybox.Lang; +import Toybox.WatchUi; + +class TimeViewDelegate extends WatchUi.BehaviorDelegate { + + function initialize() { + BehaviorDelegate.initialize(); + } + + // Long-press MENU to open settings + function onMenu() as Boolean { + pushSettingsView(); + return true; + } + + // Down button to scroll to AdvancedView + function onKey(keyEvent as WatchUi.KeyEvent) as Boolean { + var key = keyEvent.getKey(); + + if (key == WatchUi.KEY_DOWN) { + var advancedView = new AdvancedView(); + WatchUi.switchToView( + advancedView, + new AdvancedViewDelegate(advancedView), + WatchUi.SLIDE_DOWN + ); + return true; + } + + if (key == WatchUi.KEY_UP) { + return true; + } + + return false; + } + + // Back button - do nothing to prevent crash + function onBack() as Boolean { + return true; + } +} + +function pushSettingsView() as Void { + var settingsView = new SettingsView(); + var settingsDelegate = new SettingsDelegate(); + WatchUi.pushView(settingsView, settingsDelegate, WatchUi.SLIDE_LEFT); +} + + +class SettingsDelegate extends WatchUi.BehaviorDelegate { + function initialize() { + BehaviorDelegate.initialize(); + } +} diff --git a/source/Views/SimpleView.mc b/source/Views/SimpleView.mc index c20332f..f68fce4 100644 --- a/source/Views/SimpleView.mc +++ b/source/Views/SimpleView.mc @@ -16,7 +16,6 @@ class SimpleView extends WatchUi.View { private var _lastZoneState = 0; // -1 = below, 0 = inside, 1 = above private var _vibeTimer = new Timer.Timer(); private var _cqDisplay; - private var _hardcoreDisplay; function _secondVibe() as Void { // Haptics not available on this target SDK/device in this workspace. @@ -38,7 +37,6 @@ class SimpleView extends WatchUi.View { _distanceDisplay = findDrawableById("distance_text"); _timeDisplay = findDrawableById("time_text"); _cqDisplay = findDrawableById("cq_text"); - _hardcoreDisplay = findDrawableById("hardcore_text"); } diff --git a/source/Views/TimeView.mc b/source/Views/TimeView.mc new file mode 100644 index 0000000..bde1842 --- /dev/null +++ b/source/Views/TimeView.mc @@ -0,0 +1,69 @@ +import Toybox.Graphics; +import Toybox.WatchUi; +import Toybox.System; +import Toybox.Time; +import Toybox.Time.Gregorian; +import Toybox.Lang; + +class TimeView extends WatchUi.View { + private var _isAwake as Boolean = false; + + function initialize() { + View.initialize(); + } + + // Load your resources here + function onLayout(dc as Dc) as Void { + setLayout(Rez.Layouts.WatchFace(dc)); + } + + // 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 { + _isAwake = true; + } + + // Update the view + function onUpdate(dc as Dc) as Void { + var date = Gregorian.info(Time.now(), Time.FORMAT_SHORT); + var dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + + // Format: "Sat 25 Jan" + (View.findDrawableById("Date") as WatchUi.Text).setText( + dayNames[date.day_of_week - 1] + " " + date.day.format("%2d") + " " + monthNames[date.month - 1] + ); + // Convert to 12-hour format with AM/PM + var hour12 = date.hour % 12; + if (hour12 == 0) { + hour12 = 12; + } + var ampm = (date.hour < 12) ? "AM" : "PM"; + (View.findDrawableById("HoursAndMinutes") as WatchUi.Text).setText( + hour12.format("%02d") + ":" + date.min.format("%02d") + ); + (View.findDrawableById("AmPm") as WatchUi.Text).setText(ampm); + + + + // Call the parent onUpdate function to redraw the layout + View.onUpdate(dc); + } + + // Called when this View is removed from the screen. Save the + // state of this View here. This includes freeing resources from + // memory. + function onHide() as Void { + } + + // The user has just looked at their watch. Timers and animations may be started here. + function onExitSleep() as Void { + _isAwake = true; + } + + // Terminate any active timers and prepare for slow updates. + function onEnterSleep() as Void { + _isAwake = false; + } +}