Skip to content

Commit

Permalink
add the arrow in datafield
Browse files Browse the repository at this point in the history
  • Loading branch information
avouspierre committed May 5, 2023
1 parent aef3e13 commit ec3b8dc
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 8 deletions.
9 changes: 5 additions & 4 deletions iAPSGarminDataField/example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"glucose": "210",
"lastLoopDateInterval": 1683299799,
"delta": "-2",
"glucose": "60",
"lastLoopDateInterval": 1683316189,
"delta": "-20",
"iob": "2.42",
"cob": "70.2",
"eventualBGRaw": "100"
"eventualBGRaw": "100",
"trendRaw":"FortyFiveDown"
}
10 changes: 10 additions & 0 deletions iAPSGarminDataField/resources/drawables/DoubleDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions iAPSGarminDataField/resources/drawables/DoubleUp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions iAPSGarminDataField/resources/drawables/Flat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions iAPSGarminDataField/resources/drawables/FortyFiveDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions iAPSGarminDataField/resources/drawables/FortyFiveUp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions iAPSGarminDataField/resources/drawables/SingleDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions iAPSGarminDataField/resources/drawables/SingleUp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions iAPSGarminDataField/resources/drawables/Unknown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions iAPSGarminDataField/resources/drawables/drawables.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,105 @@
<drawables>
<bitmap id="LauncherIcon" filename="launcher_40_40.png" />

<!-- Arrows -->

<bitmap id="Flat" filename="Flat.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="Unknown" filename="Unknown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="FortyFiveUp" filename="FortyFiveUp.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="FortyFiveDown" filename="FortyFiveDown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="SingleUp" filename="SingleUp.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="SingleDown" filename="SingleDown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="DoubleUp" filename="DoubleUp.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<bitmap id="DoubleDown" filename="DoubleDown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>

<!-- Arrows black-->

<bitmap id="FlatB" filename="Flat.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="UnknownB" filename="Unknown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="FortyFiveUpB" filename="FortyFiveUp.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="FortyFiveDownB" filename="FortyFiveDown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="SingleUpB" filename="SingleUp.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="SingleDownB" filename="SingleDown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="DoubleUpB" filename="DoubleUp.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>

<bitmap id="DoubleDownB" filename="DoubleDown.svg" scaleX="7%" scaleY="7%" scaleRelativeTo="screen">
<palette>
<color>000000</color>
</palette>
</bitmap>


</drawables>
1 change: 1 addition & 0 deletions iAPSGarminDataField/resources/drawables/heart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions iAPSGarminDataField/resources/drawables/right-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions iAPSGarminDataField/resources/drawables/steps.svg
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 iAPSGarminDataField/resources/layouts/layouts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<label id="value" x="center" y="center" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_LARGE" />
<label id="valueDelta" x="center" y="center" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_SMALL" />
<label id="valueTime" x="center" y="center" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_XTINY" />
<bitmap id="arrow" x="center" y="center" filename="../drawables/Unknown.svg" scaleX="8%" scaleY="8%" scaleRelativeTo="screen">
<palette>
<color>FFFFFF</color>
</palette>
</bitmap>
</layout>

<!-- Layouts used for the for the four quadrants. -->
Expand Down
2 changes: 0 additions & 2 deletions iAPSGarminDataField/source/iAPSBGServiceDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ class iAPSBGServiceDelegate extends System.ServiceDelegate {
Background.exit(msg.data);
}


function onTemporalEvent() {
System.println("Temp event");
Communications.transmit("status", null, new CommsRelay(method(:onTransmitComplete)));
Background.exit(null);

}

