aboutsummaryrefslogtreecommitdiffstats
path: root/src/displayapp/screens/FlashLight.cpp
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2022-09-11 14:59:49 +0200
committerJean-François Milants <jf@codingfield.com>2022-09-11 14:59:49 +0200
commitada2c09581d2d13acfa5ce9a97671c0ec17863f1 (patch)
tree2f776adc59d0c63e403d2043cb8460e65d6c46fe /src/displayapp/screens/FlashLight.cpp
parent18cff286c75f432095db4b188e0f9a8a9e2bd8e8 (diff)
parentc9a5c3fa5c930a5939d3114a6c6b48570d61ca24 (diff)
Merge branch 'develop' into infineat-external-resources
# Conflicts: # src/displayapp/screens/Symbols.h # src/displayapp/screens/settings/SettingWatchFace.cpp # src/displayapp/screens/settings/SettingWatchFace.h
Diffstat (limited to 'src/displayapp/screens/FlashLight.cpp')
-rw-r--r--src/displayapp/screens/FlashLight.cpp86
1 files changed, 41 insertions, 45 deletions
diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp
index 2a1884f6..e06b59b5 100644
--- a/src/displayapp/screens/FlashLight.cpp
+++ b/src/displayapp/screens/FlashLight.cpp
@@ -1,37 +1,35 @@
#include "displayapp/screens/FlashLight.h"
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Symbols.h"
+#include "displayapp/InfiniTimeTheme.h"
using namespace Pinetime::Applications::Screens;
namespace {
- void event_handler(lv_obj_t* obj, lv_event_t event) {
- auto* screen = static_cast<FlashLight*>(obj->user_data);
- screen->OnClickEvent(obj, event);
+ void EventHandler(lv_obj_t* obj, lv_event_t event) {
+ if (event == LV_EVENT_CLICKED) {
+ auto* screen = static_cast<FlashLight*>(obj->user_data);
+ screen->Toggle();
+ }
}
}
FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
System::SystemTask& systemTask,
Controllers::BrightnessController& brightnessController)
- : Screen(app),
- systemTask {systemTask},
- brightnessController {brightnessController}
-
-{
- brightnessController.Backup();
+ : Screen(app), systemTask {systemTask}, brightnessController {brightnessController} {
- brightnessLevel = brightnessController.Level();
+ brightnessController.Set(Controllers::BrightnessController::Levels::Low);
flashLight = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
- lv_label_set_text_static(flashLight, Symbols::highlight);
+ lv_label_set_text_static(flashLight, Symbols::flashlight);
lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0);
- for (auto& i : indicators) {
- i = lv_obj_create(lv_scr_act(), nullptr);
- lv_obj_set_size(i, 15, 10);
- lv_obj_set_style_local_border_width(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2);
+ for (auto& indicator : indicators) {
+ indicator = lv_obj_create(lv_scr_act(), nullptr);
+ lv_obj_set_size(indicator, 15, 10);
+ lv_obj_set_style_local_border_width(indicator, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2);
}
lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
@@ -48,7 +46,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
lv_label_set_text_static(backgroundAction, "");
lv_obj_set_click(backgroundAction, true);
backgroundAction->user_data = this;
- lv_obj_set_event_cb(backgroundAction, event_handler);
+ lv_obj_set_event_cb(backgroundAction, EventHandler);
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
}
@@ -56,27 +54,19 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
FlashLight::~FlashLight() {
lv_obj_clean(lv_scr_act());
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
- brightnessController.Restore();
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
}
void FlashLight::SetColors() {
- if (isOn) {
- lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
- lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
- for (auto& i : indicators) {
- lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
- lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE);
- lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
- }
- } else {
- lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
- lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
- for (auto& i : indicators) {
- lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
- lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK);
- lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
- }
+ lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK;
+ lv_color_t fgColor = isOn ? Colors::lightGray : LV_COLOR_WHITE;
+
+ lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, bgColor);
+ lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fgColor);
+ for (auto& indicator : indicators) {
+ lv_obj_set_style_local_bg_color(indicator, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, fgColor);
+ lv_obj_set_style_local_bg_color(indicator, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, bgColor);
+ lv_obj_set_style_local_border_color(indicator, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, fgColor);
}
}
@@ -95,37 +85,43 @@ void FlashLight::SetIndicators() {
}
}
-void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
- if (obj == backgroundAction && event == LV_EVENT_CLICKED) {
- isOn = !isOn;
- SetColors();
+void FlashLight::Toggle() {
+ isOn = !isOn;
+ SetColors();
+ if (isOn) {
+ brightnessController.Set(brightnessLevel);
+ } else {
+ brightnessController.Set(Controllers::BrightnessController::Levels::Low);
}
}
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
using namespace Pinetime::Controllers;
+ auto SetState = [this]() {
+ if (isOn) {
+ brightnessController.Set(brightnessLevel);
+ }
+ SetIndicators();
+ };
+
if (event == TouchEvents::SwipeLeft) {
if (brightnessLevel == BrightnessController::Levels::High) {
brightnessLevel = BrightnessController::Levels::Medium;
- brightnessController.Set(brightnessLevel);
- SetIndicators();
+ SetState();
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
brightnessLevel = BrightnessController::Levels::Low;
- brightnessController.Set(brightnessLevel);
- SetIndicators();
+ SetState();
}
return true;
}
if (event == TouchEvents::SwipeRight) {
if (brightnessLevel == BrightnessController::Levels::Low) {
brightnessLevel = BrightnessController::Levels::Medium;
- brightnessController.Set(brightnessLevel);
- SetIndicators();
+ SetState();
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
brightnessLevel = BrightnessController::Levels::High;
- brightnessController.Set(brightnessLevel);
- SetIndicators();
+ SetState();
}
return true;
}