Skip to content

Commit

Permalink
Intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekthakurGarmin committed Apr 25, 2023
0 parents commit a750bbc
Show file tree
Hide file tree
Showing 106 changed files with 3,242 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OS X
.DS_Store
ExampleApp/.DS_Store

## User settings
xcuserdata/
*.xcuserdatad
17 changes: 17 additions & 0 deletions Comm Watch/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Comm</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>connectiq.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>connectiq.projectNature</nature>
</natures>
</projectDescription>
34 changes: 34 additions & 0 deletions Comm Watch/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. -->
<iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="1">
<iq:application entry="CommExample" id="a3421feed289106a538cb9547ab12095" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="1.2.0" name="@Strings.AppName" type="watch-app">
<iq:products>
<iq:product id="approachs60"/>
<iq:product id="d2bravo"/>
<iq:product id="d2bravo_titanium"/>
<iq:product id="d2charlie"/>
<iq:product id="descentmk1"/>
<iq:product id="epix"/>
<iq:product id="fenix3"/>
<iq:product id="fenix3_hr"/>
<iq:product id="fenix5"/>
<iq:product id="fenix5s"/>
<iq:product id="fenix5x"/>
<iq:product id="fenixchronos"/>
<iq:product id="fr230"/>
<iq:product id="fr235"/>
<iq:product id="fr630"/>
<iq:product id="fr735xt"/>
<iq:product id="fr920xt"/>
<iq:product id="fr935"/>
<iq:product id="vivoactive"/>
<iq:product id="vivoactive3"/>
<iq:product id="vivoactive_hr"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Communications"/>
</iq:permissions>
<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>
</iq:application>
</iq:manifest>
1 change: 1 addition & 0 deletions Comm Watch/monkey.jungle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.manifest = manifest.xml
3 changes: 3 additions & 0 deletions Comm Watch/resources/bitmaps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<bitmap id="LauncherIcon" filename="images/icon.png" />
</resources>
Binary file added Comm Watch/resources/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Comm Watch/resources/images/monkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Comm Watch/resources/resources.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<bitmaps>
<bitmap id="id_monkey" filename="images/monkey.png" />
</bitmaps>
</resources>
3 changes: 3 additions & 0 deletions Comm Watch/resources/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string id="AppName">Comm</string>
</resources>
84 changes: 84 additions & 0 deletions Comm Watch/source/CommApp.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// Copyright 2015-2016 by Garmin Ltd. or its subsidiaries.
// Subject to Garmin SDK License Agreement and Wearables
// Application Developer Agreement.
//

using Toybox.Application;
using Toybox.Communications;
using Toybox.WatchUi;
using Toybox.System;

var page = 0;
var strings = ["","","","",""];
var stringsSize = 5;
var mailMethod;
var phoneMethod;
var crashOnMessage = false;
var hasDirectMessagingSupport = true;

class CommExample extends Application.AppBase {

function initialize() {
Application.AppBase.initialize();

mailMethod = method(:onMail);
phoneMethod = method(:onPhone);
if(Communications has :registerForPhoneAppMessages) {
Communications.registerForPhoneAppMessages(phoneMethod);
} else if(Communications has :setMailboxListener) {
Communications.setMailboxListener(mailMethod);
} else {
hasDirectMessagingSupport = false;
}
}

// onStart() is called on application start up
function onStart(state) {
}

// onStop() is called when your application is exiting
function onStop(state) {
}

// Return the initial view of your application here
function getInitialView() {
return [new CommView(), new CommInputDelegate()];
}

function onMail(mailIter) {
var mail;

mail = mailIter.next();

while(mail != null) {
var i;
for(i = (stringsSize - 1); i > 0; i -= 1) {
strings[i] = strings[i-1];
}
strings[0] = mail.toString();
page = 1;
mail = mailIter.next();
}

Communications.emptyMailbox();
WatchUi.requestUpdate();
}

function onPhone(msg) {
var i;

if((crashOnMessage == true) && msg.data.equals("Hi")) {
msg.length(); // Generates a symbol not found error in the VM
}

for(i = (stringsSize - 1); i > 0; i -= 1) {
strings[i] = strings[i-1];
}
strings[0] = msg.data.toString();
page = 1;

WatchUi.requestUpdate();
}

}
124 changes: 124 additions & 0 deletions Comm Watch/source/CommDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// Copyright 2016 by Garmin Ltd. or its subsidiaries.
// Subject to Garmin SDK License Agreement and Wearables
// Application Developer Agreement.
//

using Toybox.WatchUi;
using Toybox.System;
using Toybox.Communications;

class CommListener extends Communications.ConnectionListener {
function initialize() {
Communications.ConnectionListener.initialize();
}

function onComplete() {
System.println("Transmit Complete");
}

function onError() {
System.println("Transmit Failed");
}
}

class CommInputDelegate extends WatchUi.BehaviorDelegate {
function initialize() {
WatchUi.BehaviorDelegate.initialize();
}

function onMenu() {
var menu = new WatchUi.Menu();
var delegate;

menu.addItem("Send Data", :sendData);
menu.addItem("Set Listener", :setListener);
delegate = new BaseMenuDelegate();
WatchUi.pushView(menu, delegate, SLIDE_IMMEDIATE);

return true;
}

function onTap(event) {
if(page == 0) {
page = 1;
} else {
page = 0;
}
WatchUi.requestUpdate();
}
}

