From 28bc4344193cda2936ff0f69ae51aa79a7840998 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 18 Oct 2020 17:35:36 +0200 Subject: [PATCH] [WIP] New notification app that uses software scrolling effect. --- src/CMakeLists.txt | 2 + src/displayapp/Apps.h | 2 +- src/displayapp/DisplayApp.cpp | 2 + src/displayapp/screens/ApplicationList.cpp | 2 +- src/displayapp/screens/Notifications.cpp | 145 +++++++++++++++++++++ src/displayapp/screens/Notifications.h | 36 +++++ src/main.cpp | 2 +- 7 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 src/displayapp/screens/Notifications.cpp create mode 100644 src/displayapp/screens/Notifications.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f38ec58..4647e92d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -341,6 +341,7 @@ list(APPEND SOURCE_FILES displayapp/screens/Music.cpp displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp + displayapp/screens/Notifications.cpp main.cpp drivers/St7789.cpp drivers/SpiNorFlash.cpp @@ -419,6 +420,7 @@ set(INCLUDE_FILES displayapp/screens/FirmwareValidation.h displayapp/screens/ApplicationList.h displayapp/Apps.h + displayapp/screens/Notifications.h drivers/St7789.h drivers/SpiNorFlash.h drivers/SpiMaster.h diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 3842e4e5..bfa799ba 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -2,6 +2,6 @@ namespace Pinetime { namespace Applications { - enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint}; + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint, Notifications}; } } \ No newline at end of file diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index d65e4f92..6653fa3d 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -8,6 +8,7 @@ #include #include "components/datetime/DateTimeController.h" #include +#include "displayapp/screens/Notifications.h" #include "displayapp/screens/Tile.h" #include "displayapp/screens/Meter.h" #include "displayapp/screens/Gauge.h" @@ -202,6 +203,7 @@ void DisplayApp::RunningState() { case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; + case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this)); break; } nextApp = Apps::None; } diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 71ba91c4..27590b97 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -58,7 +58,7 @@ std::unique_ptr ApplicationList::CreateScreen2() { {{Symbols::tachometer, Apps::Gauge}, {Symbols::asterisk, Apps::Meter}, {Symbols::paintbrush, Apps::Paint}, - {Symbols::none, Apps::None}, + {Symbols::shoe, Apps::Notifications}, {Symbols::none, Apps::None}, {Symbols::none, Apps::None} } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp new file mode 100644 index 00000000..fd1225f3 --- /dev/null +++ b/src/displayapp/screens/Notifications.cpp @@ -0,0 +1,145 @@ +#include "Notifications.h" +#include "displayapp/DisplayApp.h" +#include + +using namespace Pinetime::Applications::Screens; + +Notifications::Notifications(DisplayApp* app) : Screen(app) { + + app->SetTouchMode(DisplayApp::TouchModes::Polling); +} + +Notifications::~Notifications() { + lv_obj_clean(lv_scr_act()); +} + +bool Notifications::Refresh() { + return running; +} + +void Notifications::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { + +} + +bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } + + +bool Notifications::OnButtonPushed() { + app->StartApp(Apps::Clock); + running = false; + return true; +} + + +Notifications::ListWidget::ListWidget() { + static lv_point_t valid_pos[] = {{0,0}, {0,1}}; + page = lv_tileview_create(lv_scr_act(), NULL); + lv_obj_set_size(page, LV_HOR_RES, LV_VER_RES); + lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0); + lv_tileview_set_valid_positions(page, valid_pos, 2); + + static lv_style_t pageStyle; + lv_style_copy(&pageStyle, lv_tileview_get_style(page, LV_TILEVIEW_STYLE_MAIN)); + + lv_tileview_set_style(page, LV_TILEVIEW_STYLE_MAIN, &pageStyle); + + + lv_obj_t* container1 = lv_cont_create(page, NULL); + static lv_style_t contStyle; + lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); + contStyle.body.padding.inner = 20; + lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container1, LV_HOR_RES); + lv_obj_set_pos(container1, 0, 0); + lv_cont_set_layout(container1, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_TIGHT); + + lv_tileview_add_element(page, container1); + + + lv_obj_t* t1 = lv_label_create(container1, NULL); + + static lv_style_t titleStyle; + static lv_style_t textStyle; + lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + + //titleStyle.body.main_color = LV_COLOR_RED; + //titleStyle.body.grad_color = LV_COLOR_RED; + titleStyle.body.padding.inner = 5; + + //textStyle.body.main_color = LV_COLOR_BLUE; + //textStyle.body.grad_color = LV_COLOR_BLUE; + textStyle.body.padding.inner = 5; + + lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); + lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t1, true); + lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t1, "Message"); + + + lv_obj_t* l1 = lv_label_create(container1, NULL); + lv_label_set_style(l1, LV_PAGE_STYLE_BG, &textStyle); + 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, "Marcel Pickett: Did you bring your ticket?"); + + /*---*/ + lv_obj_t* container2 = lv_cont_create(page, NULL); + lv_cont_set_style(container2, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container2, LV_HOR_RES); + lv_obj_set_pos(container2, 0, lv_obj_get_y(container1) + lv_obj_get_height(container1)+5); + lv_cont_set_layout(container2, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_tileview_add_element(page, container2); + + lv_obj_t* t2 = lv_label_create(container2, NULL); + lv_label_set_style(t2, LV_PAGE_STYLE_BG, &titleStyle); + lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t2, true); + lv_obj_set_width(t2, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t2, "Alarm"); + + + lv_obj_t* l2 = lv_label_create(container2, NULL); + lv_label_set_style(l2, LV_PAGE_STYLE_BG, &textStyle); + 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, "Missed: 09:30"); + + /*****/ + lv_obj_t* container3 = lv_cont_create(page, NULL); + lv_cont_set_style(container3, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container3, LV_HOR_RES); + lv_obj_set_pos(container3, 0, lv_obj_get_y(container2) + lv_obj_get_height(container2)+5); + lv_cont_set_layout(container3, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container3, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_tileview_add_element(page, container3); + + lv_obj_t* t3 = lv_label_create(container3, NULL); + lv_label_set_style(t3, LV_PAGE_STYLE_BG, &titleStyle); + lv_label_set_long_mode(t3, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t3, true); + lv_obj_set_width(t3, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t3, "Spotify"); + + + lv_obj_t* l3 = lv_label_create(container3, NULL); + lv_label_set_style(l3, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l3, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l3, true); + lv_obj_set_width(l3, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l3, "Now playing: Bame game - Kanye West"); + + + + + + + + + +} diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h new file mode 100644 index 00000000..b4d0beda --- /dev/null +++ b/src/displayapp/screens/Notifications.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include "Screen.h" +#include +#include "Modal.h" +#include +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Notifications : public Screen { + public: + explicit Notifications(DisplayApp* app); + ~Notifications() override; + + bool Refresh() override; + bool OnButtonPushed() override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + + private: + class ListWidget { + public: + ListWidget(); + private: + lv_obj_t* page = nullptr; + }; + + bool running = true; + ListWidget list; + }; + } + } +} diff --git a/src/main.cpp b/src/main.cpp index e3243362..45aac6de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ #if NRF_LOG_ENABLED -#include "Logging/NrfLogger.h" +#include "logging/NrfLogger.h" Pinetime::Logging::NrfLogger logger; #else #include "logging/DummyLogger.h"