summaryrefslogtreecommitdiff
path: root/src/DisplayApp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DisplayApp')
-rw-r--r--src/DisplayApp/DisplayApp.cpp11
-rw-r--r--src/DisplayApp/DisplayApp.h7
-rw-r--r--src/DisplayApp/Screens/Modal.cpp37
-rw-r--r--src/DisplayApp/Screens/Modal.h3
4 files changed, 57 insertions, 1 deletions
diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp
index e7187f1d..2e07cbc5 100644
--- a/src/DisplayApp/DisplayApp.cpp
+++ b/src/DisplayApp/DisplayApp.cpp
@@ -38,6 +38,7 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd,
systemTask{systemTask} {
msgQueue = xQueueCreate(queueSize, itemSize);
onClockApp = true;
+ modal.reset(new Screens::Modal(this));
}
void DisplayApp::Start() {
@@ -103,6 +104,7 @@ void DisplayApp::Refresh() {
state = States::Running;
break;
case Messages::UpdateDateTime:
+// modal->Show();
break;
case Messages::UpdateBleConnection:
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected);
@@ -110,6 +112,15 @@ void DisplayApp::Refresh() {
case Messages::UpdateBatteryLevel:
// clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining());
break;
+ case Messages::NewNotification: {
+ Pinetime::Controllers::Ble::NotificationMessage notificationMessage;
+ if (bleController.PopNotification(notificationMessage)) {
+ std::string m {notificationMessage.message, notificationMessage.size};
+ modal->Show(m);
+ // TODO delete message
+ }
+ }
+ 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 04c82fee..ad817331 100644
--- a/src/DisplayApp/DisplayApp.h
+++ b/src/DisplayApp/DisplayApp.h
@@ -16,6 +16,7 @@
#include <date/date.h>
#include <DisplayApp/Screens/Clock.h>
#include <drivers/Watchdog.h>
+#include <DisplayApp/Screens/Modal.h>
#include "TouchEvents.h"
@@ -27,7 +28,9 @@ namespace Pinetime {
class DisplayApp {
public:
enum class States {Idle, Running};
- enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed};
+ enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed,
+ NewNotification
+ };
enum class FullRefreshDirections { None, Up, Down };
@@ -78,6 +81,8 @@ namespace Pinetime {
Apps nextApp = Apps::None;
bool onClockApp = false; // TODO find a better way to know that we should handle gestures and button differently for the Clock app.
Controllers::BrightnessController brightnessController;
+ std::unique_ptr<Screens::Modal> modal;
+
};
}
}
diff --git a/src/DisplayApp/Screens/Modal.cpp b/src/DisplayApp/Screens/Modal.cpp
index fc353c49..ec477b6e 100644
--- a/src/DisplayApp/Screens/Modal.cpp
+++ b/src/DisplayApp/Screens/Modal.cpp
@@ -26,6 +26,8 @@ bool Modal::OnButtonPushed() {
}
void Modal::Show() {
+ if(isVisible) return;
+ isVisible = true;
lv_style_copy(&modal_style, &lv_style_plain_color);
modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK;
modal_style.body.opa = LV_OPA_50;
@@ -63,6 +65,7 @@ void Modal::Hide() {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
+ isVisible = false;
}
void Modal::mbox_event_cb(lv_obj_t *obj, lv_event_t evt) {
@@ -79,3 +82,37 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) {
// Hide();
}
}
+
+void Modal::Show(const std::string& message) {
+ if(isVisible) return;
+ this->message = message;
+ isVisible = true;
+ lv_style_copy(&modal_style, &lv_style_plain_color);
+ modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK;
+ modal_style.body.opa = LV_OPA_50;
+
+ obj = lv_obj_create(lv_scr_act(), NULL);
+ lv_obj_set_style(obj, &modal_style);
+ lv_obj_set_pos(obj, 0, 0);
+ 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, NULL);
+ lv_mbox_add_btns(mbox, btns2);
+ lv_mbox_set_text(mbox, message.data());
+ lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
+ lv_obj_set_event_cb(mbox, Modal::mbox_event_cb);
+
+ mbox->user_data = this;
+
+ /* Fade the message box in with an animation */
+ lv_anim_t a;
+ lv_anim_init(&a);
+ lv_anim_set_time(&a, 500, 0);
+ lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER);
+ lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale);
+ lv_anim_create(&a);
+}
diff --git a/src/DisplayApp/Screens/Modal.h b/src/DisplayApp/Screens/Modal.h
index de287293..b13b5c60 100644
--- a/src/DisplayApp/Screens/Modal.h
+++ b/src/DisplayApp/Screens/Modal.h
@@ -23,6 +23,7 @@ namespace Pinetime {
~Modal() override;
void Show();
+ void Show(const std::string& message);
void Hide();
bool Refresh() override;
@@ -37,6 +38,8 @@ namespace Pinetime {
lv_obj_t *mbox;
lv_obj_t *info;
bool running = true;
+ bool isVisible = false;
+ std::string message;
};
}