ref: 0.13.0
src/displayapp/screens/Notifications.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
#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, 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, notification.category, notificationManager.NbNotifications(), mode, alertNotificationService)); validDisplay = true; } else { currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notification.category, notificationManager.NbNotifications(), Modes::Preview, alertNotificationService)); } if(mode == Modes::Preview) { static lv_style_t style_line; lv_style_copy(&style_line, &lv_style_plain); style_line.line.color = LV_COLOR_WHITE; style_line.line.width = 3; style_line.line.rounded = 0; timeoutLine = lv_line_create(lv_scr_act(), nullptr); lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line); lv_line_set_points(timeoutLine, timeoutLinePoints, 2); timeoutTickCountStart = xTaskGetTickCount(); timeoutTickCountEnd = timeoutTickCountStart + (5*1024); } } Notifications::~Notifications() { lv_obj_clean(lv_scr_act()); } bool Notifications::Refresh() { if (mode == Modes::Preview) { auto tick = xTaskGetTickCount(); int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240)); if (pos < 0) running = false; timeoutLinePoints[1].x = pos; lv_line_set_points(timeoutLine, timeoutLinePoints, 2); if (!running) { // Start clock app when exiting this one app->StartApp(Apps::Clock); } } return running; } bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { switch (event) { case Pinetime::Applications::TouchEvents::SwipeUp: { 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::Up); currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, previousNotification.category, notificationManager.NbNotifications(), mode, alertNotificationService)); } return true; case Pinetime::Applications::TouchEvents::SwipeDown: { Controllers::NotificationManager::Notification nextNotification; if(validDisplay) nextNotification = notificationManager.GetNext(currentId); else nextNotification = notificationManager.GetLastNotification(); if (!nextNotification.valid) return true; validDisplay = true; currentId = nextNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); 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(); return true; } default: return false; } } bool Notifications::OnButtonPushed() { running = false; 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, 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)); 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_height(container1, LV_VER_RES); lv_obj_set_pos(container1, 0, 0); lv_cont_set_layout(container1, LV_LAYOUT_OFF); lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD); t1 = lv_label_create(container1, nullptr); static lv_style_t titleStyle; static lv_style_t textStyle; static lv_style_t bottomStyle; 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)); lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); titleStyle.body.padding.inner = 5; titleStyle.body.grad_color = LV_COLOR_GRAY; titleStyle.body.main_color = LV_COLOR_GRAY; titleStyle.body.radius = 20; textStyle.body.border.part = LV_BORDER_NONE; textStyle.body.padding.inner = 5; bottomStyle.body.main_color = LV_COLOR_GREEN; bottomStyle.body.grad_color = LV_COLOR_GREEN; bottomStyle.body.border.part = LV_BORDER_TOP; bottomStyle.body.border.color = LV_COLOR_RED; 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, title); static constexpr int16_t offscreenOffset = -20 ; lv_obj_set_pos(t1, titleStyle.body.padding.left, offscreenOffset); auto titleHeight = lv_obj_get_height(t1); 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); 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) { bottomPlaceholder = lv_label_create(container1, nullptr); lv_label_set_style(bottomPlaceholder, LV_LABEL_STYLE_MAIN, &titleStyle); lv_label_set_long_mode(bottomPlaceholder, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(bottomPlaceholder, true); lv_obj_set_width(bottomPlaceholder, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right)); lv_label_set_text(bottomPlaceholder, " "); lv_obj_set_pos(bottomPlaceholder, titleStyle.body.padding.left, LV_VER_RES - 5); } } } 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()); } |