Skip to content

Commit c5d47d6

Browse files
committed
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.
1 parent ecf2f56 commit c5d47d6

File tree

8 files changed

+136
-1
lines changed

8 files changed

+136
-1
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ list(APPEND SOURCE_FILES
377377
displayapp/screens/FirmwareUpdate.cpp
378378
displayapp/screens/Music.cpp
379379
displayapp/screens/Navigation.cpp
380+
displayapp/screens/Calendar.cpp
380381
displayapp/screens/Metronome.cpp
381382
displayapp/screens/Motion.cpp
382383
displayapp/screens/FirmwareValidation.cpp

src/displayapp/DisplayApp.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "displayapp/screens/Metronome.h"
2020
#include "displayapp/screens/Music.h"
2121
#include "displayapp/screens/Navigation.h"
22+
#include "displayapp/screens/Calendar.h"
2223
#include "displayapp/screens/Notifications.h"
2324
#include "displayapp/screens/SystemInfo.h"
2425
#include "displayapp/screens/Tile.h"

src/displayapp/apps/Apps.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Pinetime {
2323
Twos,
2424
HeartRate,
2525
Navigation,
26+
Calendar,
2627
StopWatch,
2728
Metronome,
2829
Motion,

src/displayapp/apps/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ else ()
1212
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Twos")
1313
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome")
1414
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
15+
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Calendar")
1516
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
1617
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
1718
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")

src/displayapp/fonts/fonts.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{
99
"file": "FontAwesome5-Solid+Brands+Regular.woff",
10-
"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, 0xf743"
10+
"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, 0xf743, 0xf073"
1111
}
1212
],
1313
"bpp": 1,

src/displayapp/screens/Calendar.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "displayapp/screens/Calendar.h"
2+
#include "components/datetime/DateTimeController.h"
3+
4+
using namespace Pinetime::Applications::Screens;
5+
6+
Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
7+
8+
// Create calendar object
9+
calendar = lv_calendar_create(lv_scr_act(), NULL);
10+
// Set size
11+
lv_obj_set_size(calendar, LV_HOR_RES, LV_VER_RES);
12+
// Set alignment
13+
lv_obj_align(calendar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
14+
// Disable clicks
15+
lv_obj_set_click(calendar, false);
16+
17+
// Set background of today's date
18+
/*
19+
lv_obj_set_style_local_bg_opa(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_OPA_COVER);
20+
lv_obj_set_style_local_bg_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_WHITE);
21+
lv_obj_set_style_local_radius(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, 3);
22+
*/
23+
24+
// Set style of today's date
25+
lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_RED);
26+
27+
// Set style of inactive month's days
28+
lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050));
29+
30+
// Get today's date
31+
today.year = static_cast<int>(dateTimeController.Year());
32+
today.month = static_cast<int>(dateTimeController.Month());
33+
today.day = static_cast<int>(dateTimeController.Day());
34+
35+
// Set today's date
36+
lv_calendar_set_today_date(calendar, &today);
37+
lv_calendar_set_showed_date(calendar, &today);
38+
39+
// Use today's date as a reference for which month to show if moved
40+
current = today;
41+
42+
}
43+
44+
bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
45+
switch (event) {
46+
case TouchEvents::SwipeLeft: {
47+
if (current.month == 12) {
48+
current.month = 1;
49+
current.year++;
50+
}
51+
else{
52+
current.month++;
53+
}
54+
lv_calendar_set_showed_date(calendar, &current);
55+
return true;
56+
}
57+
case TouchEvents::SwipeRight: {
58+
if (current.month == 1) {
59+
current.month = 12;
60+
current.year--;
61+
}
62+
else{
63+
current.month--;
64+
}
65+
lv_calendar_set_showed_date(calendar, &current);
66+
return true;
67+
}
68+
/*
69+
case TouchEvents::SwipeUp: {
70+
current.year++;
71+
lv_calendar_set_showed_date(calendar, &current);
72+
return true;
73+
}
74+
case TouchEvents::SwipeDown: {
75+
current.year--;
76+
lv_calendar_set_showed_date(calendar, &current);
77+
return true;
78+
}
79+
*/
80+
default: {
81+
return false;
82+
}
83+
}
84+
}
85+
86+
Calendar::~Calendar() {
87+
lv_obj_clean(lv_scr_act());
88+
}

src/displayapp/screens/Calendar.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
#include "displayapp/apps/Apps.h"
4+
#include "displayapp/Controllers.h"
5+
#include "displayapp/screens/Screen.h"
6+
#include "components/datetime/DateTimeController.h"
7+
#include <lvgl/lvgl.h>
8+
9+
#include "Symbols.h"
10+
11+
namespace Pinetime {
12+
namespace Controllers {
13+
class Settings;
14+
}
15+
16+
namespace Applications {
17+
namespace Screens {
18+
class Calendar : public Screen {
19+
public:
20+
Calendar(Controllers::DateTime& dateTimeController);
21+
~Calendar() override;
22+
private:
23+
bool OnTouchEvent(TouchEvents event);
24+
Controllers::DateTime& dateTimeController;
25+
lv_obj_t* label_time;
26+
lv_obj_t * calendar;
27+
lv_calendar_date_t today;
28+
lv_calendar_date_t current;
29+
};
30+
}
31+
32+
template <>
33+
struct AppTraits<Apps::Calendar> {
34+
static constexpr Apps app = Apps::Calendar;
35+
static constexpr const char* icon = Screens::Symbols::calendar;
36+
37+
static Screens::Screen* Create(AppControllers& controllers) {
38+
return new Screens::Calendar(controllers.dateTimeController);
39+
};
40+
};
41+
}
42+
}

src/displayapp/screens/Symbols.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Pinetime {
3737
static constexpr const char* eye = "\xEF\x81\xAE";
3838
static constexpr const char* home = "\xEF\x80\x95";
3939
static constexpr const char* sleep = "\xEE\xBD\x84";
40+
static constexpr const char* calendar = "\xEF\x81\xB3";
4041

4142
// fontawesome_weathericons.c
4243
// static constexpr const char* sun = "\xEF\x86\x85";

0 commit comments

Comments
 (0)