2021-04-04 04:08:51 +02:00
|
|
|
#include "FlashLight.h"
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
#include "Symbols.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
2021-04-18 19:28:14 +02:00
|
|
|
static void event_handler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
FlashLight* 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,
|
|
|
|
Controllers::BrightnessController& brightness)
|
|
|
|
: Screen(app),
|
|
|
|
systemTask {systemTask},
|
|
|
|
brightness {brightness}
|
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
{
|
|
|
|
brightness.Backup();
|
|
|
|
brightness.Set(Controllers::BrightnessController::Levels::High);
|
|
|
|
// Set the background
|
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
flashLight = lv_label_create(lv_scr_act(), NULL);
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
|
|
|
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_obj_align(flashLight, NULL, LV_ALIGN_CENTER, 0, 0);
|
|
|
|
|
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());
|
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
|
|
|
brightness.Restore();
|
2021-06-06 15:56:03 +02:00
|
|
|
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
if (obj == backgroundAction) {
|
2021-04-04 04:08:51 +02:00
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
isOn = !isOn;
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
if (isOn) {
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
|
|
|
|
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
|
|
|
} else {
|
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
|
|
|
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
2021-06-11 13:55:37 +02:00
|
|
|
return false;
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|