Skip to content

Commit

Permalink
Merge pull request #11 from miss-architect/sdk-update-button
Browse files Browse the repository at this point in the history
Updated SDK to support Button component and introduced support for newer
  • Loading branch information
miss-architect authored Mar 13, 2021
2 parents 98f6a35 + 5014806 commit ff71167
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 173 deletions.
46 changes: 30 additions & 16 deletions manifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
<!-- 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="SquashApp" id="020B05CFF17F4B248AE111724A7A6EC5" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="1.3.1" name="@Strings.AppName" type="watch-app">

<!-- 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="SquashApp" id="020B05CFF17F4B248AE111724A7A6EC5" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watch-app">
<iq:products>
<iq:product id="fr630"/>
<iq:product id="fr235"/>
<iq:product id="fr735xt"/>
<iq:product id="fr230"/>
<iq:product id="vivoactive"/>
<iq:product id="fenix3"/>
<iq:product id="fenix3_hr"/>
<iq:product id="fr920xt"/>
<iq:product id="vivoactive_hr"/>
<iq:product id="fenix5"/>
<iq:product id="fenix5plus"/>
<iq:product id="fenix5s"/>
<iq:product id="fenix5splus"/>
<iq:product id="fenix5x"/>
<iq:product id="fenix5xplus"/>
<iq:product id="fenix6"/>
<iq:product id="fenix6pro"/>
<iq:product id="fenix6s"/>
<iq:product id="fenix6spro"/>
<iq:product id="fenix6xpro"/>
<iq:product id="fenixchronos"/>
<iq:product id="fr245"/>
<iq:product id="fr245m"/>
<iq:product id="fr645"/>
<iq:product id="fr645m"/>
<iq:product id="fr745"/>
<iq:product id="fr935"/>
<iq:product id="fr945"/>
<iq:product id="vivoactive3"/>
<iq:product id="vivoactive3d"/>
<iq:product id="vivoactive3m"/>
<iq:product id="vivoactive3mlte"/>
<iq:product id="vivoactive4"/>
<iq:product id="vivoactive4s"/>
</iq:products>

<iq:permissions>
<iq:uses-permission id="Background"/>
<iq:uses-permission id="Fit"/>
<iq:uses-permission id="FitContributor"/>
<iq:uses-permission id="PersistedContent"/>
<iq:uses-permission id="Sensor"/>
<iq:uses-permission id="SensorHistory"/>
</iq:permissions>

<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>

</iq:application>
</iq:manifest>
Binary file modified resources/drawables/launcher_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 25 additions & 25 deletions resources/layouts/playerfield.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<resources>
<drawable-list id="player1field" x="2" y="27" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="player2field" x="74" y="27" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="stepsfield" x="2" y="82" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="heartratefield" x="74" y="82" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="timeField" x="2" y="127" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="calories" x="74" y="127" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<resources>
<drawable-list id="player1field" x="2" y="27" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="player2field" x="74" y="27" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="timeField" x="2" y="82" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="heartratefield" x="74" y="82" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="stepsfield" x="2" y="127" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

<drawable-list id="calories" x="74" y="127" width="70" height="42">
<shape type="rectangle" x="0" y="0" width="70" height="42" color="Gfx.COLOR_BLACK" border_color="Gfx.COLOR_WHITE" border_width="2"/>
</drawable-list>

</resources>
138 changes: 69 additions & 69 deletions source/GameConfiguration.mc
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
using Toybox.WatchUi as Ui;
using Toybox.Application as App;

