Skip to content

Commit

Permalink
feat: add time gauge customisation options
Browse files Browse the repository at this point in the history
  • Loading branch information
Antvirf committed Oct 22, 2022
1 parent 236d7be commit cb79f42
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 5 deletions.
34 changes: 34 additions & 0 deletions resources/settings/options_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

def generate_options_and_case_code():
xml = """"""
monkey = """"""

start_hr = 13
end_hr = 23

cnt = 0
for hours in range(start_hr, end_hr, 1):
for minutes in range(0, 60, 30):
if len(str(hours)) == 1:
hours = "0"+str(hours)
if len(str(minutes)) == 1:
minutes = "0"+str(minutes)
value = str(hours)+str(minutes)
value_start = value[:2]
if value_start.startswith("0"):
value_start = value_start[1]
value_end = value[-2:].replace("00", "0")

xml += f'<listEntry value="{cnt}">"{value}"</listEntry>' + "\n"
monkey += f"""case {cnt}:
return [{value_start},{value_end}];\n"""

cnt += 1

print(xml)
print()
print(monkey)


if __name__ == "__main__":
generate_options_and_case_code()
2 changes: 2 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<property id="UseMilitaryFormat" type="boolean">true</property>
<property id="DateInfoFirst" type="number">0</property>
<property id="DateInfoSecond" type="number">1</property>
<property id="TimeGaugeStartValue" type="number">1</property>
<property id="TimeGaugeEndValue" type="number">10</property>
</properties>
43 changes: 43 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,47 @@
<listEntry value="3">"ddd (e.g. Mon): Day of week, text"</listEntry>
</settingConfig>
</setting>

<setting propertyKey="@Properties.TimeGaugeStartValue" title="@Strings.TimeGaugeStartString">
<settingConfig type="list">
<listEntry value="0">"0600"</listEntry>
<listEntry value="1">"0630"</listEntry>
<listEntry value="2">"0700"</listEntry>
<listEntry value="3">"0730"</listEntry>
<listEntry value="4">"0800"</listEntry>
<listEntry value="5">"0830"</listEntry>
<listEntry value="6">"0900"</listEntry>
<listEntry value="7">"0930"</listEntry>
<listEntry value="8">"1000"</listEntry>
<listEntry value="9">"1030"</listEntry>
<listEntry value="10">"1100"</listEntry>
<listEntry value="11">"1130"</listEntry>
<listEntry value="12">"1200"</listEntry>
</settingConfig>
</setting>

<setting propertyKey="@Properties.TimeGaugeEndValue" title="@Strings.TimeGaugeEndString">
<settingConfig type="list">
<listEntry value="0">"1300"</listEntry>
<listEntry value="1">"1330"</listEntry>
<listEntry value="2">"1400"</listEntry>
<listEntry value="3">"1430"</listEntry>
<listEntry value="4">"1500"</listEntry>
<listEntry value="5">"1530"</listEntry>
<listEntry value="6">"1600"</listEntry>
<listEntry value="7">"1630"</listEntry>
<listEntry value="8">"1700"</listEntry>
<listEntry value="9">"1730"</listEntry>
<listEntry value="10">"1800"</listEntry>
<listEntry value="11">"1830"</listEntry>
<listEntry value="12">"1900"</listEntry>
<listEntry value="13">"1930"</listEntry>
<listEntry value="14">"2000"</listEntry>
<listEntry value="15">"2030"</listEntry>
<listEntry value="16">"2100"</listEntry>
<listEntry value="17">"2130"</listEntry>
<listEntry value="18">"2200"</listEntry>
<listEntry value="19">"2230"</listEntry>
</settingConfig>
</setting>
</settings>
2 changes: 2 additions & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<string id="MilitaryFormatTitle">Military Format for 24 Hour Time</string>
<string id="DateInfoFirstString">1st date field</string>
<string id="DateInfoSecondString">2nd date field</string>
<string id="TimeGaugeStartString">Start time for daylight gauge</string>
<string id="TimeGaugeEndString">End time for daylight gauge</string>
</strings>
105 changes: 100 additions & 5 deletions source/mattermetricsView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,96 @@ class mattermetricsView extends WatchUi.WatchFace {
return Lang.format("$1$", [longInfo.day_of_week]);
}
}

// Get corresponding start time value, given app setting
private function getStartTimeValue(dc as Dc, option as Number) as Array<Number>{
switch (option){
case 0:
return [6,0];
case 1:
return [6,30];
case 2:
return [7,0];
case 3:
return [7,30];
case 4:
return [8,0];
case 5:
return [8,30];
case 6:
return [9,0];
case 7:
return [9,30];
case 8:
return [10,0];
case 9:
return [10,30];
case 10:
return [11,0];
case 11:
return [11,30];
case 12:
return [12,0];
case 13:
return [12,30];
}
}

// Get corresponding end time value, given app setting
private function getEndTimeValue(dc as Dc, option as Number) as Array<Number>{
switch (option){
case 0:
return [13,0];
case 1:
return [13,30];
case 2:
return [14,0];
case 3:
return [14,30];
case 4:
return [15,0];
case 5:
return [15,30];
case 6:
return [16,0];
case 7:
return [16,30];
case 8:
return [17,0];
case 9:
return [17,30];
case 10:
return [18,0];
case 11:
return [18,30];
case 12:
return [19,0];
case 13:
return [19,30];
case 14:
return [20,0];
case 15:
return [20,30];
case 16:
return [21,0];
case 17:
return [21,30];
case 18:
return [22,0];
case 19:
return [22,30];
}
}

// Convert timevalue arrays into a nicely formatted string
private function prettifyTimeArray(input as Array<Number>) as String {
if (getApp().getProperty("UseMilitaryFormat")) {
return input[0].format("%02d") + input[1].format("%02d");
} else {
return input[0].format("%02d") + ":" + input[1].format("%02d");
}
}

// Draw gauge function
private function drawGauge(
dc as Dc,
Expand Down Expand Up @@ -211,10 +301,15 @@ class mattermetricsView extends WatchUi.WatchFace {

// Draw sunrise and sunset
// Define start and end times
var startHour = 6;
var startMin = 15;
var endHour = 18;
var endMin = 30;
var timeStart = getStartTimeValue(dc, Application.getApp().Properties.getValue("TimeGaugeStartValue"));
var timeEnd = getEndTimeValue(dc, Application.getApp().Properties.getValue("TimeGaugeEndValue"));
var prettyStartTime = prettifyTimeArray(timeStart);
var prettyEndTime = prettifyTimeArray(timeEnd);

var startHour = timeStart[0]; //6;
var startMin = timeStart[1]; //15;
var endHour = timeEnd[0]; //18;
var endMin = timeEnd[1]; //30;

// Compute total time difference in minutes
var timeDiffTotal = (endHour-startHour)*60 +(endMin-startMin);
Expand All @@ -229,7 +324,7 @@ class mattermetricsView extends WatchUi.WatchFace {
}

//var timeAmount = clockTime.hour*100.0 + clockTime.min/1.0;
drawGauge(dc, 10, 4, 1, 0.0, timeDiffTotal.toFloat(), timeDiffCurrent.toFloat(), ["0615", "1830", ""]);
drawGauge(dc, 10, 4, 1, 0.0, timeDiffTotal.toFloat(), timeDiffCurrent.toFloat(), [prettyStartTime, prettyEndTime, ""]);
}

// Called when this View is removed from the screen. Save the
Expand Down

0 comments on commit cb79f42

Please sign in to comment.