diff options
author | Rasmus Schenstrom <element_004@hotmail.com> | 2020-10-27 19:51:06 +0100 |
---|---|---|
committer | petter <39340152+petterhs@users.noreply.github.com> | 2021-01-21 23:15:29 +0100 |
commit | 10ba20876f37c8e18307dfbc8d06d70bb94d5fae (patch) | |
tree | 18d4a9d143162420452be53ee27fa8370ce465cc /src/displayapp | |
parent | 7e27bc873315589ae4076780607720aa5278c5a1 (diff) |
Add incoming call functionality
Add categories to AlertNotification
Add new alert notification screens bases
Add Incoming Call
Add Modal
Add event to AlertNotification
Co-authored-by: Robin Karlsson <robin.karlsson@protonmail.com>
Diffstat (limited to 'src/displayapp')
-rw-r--r-- | src/displayapp/DisplayApp.cpp | 3 | ||||
-rw-r--r-- | src/displayapp/DisplayApp.h | 2 | ||||
-rw-r--r-- | src/displayapp/screens/Modal.cpp | 50 | ||||
-rw-r--r-- | src/displayapp/screens/Modal.h | 11 |
4 files changed, 53 insertions, 13 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index b6ad90b4..879b5f22 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -128,6 +128,9 @@ void DisplayApp::Refresh() { } } break; + case Messages::NewCall: + modal->NewNotification(notificationManager, &systemTask.nimble().alertService()); + break; case Messages::TouchEvent: { if (state != States::Running) break; auto gesture = OnTouchEvent(); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index da5a7b22..b79df51a 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -34,7 +34,7 @@ namespace Pinetime { public: enum class States {Idle, Running}; enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, ButtonPushed, - NewNotification, BleFirmwareUpdateStarted }; + NewNotification, NewCall, BleFirmwareUpdateStarted }; enum class FullRefreshDirections { None, Up, Down }; enum class TouchModes { Gestures, Polling }; 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; |