loading...
Cover image for Day 10 of #100DaysOfCode: Learn Monkey C- create a menu for CIQ application

Day 10 of #100DaysOfCode: Learn Monkey C- create a menu for CIQ application

jenhsuan profile image Jen-Hsuan Hsieh ・2 min read

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

Alt Text

Steps

1.Prepare the development environment

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!

Alt Text

Articles

There are some of my articles. Feel free to check if you like!

Posted on by:

jenhsuan profile

Jen-Hsuan Hsieh

@jenhsuan

6+ year work experience in the software engineering field. 2+ year work experience with front-end JavaScript framework like React.js, Knockout.js. and Microsoft solution.

Discussion

markdown guide