Introduction
We can use Monkey C and Connect IQ SDK to customize the appearance of Garmin devices. The article is the note for learning Monkey C.
Overview
It's a simple example for a Connect IQ application with simple menu. There are a few kind of objects in this example.
- App.AppBase: entry point
- Ui.View: menu or other views
- Ui.MenuInputDelegate: the actions when the menu item is selected
- module: stores static variables
Steps
1.Prepare the development environment
- Please install Eclipse and Connect SDK with the documents: https://developer.ola.cf.garmin.com/connect-iq/programmers-guide/getting-started
2.Prepare the manifest.xml and resources/menus/menu.xml
- manifest.xml: specify the entry
entry="ExampleApp"
- resources/menus/menu.xml
<menu id="ExampleMenu"> <menu-item id="room_1" label="Item 1" /> <menu-item id="room_2" label="Item 2" /> </menu>
3.Prepare main files
- Module (Example)
using Toybox.System as Sys; using Toybox.Communications as Comm; using Toybox.Application; using Toybox.WatchUi as Ui; using Toybox.Timer as Timer; using Toybox.UserProfile; module Example { var roomId = -1; }
- Entry point (ExampleApp)
using Toybox.Application as App; using Toybox.WatchUi as Ui; class ExampleApp extends App.AppBase { function initialize() { AppBase.initialize(); } // Return the initial view of your application here function getInitialView() { return [new ExampleAppMenu()]; } }
- Menu (ExampleAppMenu)
using Toybox.WatchUi as Ui; using Toybox.System as Sys; using Toybox.Timer as Timer; class ExampleAppMenu extends Ui.View { function initialize() { } function selectRoomMenu() { Ui.pushView(new Rez.Menus.ExampleMenu(), new ExampleAppMenuDelegate(), Ui.SLIDE_IMMEDIATE); } }
- Actions (ExampleAppMenuDelegate)
using Toybox.WatchUi as Ui; using Toybox.System as Sys; class ExampleAppMenuDelegate extends Ui.MenuInputDelegate { function initialize() { MenuInputDelegate.initialize(); } function onMenuItem(item) { if (item == :room_1) { Example.roomId = 1; } else { Example.roomId = 2; } Ui.popView(Ui.SLIDE_IMMEDIATE); Ui.pushView(new ExampleAppView(), new ExampleAppDelegate(), Ui.SLIDE_IMMEDIATE); } }
4.Compile and run on the simulator
- That's it!
Articles
There are some of my articles. Feel free to check if you like!
- My blog-posts for software developing: https://medium.com/a-layman
- My website: https://www.alayman.io/
- Facebook page: https://www.facebook.com/imalayman
Top comments (2)
The example doesn't work . You missed to share something...
This seems to be indeed missing at least implementation of
ExampleAppView()
andExampleAppDelegate()