@@ -11,6 +11,7 @@ extern lv_font_t jetbrains_mono_bold_20;
1111Notifications::Notifications (DisplayApp* app,
1212 Pinetime::Controllers::NotificationManager& notificationManager,
1313 Pinetime::Controllers::AlertNotificationService& alertNotificationService,
14+ Pinetime::Controllers::MotorController& motorController,
1415 Modes mode)
1516 : Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
1617 notificationManager.ClearNewNotificationFlag ();
@@ -36,25 +37,31 @@ Notifications::Notifications(DisplayApp* app,
3637 }
3738
3839 if (mode == Modes::Preview) {
39-
40- timeoutLine = lv_line_create (lv_scr_act (), nullptr );
41-
42- lv_obj_set_style_local_line_width (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3 );
43- lv_obj_set_style_local_line_color (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
44- lv_obj_set_style_local_line_rounded (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true );
45-
46- lv_line_set_points (timeoutLine, timeoutLinePoints, 2 );
47- timeoutTickCountStart = xTaskGetTickCount ();
48- timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024 );
40+ if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) {
41+ motorController.StartRinging ();
42+ } else {
43+ motorController.RunForDuration (35 );
44+ timeoutLine = lv_line_create (lv_scr_act (), nullptr );
45+
46+ lv_obj_set_style_local_line_width (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3 );
47+ lv_obj_set_style_local_line_color (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
48+ lv_obj_set_style_local_line_rounded (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true );
49+
50+ lv_line_set_points (timeoutLine, timeoutLinePoints, 2 );
51+ timeoutTickCountStart = xTaskGetTickCount ();
52+ timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024 );
53+ }
4954 }
5055}
5156
5257Notifications::~Notifications () {
58+ // make sure we stop any vibrations before exiting
59+ Controllers::MotorController::StopRinging ();
5360 lv_obj_clean (lv_scr_act ());
5461}
5562
5663bool Notifications::Refresh () {
57- if (mode == Modes::Preview) {
64+ if (mode == Modes::Preview && timeoutLine != nullptr ) {
5865 auto tick = xTaskGetTickCount ();
5966 int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240 ));
6067 if (pos < 0 )
@@ -63,13 +70,13 @@ bool Notifications::Refresh() {
6370 timeoutLinePoints[1 ].x = pos;
6471 lv_line_set_points (timeoutLine, timeoutLinePoints, 2 );
6572 }
66-
67- return running;
73+ return running && currentItem->IsRunning ();
6874}
6975
7076bool Notifications::OnTouchEvent (Pinetime::Applications::TouchEvents event) {
71- if (mode != Modes::Normal)
72- return true ;
77+ if (mode != Modes::Normal) {
78+ return false ;
79+ }
7380
7481 switch (event) {
7582 case Pinetime::Applications::TouchEvents::SwipeDown: {
@@ -130,19 +137,9 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
130137}
131138
132139namespace {
133- static void AcceptIncomingCallEventHandler (lv_obj_t * obj, lv_event_t event) {
134- auto * item = static_cast <Notifications::NotificationItem*>(obj->user_data );
135- item->OnAcceptIncomingCall (event);
136- }
137-
138- static void MuteIncomingCallEventHandler (lv_obj_t * obj, lv_event_t event) {
140+ void CallEventHandler (lv_obj_t * obj, lv_event_t event) {
139141 auto * item = static_cast <Notifications::NotificationItem*>(obj->user_data );
140- item->OnMuteIncomingCall (event);
141- }
142-
143- static void RejectIncomingCallEventHandler (lv_obj_t * obj, lv_event_t event) {
144- auto * item = static_cast <Notifications::NotificationItem*>(obj->user_data );
145- item->OnRejectIncomingCall (event);
142+ item->OnCallButtonEvent (obj, event);
146143 }
147144}
148145
@@ -154,7 +151,6 @@ Notifications::NotificationItem::NotificationItem(const char* title,
154151 Modes mode,
155152 Pinetime::Controllers::AlertNotificationService& alertNotificationService)
156153 : notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
157-
158154 lv_obj_t * container1 = lv_cont_create (lv_scr_act (), NULL );
159155
160156 lv_obj_set_style_local_bg_color (container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x222222 ));
@@ -212,7 +208,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
212208
213209 bt_accept = lv_btn_create (lv_scr_act (), nullptr );
214210 bt_accept->user_data = this ;
215- lv_obj_set_event_cb (bt_accept, AcceptIncomingCallEventHandler );
211+ lv_obj_set_event_cb (bt_accept, CallEventHandler );
216212 lv_obj_set_size (bt_accept, 76 , 76 );
217213 lv_obj_align (bt_accept, NULL , LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
218214 label_accept = lv_label_create (bt_accept, nullptr );
@@ -221,7 +217,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
221217
222218 bt_reject = lv_btn_create (lv_scr_act (), nullptr );
223219 bt_reject->user_data = this ;
224- lv_obj_set_event_cb (bt_reject, RejectIncomingCallEventHandler );
220+ lv_obj_set_event_cb (bt_reject, CallEventHandler );
225221 lv_obj_set_size (bt_reject, 76 , 76 );
226222 lv_obj_align (bt_reject, NULL , LV_ALIGN_IN_BOTTOM_MID, 0 , 0 );
227223 label_reject = lv_label_create (bt_reject, nullptr );
@@ -230,7 +226,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
230226
231227 bt_mute = lv_btn_create (lv_scr_act (), nullptr );
232228 bt_mute->user_data = this ;
233- lv_obj_set_event_cb (bt_mute, MuteIncomingCallEventHandler );
229+ lv_obj_set_event_cb (bt_mute, CallEventHandler );
234230 lv_obj_set_size (bt_mute, 76 , 76 );
235231 lv_obj_align (bt_mute, NULL , LV_ALIGN_IN_BOTTOM_RIGHT, 0 , 0 );
236232 label_mute = lv_label_create (bt_mute, nullptr );
@@ -246,25 +242,22 @@ Notifications::NotificationItem::NotificationItem(const char* title,
246242 lv_label_set_text (backgroundLabel, " " );
247243}
248244
249- void Notifications::NotificationItem::OnAcceptIncomingCall (lv_event_t event) {
250- if (event != LV_EVENT_CLICKED)
251- return ;
252-
253- alertNotificationService.AcceptIncomingCall ();
254- }
255-
256- void Notifications::NotificationItem::OnMuteIncomingCall (lv_event_t event) {
257- if (event != LV_EVENT_CLICKED)
245+ void Notifications::NotificationItem::OnCallButtonEvent (lv_obj_t * obj, lv_event_t event) {
246+ if (event != LV_EVENT_CLICKED) {
258247 return ;
248+ }
259249
260- alertNotificationService.MuteIncomingCall ();
261- }
250+ Controllers::MotorController::StopRinging ();
262251
263- void Notifications::NotificationItem::OnRejectIncomingCall (lv_event_t event) {
264- if (event != LV_EVENT_CLICKED)
265- return ;
252+ if (obj == bt_accept) {
253+ alertNotificationService.AcceptIncomingCall ();
254+ } else if (obj == bt_reject) {
255+ alertNotificationService.RejectIncomingCall ();
256+ } else if (obj == bt_mute) {
257+ alertNotificationService.MuteIncomingCall ();
258+ }
266259
267- alertNotificationService. RejectIncomingCall () ;
260+ running = false ;
268261}
269262
270263Notifications::NotificationItem::~NotificationItem () {
0 commit comments