Skip to content

Commit cf468e3

Browse files
jmlichvchigrin
authored andcommitted
update screen layout
1 parent 201e848 commit cf468e3

File tree

3 files changed

+79
-27
lines changed

3 files changed

+79
-27
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ list(APPEND SOURCE_FILES
460460
components/ble/BatteryInformationService.cpp
461461
components/ble/FSService.cpp
462462
components/ble/ImmediateAlertService.cpp
463+
components/ble/ImmediateAlertClient.cpp
463464
components/ble/ServiceDiscovery.cpp
464465
components/ble/HeartRateService.cpp
465466
components/ble/MotionService.cpp
@@ -528,6 +529,7 @@ list(APPEND RECOVERY_SOURCE_FILES
528529
components/ble/BatteryInformationService.cpp
529530
components/ble/FSService.cpp
530531
components/ble/ImmediateAlertService.cpp
532+
components/ble/ImmediateAlertClient.cpp
531533
components/ble/ServiceDiscovery.cpp
532534
components/ble/NavigationService.cpp
533535
components/ble/HeartRateService.cpp
@@ -647,6 +649,7 @@ set(INCLUDE_FILES
647649
components/ble/BatteryInformationService.h
648650
components/ble/FSService.h
649651
components/ble/ImmediateAlertService.h
652+
components/ble/ImmediateAlertClient.h
650653
components/ble/ServiceDiscovery.h
651654
components/ble/BleClient.h
652655
components/ble/HeartRateService.h

src/displayapp/screens/FindMyPhone.cpp

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,89 @@
77
using namespace Pinetime::Applications::Screens;
88

99
namespace {
10-
void btnStartStopEventHandler(lv_obj_t* obj, lv_event_t event) {
10+
void btnImmediateAlertEventHandler(lv_obj_t* obj, lv_event_t event) {
1111
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
12-
screen->OnStartStopEvent(event);
12+
screen->OnImmediateAlertEvent(obj, event);
1313
}
1414
}
1515

1616
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertService& immediateAlertService)
1717
: 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+
1928
label_title = lv_label_create(lv_scr_act(), nullptr);
2029

2130
lv_label_set_text_static(label_title, "Find my phone");
2231
lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40);
2332

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);
2950

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();
3261
}
3362

3463
FindMyPhone::~FindMyPhone() {
3564
lv_obj_clean(lv_scr_act());
3665
}
3766

38-
void FindMyPhone::OnStartStopEvent(lv_event_t event) {
67+
void FindMyPhone::OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event) {
3968
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();
4277
}
4378
}
4479

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;
5491
}
92+
immediateAlertService.sendImmediateAlert(last_level);
93+
5594
}
95+

src/displayapp/screens/FindMyPhone.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "displayapp/screens/Screen.h"
66
#include "Symbols.h"
77
#include "systemtask/SystemTask.h"
8+
#include "components/ble/ImmediateAlertService.h"
9+
810
#include <lvgl/src/lv_core/lv_style.h>
911
#include <lvgl/src/lv_core/lv_obj.h>
1012

@@ -22,17 +24,24 @@ namespace Pinetime {
2224
FindMyPhone(Pinetime::Controllers::ImmediateAlertService& immediateAlertService);
2325
~FindMyPhone() override;
2426

25-
void OnStartStopEvent(lv_event_t event);
27+
void OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event);
2628

2729
private:
2830
Pinetime::Controllers::ImmediateAlertService& immediateAlertService;
2931

30-
void UpdateStartStopButton(bool isRunning);
32+
void UpdateImmediateAlerts();
33+
34+
lv_obj_t* container;
3135
lv_obj_t* label_title;
32-
lv_obj_t* btn_startStop;
33-
lv_obj_t* label_startStop;
36+
lv_obj_t* bt_none;
37+
lv_obj_t* bt_high;
38+
lv_obj_t* bt_mild;
39+
lv_obj_t* label_none;
40+
lv_obj_t* label_high;
41+
lv_obj_t* label_mild;
42+
3443

35-
bool isFindMyPhoneRunning;
44+
Pinetime::Controllers::ImmediateAlertService::Levels last_level;
3645
};
3746
}
3847

0 commit comments

Comments
 (0)