2021-04-04 04:08:51 +02:00
|
|
|
#include "FlashLight.h"
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
#include "Symbols.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
2021-10-13 12:04:40 +02:00
|
|
|
void event_handler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* screen = static_cast<FlashLight*>(obj->user_data);
|
2021-04-04 04:08:51 +02:00
|
|
|
screen->OnClickEvent(obj, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
|
|
|
|
System::SystemTask& systemTask,
|
2021-10-13 12:04:40 +02:00
|
|
|
Controllers::BrightnessController& brightnessController)
|
2021-04-18 19:28:14 +02:00
|
|
|
: Screen(app),
|
|
|
|
systemTask {systemTask},
|
2021-10-13 12:04:40 +02:00
|
|
|
brightnessController {brightnessController}
|
2021-04-18 19:28:14 +02:00
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
{
|
2021-10-13 12:04:40 +02:00
|
|
|
brightnessController.Backup();
|
2021-04-18 19:28:14 +02:00
|
|
|
|
2021-10-13 12:04:40 +02:00
|
|
|
brightnessLevel = brightnessController.Level();
|
|
|
|
|
|
|
|
flashLight = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 04:08:51 +02:00
|
|
|
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);
|
2021-10-13 12:04:40 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04 04:08:51 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
backgroundAction = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 04:08:51 +02: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);
|
|
|
|
lv_label_set_text(backgroundAction, "");
|
|
|
|
lv_obj_set_click(backgroundAction, true);
|
2021-04-18 19:28:14 +02:00
|
|
|
backgroundAction->user_data = this;
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_set_event_cb(backgroundAction, event_handler);
|
|
|
|
|
2021-06-06 15:56:03 +02:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FlashLight::~FlashLight() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
2021-10-13 12:04:40 +02:00
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
|
|
|
brightnessController.Restore();
|
2021-06-06 15:56:03 +02:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 12:04:40 +02:00
|
|
|
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_GRAY);
|
|
|
|
for (auto & i : indicators) {
|
|
|
|
lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
|
|
|
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_GRAY);
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|
2021-10-13 12:04:40 +02:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
if (obj == backgroundAction && event == LV_EVENT_CLICKED) {
|
|
|
|
isOn = !isOn;
|
|
|
|
SetColors();
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
2021-10-13 12:04:40 +02:00
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
|
|
|
|
if (event == TouchEvents::SwipeLeft) {
|
|
|
|
if (brightnessLevel == BrightnessController::Levels::High) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::Medium;
|
|
|
|
brightnessController.Set(brightnessLevel);
|
|
|
|
SetIndicators();
|
|
|
|
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::Low;
|
|
|
|
brightnessController.Set(brightnessLevel);
|
|
|
|
SetIndicators();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (event == TouchEvents::SwipeRight) {
|
|
|
|
if (brightnessLevel == BrightnessController::Levels::Low) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::Medium;
|
|
|
|
brightnessController.Set(brightnessLevel);
|
|
|
|
SetIndicators();
|
|
|
|
} else if (brightnessLevel == BrightnessController::Levels::Medium) {
|
|
|
|
brightnessLevel = BrightnessController::Levels::High;
|
|
|
|
brightnessController.Set(brightnessLevel);
|
|
|
|
SetIndicators();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-11 13:55:37 +02:00
|
|
|
return false;
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|