2021-10-13 16:08:35 -04:00
|
|
|
#include "displayapp/screens/FlashLight.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
2022-08-16 01:21:23 -04:00
|
|
|
#include "displayapp/InfiniTimeTheme.h"
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
2022-06-13 16:51:05 -04:00
|
|
|
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();
|
|
|
|
}
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
|
|
|
|
System::SystemTask& systemTask,
|
2021-10-13 06:04:40 -04:00
|
|
|
Controllers::BrightnessController& brightnessController)
|
2022-06-18 05:54:41 -04:00
|
|
|
: Screen(app), systemTask {systemTask}, brightnessController {brightnessController} {
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2022-07-21 15:22:14 -04:00
|
|
|
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
|
2021-10-13 06:04:40 -04:00
|
|
|
|
|
|
|
flashLight = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
2022-07-21 15:56:34 -04:00
|
|
|
lv_label_set_text_static(flashLight, Symbols::flashlight);
|
2021-10-13 06:04:40 -04:00
|
|
|
lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0);
|
|
|
|
|
2022-07-21 15:22:14 -04:00
|
|
|
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);
|
2021-10-13 06:04:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
|
|
|
lv_obj_align(indicators[0], indicators[1], LV_ALIGN_OUT_LEFT_MID, -8, 0);
|
|
|
|
lv_obj_align(indicators[2], indicators[1], LV_ALIGN_OUT_RIGHT_MID, 8, 0);
|
|
|
|
|
|
|
|
SetIndicators();
|
|
|
|
SetColors();
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
backgroundAction = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundAction, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundAction, 0, 0);
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(backgroundAction, "");
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_click(backgroundAction, true);
|
2021-04-18 13:28:14 -04:00
|
|
|
backgroundAction->user_data = this;
|
2022-06-13 16:51:05 -04:00
|
|
|
lv_obj_set_event_cb(backgroundAction, EventHandler);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-06-06 09:56:03 -04:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
FlashLight::~FlashLight() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
2021-10-13 06:04:40 -04:00
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
2021-06-06 09:56:03 -04:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 06:04:40 -04:00
|
|
|
void FlashLight::SetColors() {
|
2022-07-21 15:22:14 -04:00
|
|
|
lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK;
|
2022-08-16 01:21:23 -04:00
|
|
|
lv_color_t fgColor = isOn ? Colors::lightGray : LV_COLOR_WHITE;
|
2022-07-21 15:22:14 -04:00
|
|
|
|
|
|
|
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);
|
2021-10-13 06:04:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlashLight::SetIndicators() {
|
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
|
|
|
|
if (brightnessLevel == BrightnessController::Levels::High) {
|
|
|
|
lv_obj_set_state(indicators[1], LV_STATE_DEFAULT);
|
|
|
|
lv_obj_set_state(indicators[2], LV_STATE_DEFAULT);
|
|
|
|
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
|
|
|
|
lv_obj_set_state(indicators[1], LV_STATE_DEFAULT);
|
|
|
|
lv_obj_set_state(indicators[2], LV_STATE_DISABLED);
|
|
|
|
} else {
|
|
|
|
lv_obj_set_state(indicators[1], LV_STATE_DISABLED);
|
|
|
|
lv_obj_set_state(indicators[2], LV_STATE_DISABLED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-13 16:51:05 -04:00
|
|
|
void FlashLight::Toggle() {
|
|
|
|
isOn = !isOn;
|
|
|
|
SetColors();
|
2022-07-21 15:22:14 -04:00
|
|
|
if (isOn) {
|
|
|
|
brightnessController.Set(brightnessLevel);
|
|
|
|
} else {
|
|
|
|
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
|
|
|
|
}
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
2021-10-13 06:04:40 -04:00
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
|
2022-07-21 15:22:14 -04:00
|
|
|
auto SetState = [this]() {
|
|
|
|
if (isOn) {
|
|
|
|
brightnessController.Set(brightnessLevel);
|
|
|
|
}
|
|
|
|
SetIndicators();
|
|
|
|
};
|
|
|
|
|
2021-10-13 06:04:40 -04:00
|
|
|
if (event == TouchEvents::SwipeLeft) {
|
|
|
|
if (brightnessLevel == BrightnessController::Levels::High) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::Medium;
|
2022-07-21 15:22:14 -04:00
|
|
|
SetState();
|
2021-10-13 06:04:40 -04:00
|
|
|
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::Low;
|
2022-07-21 15:22:14 -04:00
|
|
|
SetState();
|
2021-10-13 06:04:40 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (event == TouchEvents::SwipeRight) {
|
|
|
|
if (brightnessLevel == BrightnessController::Levels::Low) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::Medium;
|
2022-07-21 15:22:14 -04:00
|
|
|
SetState();
|
2021-10-13 06:04:40 -04:00
|
|
|
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::High;
|
2022-07-21 15:22:14 -04:00
|
|
|
SetState();
|
2021-10-13 06:04:40 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-11 07:55:37 -04:00
|
|
|
return false;
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|