Skip to content

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Radko Najman committed Oct 24, 2022
1 parent 8292202 commit 3634f87
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.7.1 (October 24, 2022)
* code optimization

# 1.7.0 (April 25, 2022)
* 64 colors support

Expand Down
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- 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="3">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.20">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.1">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down
2 changes: 1 addition & 1 deletion manifest.xml.beta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- 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="3">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.2">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.26">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down
2 changes: 1 addition & 1 deletion manifest.xml.prod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- 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="3">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.0">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.1">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down
13 changes: 0 additions & 13 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
<property id="dateFormat" type="number">1</property>
<property id="dateColor" type="number">0xAAAAAA</property>

<property id="arcsStyle" type="number">1</property>

<property id="hrColor" type="number">-999</property>
<property id="hrRefreshInterval" type="number">3</property>

Expand Down Expand Up @@ -208,10 +206,6 @@

<string id="off">- Off -</string>

<string id="arcsStyle">Indicators style</string>
<string id="arcsDecent">Classic</string>
<string id="arcsExtravagant">Extravagant (experimental)</string>

<string id="hrColor">Heart rate color (off or color)</string>
<string id="hrRefreshInterval">Heart rate refresh interval (seconds)</string>
<string id="hr1">1</string>
Expand Down Expand Up @@ -612,13 +606,6 @@
</settingConfig>
</setting>

<setting propertyKey="@Properties.arcsStyle" title="@Strings.arcsStyle">
<settingConfig type="list">
<listEntry value="1">@Strings.arcsDecent</listEntry>
<listEntry value="2">@Strings.arcsExtravagant</listEntry>
</settingConfig>
</setting>

<setting propertyKey="@Properties.oneColor" title="@Strings.oneColor">
<settingConfig type="list">
<listEntry value="-999">@Strings.off</listEntry>
Expand Down
35 changes: 14 additions & 21 deletions source/SmartArcsView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class SmartArcsView extends WatchUi.WatchFace {

//global variables
var isAwake = false;
var partialUpdatesAllowed = false;
var curClip;
var fullScreenRefresh;
var offscreenBuffer;
var offSettingFlag = -999;
var font = Graphics.FONT_TINY;
var needComputeConstants;
var lastMeasuredHR;
var powerSaverDrawn = false;
var sunArcsOffset;
Expand Down Expand Up @@ -117,9 +117,7 @@ class SmartArcsView extends WatchUi.WatchFace {
var sunsetColor;

function initialize() {
loadUserSettings();
WatchFace.initialize();
fullScreenRefresh = true;
}

//load resources here
Expand All @@ -136,6 +134,12 @@ class SmartArcsView extends WatchUi.WatchFace {
offscreenBuffer = null;
}

partialUpdatesAllowed = (Toybox.WatchUi.WatchFace has :onPartialUpdate);
loadUserSettings();
computeConstants(dc);
computeSunConstants();
fullScreenRefresh = true;

curClip = null;
}

Expand All @@ -161,13 +165,8 @@ class SmartArcsView extends WatchUi.WatchFace {

var deviceSettings = System.getDeviceSettings();

//compute what does not need to be computed on each update
if (needComputeConstants) {
computeConstants(dc);
}

//recompute sunrise/sunset constants every hour - to address new location when traveling
if (clockTime.min == 0) {
//recompute sunrise/sunset constants every hour - to address new location when traveling
computeSunConstants();
//not needed to get date on every refresh event
dateInfo = Gregorian.info(Time.today(), Time.FORMAT_MEDIUM);
Expand Down Expand Up @@ -235,7 +234,9 @@ class SmartArcsView extends WatchUi.WatchFace {
}
}

drawSun(targetDc);
if (locationLatitude != offSettingFlag) {
drawSun(targetDc);
}

if (ticks != null) {
drawTicks(targetDc);
Expand Down Expand Up @@ -284,7 +285,7 @@ class SmartArcsView extends WatchUi.WatchFace {
return;
}

if ((Toybox.WatchUi.WatchFace has :onPartialUpdate) && (hrColor != offSettingFlag || showSecondHand == 2)) {
if (partialUpdatesAllowed && (hrColor != offSettingFlag || showSecondHand == 2)) {
onPartialUpdate(dc);
}

Expand Down Expand Up @@ -414,9 +415,6 @@ class SmartArcsView extends WatchUi.WatchFace {
locationLatitude = app.getProperty("locationLatitude");
locationLongitude = app.getProperty("locationLongitude");

//ensure that constants will be pre-computed
needComputeConstants = true;

//ensure that screen will be refreshed when settings are changed
powerSaverDrawn = false;
}
Expand Down Expand Up @@ -490,11 +488,6 @@ class SmartArcsView extends WatchUi.WatchFace {
}

dateInfo = Gregorian.info(Time.today(), Time.FORMAT_MEDIUM);

computeSunConstants();

//constants pre-computed, doesn't need to be computed again
needComputeConstants = false;
}

function parsePowerSaverTime(time) {
Expand Down Expand Up @@ -1030,7 +1023,7 @@ class SmartArcsView extends WatchUi.WatchFace {
dc.setPenWidth(7);

//draw sunrise
if (sunriseColor != offSettingFlag && locationLatitude != offSettingFlag) {
if (sunriseColor != offSettingFlag) {
dc.setColor(sunriseColor, Graphics.COLOR_TRANSPARENT);
if (sunriseStartAngle > sunriseEndAngle) {
dc.drawArc(screenRadius, screenRadius, screenRadius - 17, Graphics.ARC_CLOCKWISE, sunriseStartAngle, sunriseEndAngle);
Expand All @@ -1040,7 +1033,7 @@ class SmartArcsView extends WatchUi.WatchFace {
}

//draw sunset
if (sunsetColor != offSettingFlag && locationLatitude != offSettingFlag) {
if (sunsetColor != offSettingFlag) {
dc.setColor(sunsetColor, Graphics.COLOR_TRANSPARENT);
if (sunsetStartAngle > sunsetEndAngle) {
dc.drawArc(screenRadius, screenRadius, screenRadius - sunArcsOffset, Graphics.ARC_CLOCKWISE, sunsetStartAngle, sunsetEndAngle);
Expand Down

0 comments on commit 3634f87

Please sign in to comment.