diff options
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r-- | src/displayapp/screens/Modal.cpp | 50 | ||||
-rw-r--r-- | src/displayapp/screens/Modal.h | 11 | ||||
-rw-r--r-- | src/displayapp/screens/Notifications.cpp | 163 | ||||
-rw-r--r-- | src/displayapp/screens/Notifications.h | 58 | ||||
-rw-r--r-- | src/displayapp/screens/Symbols.h | 10 | ||||
-rw-r--r-- | src/displayapp/screens/Tile.cpp | 1 | ||||
-rw-r--r-- | src/displayapp/screens/Tile.h | 2 |
7 files changed, 236 insertions, 59 deletions
diff --git a/src/displayapp/screens/Modal.cpp b/src/displayapp/screens/Modal.cpp index d1a110ea..6d6768dc 100644 --- a/src/displayapp/screens/Modal.cpp +++ b/src/displayapp/screens/Modal.cpp @@ -6,10 +6,7 @@ using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; -Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app) { - - -} +Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app), alertNotificationService(nullptr) {} Modal::~Modal() { lv_obj_clean(lv_scr_act()); @@ -41,13 +38,46 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) { if(evt == LV_EVENT_DELETE && event_obj == mbox) { Hide(); } else if(evt == LV_EVENT_VALUE_CHANGED) { - /* A button was clicked */ - lv_mbox_start_auto_close(mbox, 0); -// Hide(); + if(event_obj == mbox) { + if(strcmp(lv_mbox_get_active_btn_text(event_obj), this->positiveButton.c_str()) == 0) { + if(alertNotificationService != nullptr) { + alertNotificationService->event(Pinetime::Controllers::AlertNotificationService::EVENT_ANSWER_CALL); + } + } else { + if(alertNotificationService != nullptr) { + alertNotificationService->event(Pinetime::Controllers::AlertNotificationService::EVENT_HANG_UP_CALL); + } + } + lv_mbox_start_auto_close(mbox, 0); + } } } -void Modal::Show(const char* msg) { +void Modal::NewNotification(Pinetime::Controllers::NotificationManager ¬ificationManager, Pinetime::Controllers::AlertNotificationService* alertService) { + alertNotificationService = alertService; + auto notification = notificationManager.GetLastNotification(); + std::string msg; + if(notification.valid) { + switch(notification.category) { + case Pinetime::Controllers::NotificationManager::Categories::IncomingCall: + this->positiveButton = "Answer"; + this->negativeButton = "Hang up"; + msg += "Incoming call from:\n"; + msg += notification.message.data(); + break; + default: + this->positiveButton = "Ok"; + this->negativeButton = "Cancel"; + msg = notification.message.data(); + break; + } + + static const char *btns[] = {this->positiveButton.c_str(), this->negativeButton.c_str(), ""}; + this->Show(msg.c_str(), btns); + } +} + +void Modal::Show(const char* msg, const char *btns[]) { if(isVisible) return; isVisible = true; lv_style_copy(&modal_style, &lv_style_plain_color); @@ -60,11 +90,9 @@ void Modal::Show(const char* msg) { lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES); lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */ - static const char * btns2[] = {"Ok", ""}; - /* Create the message box as a child of the modal background */ mbox = lv_mbox_create(obj, nullptr); - lv_mbox_add_btns(mbox, btns2); + lv_mbox_add_btns(mbox, btns); lv_mbox_set_text(mbox, msg); lv_obj_align(mbox, nullptr, LV_ALIGN_CENTER, 0, 0); lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); diff --git a/src/displayapp/screens/Modal.h b/src/displayapp/screens/Modal.h index 9cc177f0..de7575a8 100644 --- a/src/displayapp/screens/Modal.h +++ b/src/displayapp/screens/Modal.h @@ -3,6 +3,8 @@ #include "Screen.h" #include <lvgl/src/lv_core/lv_style.h> #include <lvgl/src/lv_core/lv_obj.h> +#include <components/ble/NotificationManager.h> +#include <components/ble/AlertNotificationService.h> namespace Pinetime { namespace Applications { @@ -13,7 +15,9 @@ namespace Pinetime { Modal(DisplayApp* app); ~Modal() override; - void Show(const char* msg); + + void NewNotification(Pinetime::Controllers::NotificationManager ¬ificationManager, Pinetime::Controllers::AlertNotificationService* alertService); + void Show(const char* msg, const char *btns[]); void Hide(); bool Refresh() override; @@ -23,6 +27,11 @@ namespace Pinetime { private: void OnEvent(lv_obj_t *event_obj, lv_event_t evt); + Pinetime::Controllers::AlertNotificationService* alertNotificationService = nullptr; + + std::string positiveButton; + std::string negativeButton; + lv_style_t modal_style; lv_obj_t *obj; lv_obj_t *mbox; diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index b481c972..c09562f3 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -1,23 +1,37 @@ #include "Notifications.h" #include <displayapp/DisplayApp.h> +#include "components/ble/MusicService.h" +#include "Symbols.h" using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; -Notifications::Notifications(DisplayApp *app, - Pinetime::Controllers::NotificationManager ¬ificationManager, - Modes mode) : - Screen(app), notificationManager{notificationManager}, mode{mode} { - +Notifications::Notifications(DisplayApp *app, + Pinetime::Controllers::NotificationManager ¬ificationManager, + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Modes mode) : + Screen(app), notificationManager{notificationManager}, alertNotificationService{alertNotificationService}, mode{mode} { notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); - - if(notification.valid) { currentId = notification.id; - currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", + notification.message.data(), + notification.index, + notification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService)); validDisplay = true; } else { - currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); + currentItem.reset(new NotificationItem("\nNotification", + "No notification to display", + 0, + notification.category, + notificationManager.NbNotifications(), + Modes::Preview, + alertNotificationService)); } if(mode == Modes::Preview) { @@ -73,7 +87,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = previousNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); - currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", + previousNotification.message.data(), + previousNotification.index, + previousNotification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService)); } return true; case Pinetime::Applications::TouchEvents::SwipeDown: { @@ -89,11 +109,17 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = nextNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); - currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", + nextNotification.message.data(), + nextNotification.index, + nextNotification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService)); } return true; case Pinetime::Applications::TouchEvents::LongTap: { - notificationManager.toggleVibrations(); + notificationManager.ToggleVibrations(); return true; } default: @@ -107,9 +133,31 @@ bool Notifications::OnButtonPushed() { return true; } +namespace { + static void AcceptIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { + auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data); + item->OnAcceptIncomingCall(event); + } + + static void MuteIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { + auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data); + item->OnMuteIncomingCall(event); + } + + static void RejectIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { + auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data); + item->OnRejectIncomingCall(event); + } +} -Notifications::NotificationItem::NotificationItem(const char *title, const char *msg, uint8_t notifNr, uint8_t notifNb, Modes mode) - : notifNr{notifNr}, notifNb{notifNb}, mode{mode} { +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) + : notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService} { container1 = lv_cont_create(lv_scr_act(), nullptr); static lv_style_t contStyle; lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); @@ -150,16 +198,68 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char auto titleHeight = lv_obj_get_height(t1); - l1 = lv_label_create(container1, nullptr); - lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); - lv_obj_set_pos(l1, textStyle.body.padding.left, - titleHeight + offscreenOffset + textStyle.body.padding.bottom + - textStyle.body.padding.top); + switch(category) { + default: { + l1 = lv_label_create(container1, nullptr); + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l1, textStyle.body.padding.left, + titleHeight + offscreenOffset + textStyle.body.padding.bottom + + textStyle.body.padding.top); + + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); + lv_label_set_text(l1, msg); + } + break; + case Controllers::NotificationManager::Categories::IncomingCall: { + l1 = lv_label_create(container1, nullptr); + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l1, textStyle.body.padding.left, + titleHeight + offscreenOffset + textStyle.body.padding.bottom + + textStyle.body.padding.top); + + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); + lv_label_set_text(l1, "Incoming call from "); + auto l1Height = lv_obj_get_height(l1); + + l2 = lv_label_create(container1, nullptr); + lv_label_set_style(l2, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l2, textStyle.body.padding.left, + titleHeight + l1Height + offscreenOffset + (textStyle.body.padding.bottom*2) + + (textStyle.body.padding.top*2)); + lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l2, true); + lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); + lv_label_set_text(l2, msg); + + bt_accept = lv_btn_create(container1, nullptr); + bt_accept->user_data = this; + lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler); + lv_obj_set_size(bt_accept, LV_HOR_RES / 3, 80); + lv_obj_align(bt_accept, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, -20); + label_accept = lv_label_create(bt_accept, nullptr); + lv_label_set_text(label_accept, Symbols::phone); - lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l1, true); - lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); - lv_label_set_text(l1, msg); + bt_reject = lv_btn_create(container1, nullptr); + bt_reject->user_data = this; + lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler); + lv_obj_set_size(bt_reject, LV_HOR_RES / 3, 80); + lv_obj_align(bt_reject, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, -20); + label_reject = lv_label_create(bt_reject, nullptr); + lv_label_set_text(label_reject, Symbols::phoneSlash); + + bt_mute = lv_btn_create(container1, nullptr); + bt_mute->user_data = this; + lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler); + lv_obj_set_size(bt_mute, LV_HOR_RES / 3, 80); + lv_obj_align(bt_mute, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -20); + label_mute = lv_label_create(bt_mute, nullptr); + lv_label_set_text(label_mute, Symbols::volumMute); + } + } if(mode == Modes::Normal) { if(notifNr < notifNb) { @@ -174,6 +274,23 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char } } +void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) { + if (event != LV_EVENT_CLICKED) return; + + alertNotificationService.AcceptIncomingCall(); +} + +void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) { + if (event != LV_EVENT_CLICKED) return; + + alertNotificationService.MuteIncomingCall(); +} + +void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) { + if (event != LV_EVENT_CLICKED) return; + + alertNotificationService.RejectIncomingCall(); +} Notifications::NotificationItem::~NotificationItem() { lv_obj_clean(lv_scr_act()); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index b621b777..c40e7002 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -7,46 +7,62 @@ #include "components/ble/NotificationManager.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, - Modes mode); + explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::AlertNotificationService& alertNotificationService, Modes mode); ~Notifications() override; bool Refresh() override; bool OnButtonPushed() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + 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); + ~NotificationItem(); + bool Refresh() {return false;} + void OnAcceptIncomingCall(lv_event_t event); + void OnMuteIncomingCall(lv_event_t event); + void OnRejectIncomingCall(lv_event_t event); + private: - bool running = true; + uint8_t notifNr = 0; + uint8_t notifNb = 0; + char pageText[4]; - class NotificationItem { - public: - NotificationItem(const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb, Modes mode); - ~NotificationItem(); - bool Refresh() {return false;} - - private: - uint8_t notifNr = 0; - uint8_t notifNb = 0; - char pageText[4]; - - lv_obj_t* container1; - lv_obj_t* t1; - lv_obj_t* l1; - lv_obj_t* bottomPlaceholder; - Modes mode; - }; + lv_obj_t* container1; + lv_obj_t* t1; + lv_obj_t* l1; + lv_obj_t* l2; + 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; + lv_obj_t* bottomPlaceholder; + Modes mode; + Pinetime::Controllers::AlertNotificationService& alertNotificationService; + + + }; + + private: + bool running = true; struct NotificationData { const char* title; const char* text; }; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::AlertNotificationService& alertNotificationService; Modes mode = Modes::Normal; std::unique_ptr<NotificationItem> currentItem; Controllers::NotificationManager::Notification::Id currentId; diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index bd6a0f90..1a6bbd7f 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -26,6 +26,16 @@ namespace Pinetime { static constexpr const char* paintbrush = "\xEF\x87\xBC"; static constexpr const char* paddle = "\xEF\x91\x9D"; static constexpr const char* map = "\xEF\x96\xa0"; + static constexpr const char* qrcode = "\xEF\x80\xa9"; + static constexpr const char* phone = "\xEF\x82\x95"; + static constexpr const char* phoneSlash = "\xEF\x8F\x9D"; + static constexpr const char* volumMute = "\xEF\x9A\xA9"; + static constexpr const char* volumUp = "\xEF\x80\xA8"; + static constexpr const char* volumDown = "\xEF\x80\xA7"; + static constexpr const char* stepForward = "\xEF\x81\x91"; + static constexpr const char* stepBackward = "\xEF\x81\x88"; + static constexpr const char* play = "\xEF\x81\x8B"; + static constexpr const char* pause = "\xEF\x81\x8C"; } } } diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index c1a5e94f..214d2736 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -22,7 +22,6 @@ Tile::Tile(DisplayApp* app, std::array<Applications, 6>& applications) : Screen( appIndex++; } } - modal.reset(new Modal(app)); btnm1 = lv_btnm_create(lv_scr_act(), nullptr); lv_btnm_set_map(btnm1, btnm_map1); diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index 7edf67b2..bf3f5d67 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -29,8 +29,6 @@ namespace Pinetime { lv_obj_t * btnm1; bool running = true; - std::unique_ptr<Modal> modal; - const char* btnm_map1[8]; Pinetime::Applications::Apps apps[6]; }; |