//! Class that holds the configuration of the game
//! as total number of sets and the max score in
//! one set. It reads the configuration from
//! the object store of the application.
class GameConfiguration {

hidden var setMaxScore;
hidden var setTotalSets;
hidden var player1Name;
hidden var player2Name;
static var instance = null;
static function getInstance() {
if (instance == null) {
instance = new GameConfiguration();
}
return instance;
}

function initialize() {
setMaxScore = readKeyInt("setMaxScore", 11);
setTotalSets = readKeyInt("setTotalSets", 5);
player1Name = readString("player1Name", 8, Ui.loadResource(Rez.Strings.player1_score_label));
player2Name = readString("player2Name", 8, Ui.loadResource(Rez.Strings.player2_score_label));
}

// make sure property is of type number
// see https://webcache.googleusercontent.com/search?cd=2&hl=en&ct=clnk&gl=ch&
// q=cache:0hxHRJ_80hcJ:https://forums.garmin.com/archive/index.php/t-359183.html+
hidden function readKeyInt(key, thisDefault) {
var value = App.getApp().getProperty(key);

if(value == null || !(value instanceof Number)) {
if(value != null) {
value = value.toNumber();
} else {
value = thisDefault;
}
}
return value;
}
hidden function readString(key, length, thisDefault) {
var value = App.getApp().getProperty(key);
if(value == null) {
value = thisDefault;
}
return value.substring(0, length);
}
function getMaxScore() {
return setMaxScore;
}
function getTotalSets() {
return setTotalSets;
}
function getPlayer1Name(){
return player1Name;
}
function getPlayer2Name() {
return player2Name;
}
using Toybox.WatchUi as Ui;
using Toybox.Application as App;

//! Class that holds the configuration of the game
//! as total number of sets and the max score in
//! one set. It reads the configuration from
//! the object store of the application.
class GameConfiguration {

hidden var setMaxScore;
hidden var setTotalSets;
hidden var player1Name;
hidden var player2Name;
static var instance = null;

static function getInstance() {
if (instance == null) {
instance = new GameConfiguration();
}
return instance;
}

function initialize() {
setMaxScore = readKeyInt("setMaxScore", 11);
setTotalSets = readKeyInt("setTotalSets", 5);
player1Name = readString("player1Name", 8, App.loadResource(Rez.Strings.player1_score_label));
player2Name = readString("player2Name", 8, App.loadResource(Rez.Strings.player2_score_label));
}

// make sure property is of type number
// see https://webcache.googleusercontent.com/search?cd=2&hl=en&ct=clnk&gl=ch&
// q=cache:0hxHRJ_80hcJ:https://forums.garmin.com/archive/index.php/t-359183.html+
hidden function readKeyInt(key, thisDefault) {
var value = App.getApp().getProperty(key);

if(value == null || !(value instanceof Number)) {
if(value != null) {
value = value.toNumber();
} else {
value = thisDefault;
}
}
return value;
}

hidden function readString(key, length, thisDefault) {
var value = App.getApp().getProperty(key);

if(value == null) {
value = thisDefault;
}
return value.substring(0, length);
}

function getMaxScore() {
return setMaxScore;
}

function getTotalSets() {
return setTotalSets;
}

function getPlayer1Name(){
return player1Name;
}

function getPlayer2Name() {
return player2Name;
}
}
3 changes: 2 additions & 1 deletion source/Session.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Toybox.ActivityRecording as Record;
using Toybox.FitContributor as Fit;
using Toybox.Attention as Attention;

//! Class used to record an activity
class Session {
Expand Down Expand Up @@ -29,7 +30,7 @@ class Session {
function start(){
if(Toybox has :ActivityRecording ) {
if(!isRecording()) {
session = Record.createSession({:name=>"Squash",
session = Record.createSession({:name=>"Squash",
:sport=>Record.SPORT_TENNIS,
:subSport=>Record.SUB_SPORT_MATCH});
setupFields();
Expand Down
27 changes: 1 addition & 26 deletions source/SquashDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,6 @@ class SquashDelegate extends Ui.BehaviorDelegate {
}
}

//! Function called when user taps a touch screen.
//! Replacement of Button feature that does not exist
//! in sdk v1.3.1
function onTap(evt)
{
var x = evt.getCoordinates()[0];
var y = evt.getCoordinates()[1];
if (isHitting(x,y, player1LocX)) {
onPlayer1();
}
else if (isHitting(x,y, player2LocX)) {
onPlayer2();
}
return true;
}

//! Check if the user is tapping a score button.
//! This function uses global variables defined
//! in SquashView. This is ugly, and has to be
//! improved! But if Garmin starts offering the
//! button feature in older devices, this won't be necessary.
function isHitting(x, y, xStartPosition) {
return (((x > xStartPosition) && (x < (xStartPosition + widthButton))) &&
(y < heightButton));
}

//! Event used in non-touchscreen devices to
//! increment player 2 score
function onNextPage() {
Expand All @@ -133,6 +107,7 @@ class SquashDelegate extends Ui.BehaviorDelegate {
new ExitConfirmationDelegate(), Ui.SLIDE_IMMEDIATE);
return true;
}

}

//! Delegate that handles the event from the Confirmation dialog
Expand Down
Loading

0 comments on commit ff71167

Please sign in to comment.