function onPhoneAppMessage(msg) {
Expand Down
106 changes: 104 additions & 2 deletions iAPSGarminDataField/source/iAPSDataFieldView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Toybox.WatchUi;


class iAPSDataFieldView extends WatchUi.DataField {

function initialize() {
DataField.initialize();
}
Expand Down Expand Up @@ -53,7 +54,9 @@ class iAPSDataFieldView extends WatchUi.DataField {
var valueViewDelta = View.findDrawableById("valueDelta");
valueViewDelta.locX = valueViewDelta.locX - 40;
valueViewDelta.locY = valueViewDelta.locY + 20;

var valueViewArrow = View.findDrawableById("arrow");
valueViewArrow.locX = valueView.locX + 30 ;
valueViewArrow.locY = valueViewArrow.locY - 10 ;
}

(View.findDrawableById("label") as Text).setText(Rez.Strings.label);
Expand Down Expand Up @@ -99,19 +102,33 @@ class iAPSDataFieldView extends WatchUi.DataField {
var value = View.findDrawableById("value") as Text;
var valueTime = View.findDrawableById("valueTime") as Text;
var valueDelta = View.findDrawableById("valueDelta") as Text;

if (getBackgroundColor() == Graphics.COLOR_BLACK) {
value.setColor(Graphics.COLOR_WHITE);
valueTime.setColor(Graphics.COLOR_WHITE);
valueDelta.setColor(Graphics.COLOR_WHITE);
valueDelta.setColor(Graphics.COLOR_WHITE);

} else {
value.setColor(Graphics.COLOR_BLACK);
valueTime.setColor(Graphics.COLOR_BLACK);
valueDelta.setColor(Graphics.COLOR_BLACK);

}


value.setText(bgString);
valueDelta.setText(deltaString);
valueTime.setText(loopString);

var arrowView = View.findDrawableById("arrow") as Bitmap;
if (getBackgroundColor() == Graphics.COLOR_BLACK) {
arrowView.setBitmap(getDirection(status));
}
else {
arrowView.setBitmap(getDirectionBlack(status));
}


// Call parent's onUpdate(dc) to redraw the layout
View.onUpdate(dc);
}
Expand Down Expand Up @@ -164,4 +181,89 @@ class iAPSDataFieldView extends WatchUi.DataField {
return deltaString;
}

function getDirectionBlack(status) as BitmapType {
var bitmap = WatchUi.loadResource(Rez.Drawables.UnknownB);
if (status instanceof Dictionary) {
var trend = status["trendRaw"] as String;
if (trend == null) {
return bitmap;
}

switch (trend) {
case "Flat":
bitmap = WatchUi.loadResource(Rez.Drawables.FlatB);
break;
case "SingleUp":
bitmap = WatchUi.loadResource(Rez.Drawables.SingleUpB);
break;
case "SingleDown":
bitmap = WatchUi.loadResource(Rez.Drawables.SingleDownB);
break;
case "FortyFiveUp":
bitmap = WatchUi.loadResource(Rez.Drawables.FortyFiveUpB);
break;
case "FortyFiveDown":
bitmap = WatchUi.loadResource(Rez.Drawables.FortyFiveDownB);
break;
case "DoubleUp":
case "TripleUp":
bitmap = WatchUi.loadResource(Rez.Drawables.DoubleUpB);
break;
case "DoubleDown":
case "TripleDown":
bitmap = WatchUi.loadResource(Rez.Drawables.DoubleDownB);
break;
default: break;
}

return bitmap;
} else {
return bitmap;
}

}

function getDirection(status) as BitmapType {
var bitmap = WatchUi.loadResource(Rez.Drawables.Unknown);
if (status instanceof Dictionary) {
var trend = status["trendRaw"] as String;
if (trend == null) {
return bitmap;
}

switch (trend) {
case "Flat":
bitmap = WatchUi.loadResource(Rez.Drawables.Flat);
break;
case "SingleUp":
bitmap = WatchUi.loadResource(Rez.Drawables.SingleUp);
break;
case "SingleDown":
bitmap = WatchUi.loadResource(Rez.Drawables.SingleDown);
break;
case "FortyFiveUp":
bitmap = WatchUi.loadResource(Rez.Drawables.FortyFiveUp);
break;
case "FortyFiveDown":
bitmap = WatchUi.loadResource(Rez.Drawables.FortyFiveDown);
break;
case "DoubleUp":
case "TripleUp":
bitmap = WatchUi.loadResource(Rez.Drawables.DoubleUp);
break;
case "DoubleDown":
case "TripleDown":
bitmap = WatchUi.loadResource(Rez.Drawables.DoubleDown);
break;
default: break;
}

return bitmap;
} else {
return bitmap;
}

}


}

0 comments on commit ec3b8dc

Please sign in to comment.