|
7 | 7 | using namespace Pinetime::Applications::Screens; |
8 | 8 |
|
9 | 9 | namespace { |
10 | | - void btnStartStopEventHandler(lv_obj_t* obj, lv_event_t event) { |
| 10 | + void btnImmediateAlertEventHandler(lv_obj_t* obj, lv_event_t event) { |
11 | 11 | auto* screen = static_cast<FindMyPhone*>(obj->user_data); |
12 | | - screen->OnStartStopEvent(event); |
| 12 | + screen->OnImmediateAlertEvent(obj, event); |
13 | 13 | } |
14 | 14 | } |
15 | 15 |
|
16 | 16 | FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertService& immediateAlertService) |
17 | 17 | : immediateAlertService {immediateAlertService} { |
18 | | - isFindMyPhoneRunning = false; |
| 18 | + last_level = Pinetime::Controllers::ImmediateAlertService::Levels::NoAlert; |
| 19 | + |
| 20 | + container = lv_cont_create(lv_scr_act(), nullptr); |
| 21 | + |
| 22 | + lv_obj_set_size(container, LV_HOR_RES, LV_VER_RES); |
| 23 | + lv_obj_set_style_local_bg_color(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); |
| 24 | + lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); |
| 25 | + lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); |
| 26 | + lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); |
| 27 | + |
19 | 28 | label_title = lv_label_create(lv_scr_act(), nullptr); |
20 | 29 |
|
21 | 30 | lv_label_set_text_static(label_title, "Find my phone"); |
22 | 31 | lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40); |
23 | 32 |
|
24 | | - btn_startStop = lv_btn_create(lv_scr_act(), nullptr); |
25 | | - btn_startStop->user_data = this; |
26 | | - lv_obj_set_height(btn_startStop, 50); |
27 | | - lv_obj_set_event_cb(btn_startStop, btnStartStopEventHandler); |
28 | | - lv_obj_align(btn_startStop, label_title, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); |
| 33 | + bt_none = lv_btn_create(container, nullptr); |
| 34 | + bt_none->user_data = this; |
| 35 | + lv_obj_set_event_cb(bt_none, btnImmediateAlertEventHandler); |
| 36 | + lv_obj_set_size(bt_none, 76, 76); |
| 37 | + lv_obj_align(bt_none, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); |
| 38 | + label_none = lv_label_create(bt_none, nullptr); |
| 39 | + lv_label_set_text_static(label_none, "None"); |
| 40 | + lv_obj_set_style_local_bg_color(bt_none, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); |
| 41 | + |
| 42 | + bt_mild = lv_btn_create(container, nullptr); |
| 43 | + bt_mild->user_data = this; |
| 44 | + lv_obj_set_event_cb(bt_mild, btnImmediateAlertEventHandler); |
| 45 | + lv_obj_set_size(bt_mild, 76, 76); |
| 46 | + lv_obj_align(bt_mild, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); |
| 47 | + label_mild = lv_label_create(bt_mild, nullptr); |
| 48 | + lv_label_set_text_static(label_mild, "Mild"); |
| 49 | + lv_obj_set_style_local_bg_color(bt_mild, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight); |
29 | 50 |
|
30 | | - label_startStop = lv_label_create(btn_startStop, nullptr); |
31 | | - UpdateStartStopButton(isFindMyPhoneRunning); |
| 51 | + bt_high = lv_btn_create(container, nullptr); |
| 52 | + bt_high->user_data = this; |
| 53 | + lv_obj_set_event_cb(bt_high, btnImmediateAlertEventHandler); |
| 54 | + lv_obj_set_size(bt_high, 76, 76); |
| 55 | + lv_obj_align(bt_high, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); |
| 56 | + label_high = lv_label_create(bt_high, nullptr); |
| 57 | + lv_label_set_text_static(label_high, "High"); |
| 58 | + lv_obj_set_style_local_bg_color(bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED ); |
| 59 | + |
| 60 | + UpdateImmediateAlerts(); |
32 | 61 | } |
33 | 62 |
|
34 | 63 | FindMyPhone::~FindMyPhone() { |
35 | 64 | lv_obj_clean(lv_scr_act()); |
36 | 65 | } |
37 | 66 |
|
38 | | -void FindMyPhone::OnStartStopEvent(lv_event_t event) { |
| 67 | +void FindMyPhone::OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event) { |
39 | 68 | if (event == LV_EVENT_CLICKED) { |
40 | | - isFindMyPhoneRunning = !isFindMyPhoneRunning; |
41 | | - UpdateStartStopButton(isFindMyPhoneRunning); |
| 69 | + if (obj == bt_none) { |
| 70 | + last_level = Pinetime::Controllers::ImmediateAlertService::Levels::NoAlert; |
| 71 | + } else if (obj == bt_mild) { |
| 72 | + last_level = Pinetime::Controllers::ImmediateAlertService::Levels::MildAlert; |
| 73 | + } else if (obj == bt_high) { |
| 74 | + last_level = Pinetime::Controllers::ImmediateAlertService::Levels::HighAlert; |
| 75 | + } |
| 76 | + UpdateImmediateAlerts(); |
42 | 77 | } |
43 | 78 | } |
44 | 79 |
|
45 | | -void FindMyPhone::UpdateStartStopButton(bool isRunning) { |
46 | | - if (isRunning) { |
47 | | - immediateAlertService.sendImmediateAlert(Pinetime::Controllers::ImmediateAlertService::Levels::HighAlert); |
48 | | - lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight); |
49 | | - lv_label_set_text_static(label_startStop, "Stop"); |
50 | | - } else { |
51 | | - lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); |
52 | | - lv_label_set_text_static(label_startStop, "Start"); |
53 | | - immediateAlertService.sendImmediateAlert(Pinetime::Controllers::ImmediateAlertService::Levels::NoAlert); |
| 80 | +void FindMyPhone::UpdateImmediateAlerts() { |
| 81 | + switch (last_level) { |
| 82 | + case Pinetime::Controllers::ImmediateAlertService::Levels::NoAlert: |
| 83 | + lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); |
| 84 | + break; |
| 85 | + case Pinetime::Controllers::ImmediateAlertService::Levels::MildAlert: |
| 86 | + lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight); |
| 87 | + break; |
| 88 | + case Pinetime::Controllers::ImmediateAlertService::Levels::HighAlert: |
| 89 | + lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); |
| 90 | + break; |
54 | 91 | } |
| 92 | + immediateAlertService.sendImmediateAlert(last_level); |
| 93 | + |
55 | 94 | } |
| 95 | + |
0 commit comments