Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion resources/layouts/layout.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<layouts>
<layout id="MainLayout" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://developer.garmin.com/downloads/connect-iq/resources.xsd">
<!-- Cadence Icon -->
<bitmap id="cadence_icon"
Expand Down Expand Up @@ -54,4 +55,27 @@
color="Gfx.COLOR_LT_GRAY" />


</layout>
</layout>

<!-- Watch face with date and time Layout -->
<layout id="WatchFace">
<label id="Date"
x="center"
y="30%"
font="Graphics.FONT_LARGE"
justification="Graphics.TEXT_JUSTIFY_CENTER" />

<label id="HoursAndMinutes"
x="40%"
y="55%"
font="Graphics.FONT_LARGE"
justification="Graphics.TEXT_JUSTIFY_CENTER" />

<label id="AmPm"
x="70%"
y="55%"
font="Graphics.FONT_LARGE"
justification="Graphics.TEXT_JUSTIFY_CENTER" />

</layout>
</layouts>
16 changes: 12 additions & 4 deletions source/Delegates/AdvancedViewDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,7 +62,7 @@ class AdvancedViewDelegate extends WatchUi.BehaviorDelegate {
}

function onBack(){
WatchUi.popView(WatchUi.SLIDE_BLINK);
// Back button disabled - no input
return true;
}

Expand Down
53 changes: 53 additions & 0 deletions source/Delegates/SettingsDelegates/WatchFaceMenuDelegate.mc
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 4 additions & 4 deletions source/Delegates/SimpleViewDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +97,7 @@ class SimpleViewDelegate extends WatchUi.BehaviorDelegate {
}

function onBack() as Boolean {
// Prevent accidental app exit
// Back button disabled - no input
return true;
}
}
4 changes: 1 addition & 3 deletions source/Delegates/SummaryViewDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
54 changes: 54 additions & 0 deletions source/Delegates/TimeViewDelegate.mc
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 0 additions & 2 deletions source/Views/SimpleView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");


}
Expand Down
69 changes: 69 additions & 0 deletions source/Views/TimeView.mc
Original file line number Diff line number Diff line change
@@ -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;
}
}