class BaseMenuDelegate extends WatchUi.MenuInputDelegate {
function initialize() {
WatchUi.MenuInputDelegate.initialize();
}

function onMenuItem(item) {
var menu = new WatchUi.Menu();
var delegate = null;

if(item == :sendData) {
menu.addItem("Hello World.", :hello);
menu.addItem("Ackbar", :trap);
menu.addItem("Garmin", :garmin);
delegate = new SendMenuDelegate();
} else if(item == :setListener) {
menu.setTitle("Listner Type");
menu.addItem("Mailbox", :mailbox);
if(Communications has :registerForPhoneAppMessages) {
menu.addItem("Phone Application", :phone);
}
menu.addItem("None", :none);
menu.addItem("Crash if 'Hi'", :phoneFail);
delegate = new ListnerMenuDelegate();
}

WatchUi.pushView(menu, delegate, SLIDE_IMMEDIATE);
}
}

class SendMenuDelegate extends WatchUi.MenuInputDelegate {
function initialize() {
WatchUi.MenuInputDelegate.initialize();
}

function onMenuItem(item) {
var listener = new CommListener();

if(item == :hello) {
Communications.transmit("Hello World.", null, listener);
} else if(item == :trap) {
Communications.transmit("IT'S A TRAP!", null, listener);
} else if(item == :garmin) {
Communications.transmit("ConnectIQ", null, listener);
}

WatchUi.popView(SLIDE_IMMEDIATE);
}
}

class ListnerMenuDelegate extends WatchUi.MenuInputDelegate {
function initialize() {
WatchUi.MenuInputDelegate.initialize();
}

function onMenuItem(item) {
if(item == :mailbox) {
Communications.setMailboxListener(mailMethod);
} else if(item == :phone) {
if(Communications has :registerForPhoneAppMessages) {
Communications.registerForPhoneAppMessages(phoneMethod);
}
} else if(item == :none) {
Communications.registerForPhoneAppMessages(null);
Communications.setMailboxListener(null);
} else if(item == :phoneFail) {
crashOnMessage = true;
Communications.registerForPhoneAppMessages(phoneMethod);
}

WatchUi.popView(SLIDE_IMMEDIATE);
}
}

74 changes: 74 additions & 0 deletions Comm Watch/source/CommView.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Copyright 2016 by Garmin Ltd. or its subsidiaries.
// Subject to Garmin SDK License Agreement and Wearables
// Application Developer Agreement.
//

using Toybox.WatchUi;
using Toybox.Graphics;
using Toybox.Communications;
using Toybox.System;

class CommView extends WatchUi.View {
var screenShape;

function initialize() {
View.initialize();
}

function onLayout(dc) {
screenShape = System.getDeviceSettings().screenShape;
}

function drawIntroPage(dc) {
if(System.SCREEN_SHAPE_ROUND == screenShape) {
dc.drawText(dc.getWidth() / 2, 25, Graphics.FONT_SMALL, "Communications", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 55, Graphics.FONT_SMALL, "Test", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 80, Graphics.FONT_TINY, "Connect a phone then", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 100, Graphics.FONT_TINY, "use the menu to send", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 120, Graphics.FONT_TINY, "strings to your phone", Graphics.TEXT_JUSTIFY_CENTER);
} else if(System.SCREEN_SHAPE_SEMI_ROUND == screenShape) {
dc.drawText(dc.getWidth() / 2, 20, Graphics.FONT_MEDIUM, "Communications test", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 50, Graphics.FONT_SMALL, "Connect a phone", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 70, Graphics.FONT_SMALL, "Then use the menu to send", Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth() / 2, 90, Graphics.FONT_SMALL, "strings to your phone", Graphics.TEXT_JUSTIFY_CENTER);
} else if(dc.getWidth() > dc.getHeight()) {
dc.drawText(10, 20, Graphics.FONT_MEDIUM, "Communications test", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 50, Graphics.FONT_SMALL, "Connect a phone", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 70, Graphics.FONT_SMALL, "Then use the menu to send", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 90, Graphics.FONT_SMALL, "strings to your phone", Graphics.TEXT_JUSTIFY_LEFT);
} else {
dc.drawText(10, 20, Graphics.FONT_MEDIUM, "Communications test", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 40, Graphics.FONT_MEDIUM, "Test", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 70, Graphics.FONT_SMALL, "Connect a phone", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 90, Graphics.FONT_SMALL, "Then use the menu", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 110, Graphics.FONT_SMALL, "to send strings", Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(10, 130, Graphics.FONT_SMALL, "to your phone", Graphics.TEXT_JUSTIFY_LEFT);
}
}

function onUpdate(dc) {
dc.setColor(Graphics.COLOR_TRANSPARENT, Graphics.COLOR_BLACK);
dc.clear();
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);

if(hasDirectMessagingSupport) {
if(page == 0) {
drawIntroPage(dc);
} else {
var i;
var y = 50;

dc.drawText(dc.getWidth() / 2, 20, Graphics.FONT_MEDIUM, "Strings Received:", Graphics.TEXT_JUSTIFY_CENTER);
for(i = 0; i < stringsSize; i += 1) {
dc.drawText(dc.getWidth() / 2, y, Graphics.FONT_SMALL, strings[i], Graphics.TEXT_JUSTIFY_CENTER);
y += 20;
}
}
} else {
dc.drawText(dc.getWidth() / 2, dc.getHeight() / 3, Graphics.FONT_MEDIUM, "Direct Messaging API\nNot Supported", Graphics.TEXT_JUSTIFY_CENTER);
}
}


}
Binary file added CommWatch.prg
Binary file not shown.
Loading

0 comments on commit a750bbc

Please sign in to comment.