From d0f776b44cf5bab2b4be0b727e16297df65c323e Mon Sep 17 00:00:00 2001 From: JustScott Date: Wed, 10 Jan 2024 22:32:01 -0600 Subject: [PATCH 1/4] Add a new Calendar App A basic calendar app that shows all the days dates in the current month along with the correlating week days, highlights the current day, and allows swiping left and right to increase and decrease the current month by one. Co-authored-by: thnikk Co-authored-by: Boteium --- src/CMakeLists.txt | 1 + src/displayapp/DisplayApp.cpp | 1 + src/displayapp/apps/Apps.h.in | 1 + src/displayapp/apps/CMakeLists.txt | 1 + src/displayapp/fonts/fonts.json | 2 +- src/displayapp/screens/Calendar.cpp | 88 +++++++++++++++++++++++++++++ src/displayapp/screens/Calendar.h | 42 ++++++++++++++ src/displayapp/screens/Symbols.h | 1 + 8 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/displayapp/screens/Calendar.cpp create mode 100644 src/displayapp/screens/Calendar.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd8ece62..21413bdb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -377,6 +377,7 @@ list(APPEND SOURCE_FILES displayapp/screens/FirmwareUpdate.cpp displayapp/screens/Music.cpp displayapp/screens/Navigation.cpp + displayapp/screens/Calendar.cpp displayapp/screens/Metronome.cpp displayapp/screens/Motion.cpp displayapp/screens/Weather.cpp diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 9c7d87b2..adfa6171 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -19,6 +19,7 @@ #include "displayapp/screens/Metronome.h" #include "displayapp/screens/Music.h" #include "displayapp/screens/Navigation.h" +#include "displayapp/screens/Calendar.h" #include "displayapp/screens/Notifications.h" #include "displayapp/screens/SystemInfo.h" #include "displayapp/screens/Tile.h" diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index 2104a267..9fa4843a 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -23,6 +23,7 @@ namespace Pinetime { Twos, HeartRate, Navigation, + Calendar, StopWatch, Metronome, Motion, diff --git a/src/displayapp/apps/CMakeLists.txt b/src/displayapp/apps/CMakeLists.txt index d7858760..99b0a936 100644 --- a/src/displayapp/apps/CMakeLists.txt +++ b/src/displayapp/apps/CMakeLists.txt @@ -14,6 +14,7 @@ else () set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation") set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather") + set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Calendar") #set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion") set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware") endif () diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index 41c383c0..b88af94f 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -7,7 +7,7 @@ }, { "file": "FontAwesome5-Solid+Brands+Regular.woff", - "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743" + "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf073" } ], "bpp": 1, diff --git a/src/displayapp/screens/Calendar.cpp b/src/displayapp/screens/Calendar.cpp new file mode 100644 index 00000000..e466ac4a --- /dev/null +++ b/src/displayapp/screens/Calendar.cpp @@ -0,0 +1,88 @@ +#include "displayapp/screens/Calendar.h" +#include "components/datetime/DateTimeController.h" + +using namespace Pinetime::Applications::Screens; + +Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} { + + // Create calendar object + calendar = lv_calendar_create(lv_scr_act(), NULL); + // Set size + lv_obj_set_size(calendar, LV_HOR_RES, LV_VER_RES); + // Set alignment + lv_obj_align(calendar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5); + // Disable clicks + lv_obj_set_click(calendar, false); + + // Set background of today's date + /* + lv_obj_set_style_local_bg_opa(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_OPA_COVER); + lv_obj_set_style_local_bg_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_WHITE); + lv_obj_set_style_local_radius(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, 3); + */ + + // Set style of today's date + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_RED); + + // Set style of inactive month's days + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050)); + + // Get today's date + today.year = static_cast(dateTimeController.Year()); + today.month = static_cast(dateTimeController.Month()); + today.day = static_cast(dateTimeController.Day()); + + // Set today's date + lv_calendar_set_today_date(calendar, &today); + lv_calendar_set_showed_date(calendar, &today); + + // Use today's date as a reference for which month to show if moved + current = today; + +} + +bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + switch (event) { + case TouchEvents::SwipeLeft: { + if (current.month == 12) { + current.month = 1; + current.year++; + } + else{ + current.month++; + } + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + case TouchEvents::SwipeRight: { + if (current.month == 1) { + current.month = 12; + current.year--; + } + else{ + current.month--; + } + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + /* + case TouchEvents::SwipeUp: { + current.year++; + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + case TouchEvents::SwipeDown: { + current.year--; + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + */ + default: { + return false; + } + } +} + +Calendar::~Calendar() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/Calendar.h b/src/displayapp/screens/Calendar.h new file mode 100644 index 00000000..ab5facfb --- /dev/null +++ b/src/displayapp/screens/Calendar.h @@ -0,0 +1,42 @@ +#pragma once + +#include "displayapp/apps/Apps.h" +#include "displayapp/Controllers.h" +#include "displayapp/screens/Screen.h" +#include "components/datetime/DateTimeController.h" +#include + +#include "Symbols.h" + +namespace Pinetime { + namespace Controllers { + class Settings; + } + + namespace Applications { + namespace Screens { + class Calendar : public Screen { + public: + Calendar(Controllers::DateTime& dateTimeController); + ~Calendar() override; + private: + bool OnTouchEvent(TouchEvents event); + Controllers::DateTime& dateTimeController; + lv_obj_t* label_time; + lv_obj_t * calendar; + lv_calendar_date_t today; + lv_calendar_date_t current; + }; + } + + template <> + struct AppTraits { + static constexpr Apps app = Apps::Calendar; + static constexpr const char* icon = Screens::Symbols::calendar; + + static Screens::Screen* Create(AppControllers& controllers) { + return new Screens::Calendar(controllers.dateTimeController); + }; + }; + } +} diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index bd958b28..e48b4336 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -39,6 +39,7 @@ namespace Pinetime { static constexpr const char* eye = "\xEF\x81\xAE"; static constexpr const char* home = "\xEF\x80\x95"; static constexpr const char* sleep = "\xEE\xBD\x84"; + static constexpr const char* calendar = "\xEF\x81\xB3"; // fontawesome_weathericons.c // static constexpr const char* sun = "\xEF\x86\x85"; From 780e68f456678e6a31c7cb47b621dd3ddec569be Mon Sep 17 00:00:00 2001 From: JustScott Date: Thu, 11 Jan 2024 10:58:05 -0600 Subject: [PATCH 2/4] Removed unused variables, some of the commented out code, and added a license copyright notice to the source and header calendar files. --- src/displayapp/screens/Calendar.cpp | 41 ++++++++++++++++++----------- src/displayapp/screens/Calendar.h | 22 +++++++++++++--- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/displayapp/screens/Calendar.cpp b/src/displayapp/screens/Calendar.cpp index e466ac4a..837970e4 100644 --- a/src/displayapp/screens/Calendar.cpp +++ b/src/displayapp/screens/Calendar.cpp @@ -1,3 +1,21 @@ +/* Copyright (C) 2024 thnikk, Boteium, JustScott + + This file is part of InfiniTime. + + InfiniTime is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + InfiniTime is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #include "displayapp/screens/Calendar.h" #include "components/datetime/DateTimeController.h" @@ -14,13 +32,6 @@ Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeControll // Disable clicks lv_obj_set_click(calendar, false); - // Set background of today's date - /* - lv_obj_set_style_local_bg_opa(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_OPA_COVER); - lv_obj_set_style_local_bg_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_WHITE); - lv_obj_set_style_local_radius(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, 3); - */ - // Set style of today's date lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_RED); @@ -28,17 +39,13 @@ Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeControll lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050)); // Get today's date - today.year = static_cast(dateTimeController.Year()); - today.month = static_cast(dateTimeController.Month()); - today.day = static_cast(dateTimeController.Day()); + current.year = static_cast(dateTimeController.Year()); + current.month = static_cast(dateTimeController.Month()); + current.day = static_cast(dateTimeController.Day()); // Set today's date - lv_calendar_set_today_date(calendar, &today); - lv_calendar_set_showed_date(calendar, &today); - - // Use today's date as a reference for which month to show if moved - current = today; - + lv_calendar_set_today_date(calendar, ¤t); + lv_calendar_set_showed_date(calendar, ¤t); } bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) { @@ -51,6 +58,7 @@ bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) { else{ current.month++; } + lv_calendar_set_showed_date(calendar, ¤t); return true; } @@ -62,6 +70,7 @@ bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) { else{ current.month--; } + lv_calendar_set_showed_date(calendar, ¤t); return true; } diff --git a/src/displayapp/screens/Calendar.h b/src/displayapp/screens/Calendar.h index ab5facfb..b20edd73 100644 --- a/src/displayapp/screens/Calendar.h +++ b/src/displayapp/screens/Calendar.h @@ -1,3 +1,21 @@ +/* Copyright (C) 2024 thnikk, Boteium, JustScott + + This file is part of InfiniTime. + + InfiniTime is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + InfiniTime is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #pragma once #include "displayapp/apps/Apps.h" @@ -22,9 +40,7 @@ namespace Pinetime { private: bool OnTouchEvent(TouchEvents event); Controllers::DateTime& dateTimeController; - lv_obj_t* label_time; - lv_obj_t * calendar; - lv_calendar_date_t today; + lv_obj_t* calendar; lv_calendar_date_t current; }; } From 0535e93848fce686edc041aa225bc1b2538eb8bb Mon Sep 17 00:00:00 2001 From: JustScott Date: Sun, 14 Jan 2024 10:15:13 -0600 Subject: [PATCH 3/4] Reformatted the code to comply with clang-format. --- src/displayapp/screens/Calendar.cpp | 116 ++++++++++++++-------------- src/displayapp/screens/Calendar.h | 3 +- 2 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/displayapp/screens/Calendar.cpp b/src/displayapp/screens/Calendar.cpp index 837970e4..fea69496 100644 --- a/src/displayapp/screens/Calendar.cpp +++ b/src/displayapp/screens/Calendar.cpp @@ -23,75 +23,73 @@ using namespace Pinetime::Applications::Screens; Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} { - // Create calendar object - calendar = lv_calendar_create(lv_scr_act(), NULL); - // Set size - lv_obj_set_size(calendar, LV_HOR_RES, LV_VER_RES); - // Set alignment - lv_obj_align(calendar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5); - // Disable clicks - lv_obj_set_click(calendar, false); + // Create calendar object + calendar = lv_calendar_create(lv_scr_act(), NULL); + // Set size + lv_obj_set_size(calendar, LV_HOR_RES, LV_VER_RES); + // Set alignment + lv_obj_align(calendar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5); + // Disable clicks + lv_obj_set_click(calendar, false); - // Set style of today's date - lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_RED); + // Set style of today's date + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_RED); - // Set style of inactive month's days - lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050)); + // Set style of inactive month's days + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050)); - // Get today's date - current.year = static_cast(dateTimeController.Year()); - current.month = static_cast(dateTimeController.Month()); - current.day = static_cast(dateTimeController.Day()); + // Get today's date + current.year = static_cast(dateTimeController.Year()); + current.month = static_cast(dateTimeController.Month()); + current.day = static_cast(dateTimeController.Day()); - // Set today's date - lv_calendar_set_today_date(calendar, ¤t); - lv_calendar_set_showed_date(calendar, ¤t); + // Set today's date + lv_calendar_set_today_date(calendar, ¤t); + lv_calendar_set_showed_date(calendar, ¤t); } bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - switch (event) { - case TouchEvents::SwipeLeft: { - if (current.month == 12) { - current.month = 1; - current.year++; - } - else{ - current.month++; - } + switch (event) { + case TouchEvents::SwipeLeft: { + if (current.month == 12) { + current.month = 1; + current.year++; + } else { + current.month++; + } - lv_calendar_set_showed_date(calendar, ¤t); - return true; - } - case TouchEvents::SwipeRight: { - if (current.month == 1) { - current.month = 12; - current.year--; - } - else{ - current.month--; - } - - lv_calendar_set_showed_date(calendar, ¤t); - return true; - } - /* - case TouchEvents::SwipeUp: { - current.year++; - lv_calendar_set_showed_date(calendar, ¤t); - return true; - } - case TouchEvents::SwipeDown: { - current.year--; - lv_calendar_set_showed_date(calendar, ¤t); - return true; - } - */ - default: { - return false; - } + lv_calendar_set_showed_date(calendar, ¤t); + return true; } + case TouchEvents::SwipeRight: { + if (current.month == 1) { + current.month = 12; + current.year--; + } else { + current.month--; + } + + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + /* + case TouchEvents::SwipeUp: { + current.year++; + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + case TouchEvents::SwipeDown: { + current.year--; + lv_calendar_set_showed_date(calendar, ¤t); + return true; + } + */ + default: { + return false; + } + } } Calendar::~Calendar() { - lv_obj_clean(lv_scr_act()); + lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/Calendar.h b/src/displayapp/screens/Calendar.h index b20edd73..bbdc8322 100644 --- a/src/displayapp/screens/Calendar.h +++ b/src/displayapp/screens/Calendar.h @@ -23,7 +23,7 @@ #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include - + #include "Symbols.h" namespace Pinetime { @@ -37,6 +37,7 @@ namespace Pinetime { public: Calendar(Controllers::DateTime& dateTimeController); ~Calendar() override; + private: bool OnTouchEvent(TouchEvents event); Controllers::DateTime& dateTimeController; From 577dfd5b8703969b1c42f14ac876ff2309c06cac Mon Sep 17 00:00:00 2001 From: JustScott Date: Mon, 22 Jan 2024 18:44:47 -0600 Subject: [PATCH 4/4] Updated the calendar to use colors from the InfiniTimeTheme.h's Colors namespace --- src/displayapp/InfiniTimeTheme.h | 1 + src/displayapp/screens/Calendar.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/displayapp/InfiniTimeTheme.h b/src/displayapp/InfiniTimeTheme.h index 0690b099..57680e87 100644 --- a/src/displayapp/InfiniTimeTheme.h +++ b/src/displayapp/InfiniTimeTheme.h @@ -8,6 +8,7 @@ namespace Colors { static constexpr lv_color_t green = LV_COLOR_MAKE(0x0, 0xb0, 0x0); static constexpr lv_color_t blue = LV_COLOR_MAKE(0x0, 0x50, 0xff); static constexpr lv_color_t lightGray = LV_COLOR_MAKE(0xb0, 0xb0, 0xb0); + static constexpr lv_color_t gray = LV_COLOR_MAKE(0x50, 0x50, 0x50); static constexpr lv_color_t bg = LV_COLOR_MAKE(0x5d, 0x69, 0x7e); static constexpr lv_color_t bgAlt = LV_COLOR_MAKE(0x38, 0x38, 0x38); diff --git a/src/displayapp/screens/Calendar.cpp b/src/displayapp/screens/Calendar.cpp index fea69496..43643f6c 100644 --- a/src/displayapp/screens/Calendar.cpp +++ b/src/displayapp/screens/Calendar.cpp @@ -18,6 +18,7 @@ #include "displayapp/screens/Calendar.h" #include "components/datetime/DateTimeController.h" +#include "displayapp/InfiniTimeTheme.h" using namespace Pinetime::Applications::Screens; @@ -33,10 +34,10 @@ Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeControll lv_obj_set_click(calendar, false); // Set style of today's date - lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_RED); + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, Colors::deepOrange); // Set style of inactive month's days - lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050)); + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, Colors::gray); // Get today's date current.year = static_cast(dateTimeController.Year());