55using namespace Pinetime ::Applications::Screens;
66
77namespace {
8- static void event_handler (lv_obj_t * obj, lv_event_t event) {
9- FlashLight * screen = static_cast <FlashLight*>(obj->user_data );
8+ void event_handler (lv_obj_t * obj, lv_event_t event) {
9+ auto * screen = static_cast <FlashLight*>(obj->user_data );
1010 screen->OnClickEvent (obj, event);
1111 }
1212}
1313
1414FlashLight::FlashLight (Pinetime::Applications::DisplayApp* app,
1515 System::SystemTask& systemTask,
16- Controllers::BrightnessController& brightness )
16+ Controllers::BrightnessController& brightnessController )
1717 : Screen(app),
1818 systemTask {systemTask},
19- brightness {brightness }
19+ brightnessController {brightnessController }
2020
2121{
22- brightness.Backup ();
23- brightness.Set (Controllers::BrightnessController::Levels::High);
24- // Set the background
25- lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xFFFFFF ));
22+ brightnessController.Backup ();
2623
27- flashLight = lv_label_create (lv_scr_act (), NULL );
28- lv_obj_set_style_local_text_color (flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000000 ));
24+ brightnessLevel = brightnessController.Level ();
25+
26+ flashLight = lv_label_create (lv_scr_act (), nullptr );
2927 lv_obj_set_style_local_text_font (flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
3028 lv_label_set_text_static (flashLight, Symbols::highlight);
31- lv_obj_align (flashLight, NULL , LV_ALIGN_CENTER, 0 , 0 );
29+ lv_obj_align (flashLight, nullptr , LV_ALIGN_CENTER, 0 , 0 );
30+
31+ for (auto & i : indicators) {
32+ i = lv_obj_create (lv_scr_act (), nullptr );
33+ lv_obj_set_size (i, 15 , 10 );
34+ lv_obj_set_style_local_border_width (i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2 );
35+ }
36+
37+ lv_obj_align (indicators[1 ], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0 , 5 );
38+ lv_obj_align (indicators[0 ], indicators[1 ], LV_ALIGN_OUT_LEFT_MID, -8 , 0 );
39+ lv_obj_align (indicators[2 ], indicators[1 ], LV_ALIGN_OUT_RIGHT_MID, 8 , 0 );
40+
41+ SetIndicators ();
42+ SetColors ();
3243
3344 backgroundAction = lv_label_create (lv_scr_act (), nullptr );
3445 lv_label_set_long_mode (backgroundAction, LV_LABEL_LONG_CROP);
@@ -44,27 +55,80 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
4455
4556FlashLight::~FlashLight () {
4657 lv_obj_clean (lv_scr_act ());
47- lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex ( 0x000000 ) );
48- brightness .Restore ();
58+ lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK );
59+ brightnessController .Restore ();
4960 systemTask.PushMessage (Pinetime::System::Messages::EnableSleeping);
5061}
5162
52- void FlashLight::OnClickEvent (lv_obj_t * obj, lv_event_t event) {
53- if (obj == backgroundAction) {
54- if (event == LV_EVENT_CLICKED) {
55- isOn = !isOn;
56-
57- if (isOn) {
58- lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xFFFFFF ));
59- lv_obj_set_style_local_text_color (flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000000 ));
60- } else {
61- lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000000 ));
62- lv_obj_set_style_local_text_color (flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xFFFFFF ));
63- }
63+ void FlashLight::SetColors () {
64+ if (isOn) {
65+ lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
66+ lv_obj_set_style_local_text_color (flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
67+ for (auto & i : indicators) {
68+ lv_obj_set_style_local_bg_color (i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
69+ lv_obj_set_style_local_bg_color (i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE);
70+ lv_obj_set_style_local_border_color (i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
6471 }
72+ } else {
73+ lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
74+ lv_obj_set_style_local_text_color (flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
75+ for (auto & i : indicators) {
76+ lv_obj_set_style_local_bg_color (i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
77+ lv_obj_set_style_local_bg_color (i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK);
78+ lv_obj_set_style_local_border_color (i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
79+ }
80+ }
81+ }
82+
83+ void FlashLight::SetIndicators () {
84+ using namespace Pinetime ::Controllers;
85+
86+ if (brightnessLevel == BrightnessController::Levels::High) {
87+ lv_obj_set_state (indicators[1 ], LV_STATE_DEFAULT);
88+ lv_obj_set_state (indicators[2 ], LV_STATE_DEFAULT);
89+ } else if (brightnessLevel == BrightnessController::Levels::Medium) {
90+ lv_obj_set_state (indicators[1 ], LV_STATE_DEFAULT);
91+ lv_obj_set_state (indicators[2 ], LV_STATE_DISABLED);
92+ } else {
93+ lv_obj_set_state (indicators[1 ], LV_STATE_DISABLED);
94+ lv_obj_set_state (indicators[2 ], LV_STATE_DISABLED);
95+ }
96+ }
97+
98+ void FlashLight::OnClickEvent (lv_obj_t * obj, lv_event_t event) {
99+ if (obj == backgroundAction && event == LV_EVENT_CLICKED) {
100+ isOn = !isOn;
101+ SetColors ();
65102 }
66103}
67104
68105bool FlashLight::OnTouchEvent (Pinetime::Applications::TouchEvents event) {
106+ using namespace Pinetime ::Controllers;
107+
108+ if (event == TouchEvents::SwipeLeft) {
109+ if (brightnessLevel == BrightnessController::Levels::High) {
110+ brightnessLevel = BrightnessController::Levels::Medium;
111+ brightnessController.Set (brightnessLevel);
112+ SetIndicators ();
113+ } else if (brightnessLevel == BrightnessController::Levels::Medium) {
114+ brightnessLevel = BrightnessController::Levels::Low;
115+ brightnessController.Set (brightnessLevel);
116+ SetIndicators ();
117+ }
118+ return true ;
119+ }
120+ if (event == TouchEvents::SwipeRight) {
121+ if (brightnessLevel == BrightnessController::Levels::Low) {
122+ brightnessLevel = BrightnessController::Levels::Medium;
123+ brightnessController.Set (brightnessLevel);
124+ SetIndicators ();
125+ } else if (brightnessLevel == BrightnessController::Levels::Medium) {
126+ brightnessLevel = BrightnessController::Levels::High;
127+ brightnessController.Set (brightnessLevel);
128+ SetIndicators ();
129+ }
130+ return true ;
131+ }
132+
69133 return false ;
70134}
0 commit comments