From 8ea7d77d1b1f476c890bf04b44ad9e2c858a4d1c Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Thu, 21 Apr 2022 12:41:24 +0200 Subject: Long-press to start red flashlight, long press again to alternate with red. diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 8aad953..2b02166 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -14,6 +14,7 @@ namespace Pinetime { Timer, Alarm, FlashLight, + FlashLightRed, BatteryInfo, Music, Paint, diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 3228061..2c33184 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -429,6 +429,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, *systemTask, brightnessController); ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::FlashLightRed: + currentScreen = std::make_unique(this, *systemTask, brightnessController, LV_COLOR_RED); + ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; case Apps::StopWatch: currentScreen = std::make_unique(this, *systemTask); break; diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 3047cf8..086b694 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -15,10 +15,12 @@ void FlashLight::EventHandler(lv_obj_t* obj, lv_event_t event) { FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, System::SystemTask& systemTask, - Controllers::BrightnessController& brightnessController) + Controllers::BrightnessController& brightnessController, + lv_color_t color) : Screen(app), systemTask {systemTask}, - brightnessController {brightnessController} + brightnessController {brightnessController}, + color {color} { brightnessLevel = brightnessController.Level(); @@ -75,21 +77,21 @@ void FlashLight::Update(bool on, Controllers::BrightnessController::Levels level isOn = on; if (isOn) { brightnessController.Backup(); - 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_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color); 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_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, color); lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); } } else { brightnessController.Restore(); 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); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); 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_DEFAULT, color); 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_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color); } } } diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 3433634..f227599 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -13,14 +13,20 @@ namespace Pinetime { class FlashLight : public Screen { public: - FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness); + FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness, lv_color_t color = LV_COLOR_WHITE); ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: inline void OnClickEvent(lv_obj_t* obj, lv_event_t event) { - if (obj == backgroundAction && event == LV_EVENT_CLICKED) { + if (obj == backgroundAction) { + if (event == LV_EVENT_CLICKED) { + } else if (event == LV_EVENT_LONG_PRESSED) { + color = (color.full == LV_COLOR_WHITE.full) ? LV_COLOR_RED : LV_COLOR_WHITE; + } else { + return; + } Update(!isOn, brightnessLevel); } } @@ -35,6 +41,7 @@ namespace Pinetime { lv_obj_t* flashLight; lv_obj_t* backgroundAction; lv_obj_t* indicators[3]; + lv_color_t color; bool isOn = false; }; } diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 97faaa7..f43f8c8 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -128,11 +128,14 @@ void QuickSettings::UpdateScreen() { } void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { - if (object == btn2 && event == LV_EVENT_CLICKED) { - - running = false; - app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up); - + if (object == btn2) { + if (event == LV_EVENT_CLICKED) { + running = false; + app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up); + } else if (event == LV_EVENT_LONG_PRESSED) { + running = false; + app->StartApp(Apps::FlashLightRed, DisplayApp::FullRefreshDirections::Up); + } } else if (object == btn1 && event == LV_EVENT_CLICKED) { brightness.Step(); -- cgit v0.10.2