diff options
Diffstat (limited to 'src/displayapp')
| -rw-r--r-- | src/displayapp/DisplayApp.cpp | 27 | ||||
| -rw-r--r-- | src/displayapp/screens/NotificationIcon.cpp | 10 | ||||
| -rw-r--r-- | src/displayapp/screens/NotificationIcon.h | 12 | ||||
| -rw-r--r-- | src/displayapp/screens/Notifications.cpp | 290 | ||||
| -rw-r--r-- | src/displayapp/screens/Notifications.h | 84 |
5 files changed, 422 insertions, 1 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 8f6ab6e..e7b3416 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -10,6 +10,7 @@ #include "displayapp/screens/Clock.h" #include "displayapp/screens/FirmwareUpdate.h" #include "displayapp/screens/FirmwareValidation.h" +#include "displayapp/screens/Notifications.h" #include "displayapp/screens/Tile.h" #include "displayapp/screens/Error.h" @@ -141,6 +142,9 @@ void DisplayApp::Refresh() { // clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : // Screens::Clock::BleConnectionStates::NotConnected); break; + case Messages::NewNotification: + LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down); + break; case Messages::TouchEvent: { if (state != States::Running) { break; @@ -155,6 +159,9 @@ void DisplayApp::Refresh() { case TouchEvents::SwipeUp: LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); break; + case TouchEvents::SwipeDown: + LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + break; case TouchEvents::SwipeRight: LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim); break; @@ -177,7 +184,9 @@ void DisplayApp::Refresh() { break; case Messages::ButtonLongPressed: if (currentApp != Apps::Clock) { - if (currentApp == Apps::QuickSettings) { + if (currentApp == Apps::Notifications) { + LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::Up); + } else if (currentApp == Apps::QuickSettings) { LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::LeftAnim); } else { LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::Down); @@ -188,6 +197,12 @@ void DisplayApp::Refresh() { // Open up Firmware window, before possible reboot if press continues LoadApp(Apps::FirmwareValidation, DisplayApp::FullRefreshDirections::Up); break; + case Messages::ButtonDoubleClicked: + if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) { + LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + } + break; + case Messages::BleFirmwareUpdateStarted: LoadApp(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down); break; @@ -259,6 +274,16 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique<Screens::FirmwareUpdate>(this, bleController); ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); break; + case Apps::Notifications: + currentScreen = std::make_unique<Screens::Notifications>( + this, notificationManager, systemTask->nimble().alertService(), motorController, *systemTask, Screens::Notifications::Modes::Normal); + ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp); + break; + case Apps::NotificationsPreview: + currentScreen = std::make_unique<Screens::Notifications>( + this, notificationManager, systemTask->nimble().alertService(), motorController, *systemTask, Screens::Notifications::Modes::Preview); + ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp); + break; // Settings case Apps::QuickSettings: currentScreen = std::make_unique<Screens::QuickSettings>( diff --git a/src/displayapp/screens/NotificationIcon.cpp b/src/displayapp/screens/NotificationIcon.cpp new file mode 100644 index 0000000..0e913ae --- /dev/null +++ b/src/displayapp/screens/NotificationIcon.cpp @@ -0,0 +1,10 @@ +#include "displayapp/screens/NotificationIcon.h" +#include "displayapp/screens/Symbols.h" +using namespace Pinetime::Applications::Screens; + +const char* NotificationIcon::GetIcon(bool newNotificationAvailable) { + if (newNotificationAvailable) + return Symbols::info; + else + return ""; +}
\ No newline at end of file diff --git a/src/displayapp/screens/NotificationIcon.h b/src/displayapp/screens/NotificationIcon.h new file mode 100644 index 0000000..dc34c3f --- /dev/null +++ b/src/displayapp/screens/NotificationIcon.h @@ -0,0 +1,12 @@ +#pragma once + +namespace Pinetime { + namespace Applications { + namespace Screens { + class NotificationIcon { + public: + static const char* GetIcon(bool newNotificationAvailable); + }; + } + } +}
\ No newline at end of file diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp new file mode 100644 index 0000000..81ee234 --- /dev/null +++ b/src/displayapp/screens/Notifications.cpp @@ -0,0 +1,290 @@ +#include "displayapp/screens/Notifications.h" +#include "displayapp/DisplayApp.h" +#include "components/ble/AlertNotificationService.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +Notifications::Notifications(DisplayApp* app, + Pinetime::Controllers::NotificationManager& notificationManager, + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController, + System::SystemTask& systemTask, + Modes mode) + : Screen(app), + notificationManager {notificationManager}, + alertNotificationService {alertNotificationService}, + motorController {motorController}, + systemTask {systemTask}, + mode {mode} { + notificationManager.ClearNewNotificationFlag(); + auto notification = notificationManager.GetLastNotification(); + if (notification.valid) { + currentId = notification.id; + currentItem = std::make_unique<NotificationItem>(notification.Title(), + notification.Message(), + notification.index, + notification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService, + motorController); + validDisplay = true; + } else { + currentItem = std::make_unique<NotificationItem>("Notification", + "No notification to display", + 0, + notification.category, + notificationManager.NbNotifications(), + Modes::Preview, + alertNotificationService, + motorController); + } + + if (mode == Modes::Preview) { + if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) { + motorController.StartRinging(); + } else { + motorController.RunForDuration(35); + } + + timeoutLine = lv_line_create(lv_scr_act(), nullptr); + + lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); + + lv_line_set_points(timeoutLine, timeoutLinePoints, 2); + timeoutTickCountStart = xTaskGetTickCount(); + interacted = false; + } + + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); +} + +Notifications::~Notifications() { + lv_task_del(taskRefresh); + // make sure we stop any vibrations before exiting + motorController.StopRinging(); + lv_obj_clean(lv_scr_act()); +} + +void Notifications::Refresh() { + if (mode == Modes::Preview && timeoutLine != nullptr) { + TickType_t tick = xTaskGetTickCount(); + int32_t pos = 240 - ((tick - timeoutTickCountStart) / (timeoutLength / 240)); + if (pos <= 0) { + running = false; + } else { + timeoutLinePoints[1].x = pos; + lv_line_set_points(timeoutLine, timeoutLinePoints, 2); + } + } + running = currentItem->IsRunning() && running; +} + +void Notifications::OnPreviewInteraction() { + motorController.StopRinging(); + if (timeoutLine != nullptr) { + lv_obj_del(timeoutLine); + timeoutLine = nullptr; + } +} + +bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + if (mode != Modes::Normal) { + if (!interacted && event == TouchEvents::Tap) { + interacted = true; + OnPreviewInteraction(); + return true; + } + return false; + } + + switch (event) { + case Pinetime::Applications::TouchEvents::SwipeDown: { + Controllers::NotificationManager::Notification previousNotification; + if (validDisplay) + previousNotification = notificationManager.GetPrevious(currentId); + else + previousNotification = notificationManager.GetLastNotification(); + + if (!previousNotification.valid) + return true; + + validDisplay = true; + currentId = previousNotification.id; + currentItem.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); + currentItem = std::make_unique<NotificationItem>(previousNotification.Title(), + previousNotification.Message(), + previousNotification.index, + previousNotification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService, + motorController); + } + return true; + case Pinetime::Applications::TouchEvents::SwipeUp: { + Controllers::NotificationManager::Notification nextNotification; + if (validDisplay) + nextNotification = notificationManager.GetNext(currentId); + else + nextNotification = notificationManager.GetLastNotification(); + + if (!nextNotification.valid) { + running = false; + return false; + } + + validDisplay = true; + currentId = nextNotification.id; + currentItem.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); + currentItem = std::make_unique<NotificationItem>(nextNotification.Title(), + nextNotification.Message(), + nextNotification.index, + nextNotification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService, + motorController); + } + return true; + default: + return false; + } +} + +namespace { + void CallEventHandler(lv_obj_t* obj, lv_event_t event) { + auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data); + item->OnCallButtonEvent(obj, event); + } +} + +Notifications::NotificationItem::NotificationItem(const char* title, + const char* msg, + uint8_t notifNr, + Controllers::NotificationManager::Categories category, + uint8_t notifNb, + Modes mode, + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController) + : mode {mode}, alertNotificationService {alertNotificationService}, motorController {motorController} { + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); + + lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222)); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 0, 50); + lv_obj_set_size(container1, LV_HOR_RES, 190); + + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + lv_cont_set_fit(container1, LV_FIT_NONE); + + lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb); + lv_obj_align(alert_count, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 16); + + lv_obj_t* alert_type = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x888888)); + if(title == nullptr) { + lv_label_set_text_static(alert_type, "Notification"); + } else { + // copy title to label and replace newlines with spaces + lv_label_set_text(alert_type, title); + char *pchar = strchr(lv_label_get_text(alert_type), '\n'); + while (pchar != nullptr) { + *pchar = ' '; + pchar = strchr(pchar + 1, '\n'); + } + lv_label_refr_text(alert_type); + } + lv_label_set_long_mode(alert_type, LV_LABEL_LONG_SROLL_CIRC); + lv_obj_set_width(alert_type, 180); + lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 16); + + ///////// + switch (category) { + default: { + lv_obj_t* alert_subject = lv_label_create(container1, nullptr); + lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); + lv_obj_set_width(alert_subject, LV_HOR_RES - 20); + lv_label_set_text(alert_subject, msg); + } break; + case Controllers::NotificationManager::Categories::IncomingCall: { + lv_obj_set_height(container1, 108); + lv_obj_t* alert_subject = lv_label_create(container1, nullptr); + lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); + lv_obj_set_width(alert_subject, LV_HOR_RES - 20); + lv_label_set_text(alert_subject, "Incoming call from"); + + lv_obj_t* alert_caller = lv_label_create(container1, nullptr); + lv_obj_align(alert_caller, alert_subject, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + lv_label_set_long_mode(alert_caller, LV_LABEL_LONG_BREAK); + lv_obj_set_width(alert_caller, LV_HOR_RES - 20); + lv_label_set_text(alert_caller, msg); + + bt_accept = lv_btn_create(lv_scr_act(), nullptr); + bt_accept->user_data = this; + lv_obj_set_event_cb(bt_accept, CallEventHandler); + lv_obj_set_size(bt_accept, 76, 76); + lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + label_accept = lv_label_create(bt_accept, nullptr); + lv_label_set_text(label_accept, Symbols::phone); + lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + + bt_reject = lv_btn_create(lv_scr_act(), nullptr); + bt_reject->user_data = this; + lv_obj_set_event_cb(bt_reject, CallEventHandler); + lv_obj_set_size(bt_reject, 76, 76); + lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + label_reject = lv_label_create(bt_reject, nullptr); + lv_label_set_text(label_reject, Symbols::phoneSlash); + lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + + bt_mute = lv_btn_create(lv_scr_act(), nullptr); + bt_mute->user_data = this; + lv_obj_set_event_cb(bt_mute, CallEventHandler); + lv_obj_set_size(bt_mute, 76, 76); + lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + label_mute = lv_label_create(bt_mute, nullptr); + lv_label_set_text(label_mute, Symbols::volumMute); + lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + } break; + } + + lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundLabel, 240, 240); + lv_obj_set_pos(backgroundLabel, 0, 0); + lv_label_set_text(backgroundLabel, ""); +} + +void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) { + if (event != LV_EVENT_CLICKED) { + return; + } + + motorController.StopRinging(); + + if (obj == bt_accept) { + alertNotificationService.AcceptIncomingCall(); + } else if (obj == bt_reject) { + alertNotificationService.RejectIncomingCall(); + } else if (obj == bt_mute) { + alertNotificationService.MuteIncomingCall(); + } + + running = false; +} + +Notifications::NotificationItem::~NotificationItem() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h new file mode 100644 index 0000000..7416035 --- /dev/null +++ b/src/displayapp/screens/Notifications.h @@ -0,0 +1,84 @@ +#pragma once + +#include <lvgl/lvgl.h> +#include <FreeRTOS.h> +#include <cstdint> +#include <memory> +#include "displayapp/screens/Screen.h" +#include "components/ble/NotificationManager.h" +#include "components/motor/MotorController.h" +#include "systemtask/SystemTask.h" + +namespace Pinetime { + namespace Controllers { + class AlertNotificationService; + } + namespace Applications { + namespace Screens { + + class Notifications : public Screen { + public: + enum class Modes { Normal, Preview }; + explicit Notifications(DisplayApp* app, + Pinetime::Controllers::NotificationManager& notificationManager, + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController, + System::SystemTask& systemTask, + Modes mode); + ~Notifications() override; + + void Refresh() override; + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + void OnPreviewInteraction(); + + class NotificationItem { + public: + NotificationItem(const char* title, + const char* msg, + uint8_t notifNr, + Controllers::NotificationManager::Categories, + uint8_t notifNb, + Modes mode, + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController); + ~NotificationItem(); + bool IsRunning() const { + return running; + } + void OnCallButtonEvent(lv_obj_t*, lv_event_t event); + + private: + lv_obj_t* container1; + lv_obj_t* bt_accept; + lv_obj_t* bt_mute; + lv_obj_t* bt_reject; + lv_obj_t* label_accept; + lv_obj_t* label_mute; + lv_obj_t* label_reject; + Modes mode; + Pinetime::Controllers::AlertNotificationService& alertNotificationService; + Pinetime::Controllers::MotorController& motorController; + bool running = true; + }; + + private: + Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::AlertNotificationService& alertNotificationService; + Pinetime::Controllers::MotorController& motorController; + System::SystemTask& systemTask; + Modes mode = Modes::Normal; + std::unique_ptr<NotificationItem> currentItem; + Controllers::NotificationManager::Notification::Id currentId; + bool validDisplay = false; + + lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}}; + lv_obj_t* timeoutLine = nullptr; + TickType_t timeoutTickCountStart; + static const TickType_t timeoutLength = pdMS_TO_TICKS(7000); + bool interacted = true; + + lv_task_t* taskRefresh; + }; + } + } +} |
