diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-03-27 10:44:47 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-03-27 10:52:52 (GMT) |
| commit | fa38eb8721d159623a344abae2bb510417b2f7a6 (patch) | |
| tree | 5fedd399e4b5c4823608d316e9fce763bfdf5e6e /src/displayapp/screens | |
| parent | 06fc04bcb3b0993c0b1ff2a13848e62b0eaeb529 (diff) | |
Adding back chimes and torch
Diffstat (limited to 'src/displayapp/screens')
| -rw-r--r-- | src/displayapp/screens/FlashLight.cpp | 134 | ||||
| -rw-r--r-- | src/displayapp/screens/FlashLight.h | 38 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/QuickSettings.cpp | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/SettingChimes.cpp | 100 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/SettingChimes.h | 27 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/Settings.cpp | 2 |
6 files changed, 304 insertions, 1 deletions
diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp new file mode 100644 index 0000000..c4d0264 --- /dev/null +++ b/src/displayapp/screens/FlashLight.cpp @@ -0,0 +1,134 @@ +#include "displayapp/screens/FlashLight.h" +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.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); + } +} + +FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, + System::SystemTask& systemTask, + Controllers::BrightnessController& brightnessController) + : Screen(app), + systemTask {systemTask}, + brightnessController {brightnessController} + +{ + brightnessController.Backup(); + + brightnessLevel = brightnessController.Level(); + + 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_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(); + + backgroundAction = lv_label_create(lv_scr_act(), nullptr); + 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); + backgroundAction->user_data = this; + lv_obj_set_event_cb(backgroundAction, event_handler); + + systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); +} + +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_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); + } + } 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(); + } +} + +bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + 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; + } + + return false; +} diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h new file mode 100644 index 0000000..e91a103 --- /dev/null +++ b/src/displayapp/screens/FlashLight.h @@ -0,0 +1,38 @@ +#pragma once + +#include "displayapp/screens/Screen.h" +#include "components/brightness/BrightnessController.h" +#include "systemtask/SystemTask.h" +#include <cstdint> +#include <lvgl/lvgl.h> + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class FlashLight : public Screen { + public: + FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness); + ~FlashLight() override; + + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + void OnClickEvent(lv_obj_t* obj, lv_event_t event); + + private: + void SetIndicators(); + void SetColors(); + + Pinetime::System::SystemTask& systemTask; + Controllers::BrightnessController& brightnessController; + + Controllers::BrightnessController::Levels brightnessLevel; + + lv_obj_t* flashLight; + lv_obj_t* backgroundAction; + lv_obj_t* indicators[3]; + bool isOn = false; + }; + } + } +} diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index c00518e..cd56c14 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -129,6 +129,10 @@ 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); + } else if (object == btn1 && event == LV_EVENT_CLICKED) { brightness.Step(); diff --git a/src/displayapp/screens/settings/SettingChimes.cpp b/src/displayapp/screens/settings/SettingChimes.cpp new file mode 100644 index 0000000..543b5e0 --- /dev/null +++ b/src/displayapp/screens/settings/SettingChimes.cpp @@ -0,0 +1,100 @@ +#include "displayapp/screens/settings/SettingChimes.h" +#include <lvgl/lvgl.h> +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Styles.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + SettingChimes* screen = static_cast<SettingChimes*>(obj->user_data); + screen->UpdateSelected(obj, event); + } +} + +SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) + : Screen(app), settingsController {settingsController} { + + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); + + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 10, 60); + lv_obj_set_width(container1, LV_HOR_RES - 20); + lv_obj_set_height(container1, LV_VER_RES - 50); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, "Chimes"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); + + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(icon, Symbols::clock); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + optionsTotal = 0; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Off"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + SetRadioButtonStyle(cbOption[optionsTotal]); + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::None) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Every hour"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + SetRadioButtonStyle(cbOption[optionsTotal]); + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 30 mins"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + SetRadioButtonStyle(cbOption[optionsTotal]); + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; +} + +SettingChimes::~SettingChimes() { + lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); +} + +void SettingChimes::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_VALUE_CHANGED) { + for (uint8_t i = 0; i < optionsTotal; i++) { + if (object == cbOption[i]) { + lv_checkbox_set_checked(cbOption[i], true); + if (i == 0) { + settingsController.SetChimeOption(Controllers::Settings::ChimesOption::None); + } + if (i == 1) { + settingsController.SetChimeOption(Controllers::Settings::ChimesOption::Hours); + } + if (i == 2) { + settingsController.SetChimeOption(Controllers::Settings::ChimesOption::HalfHours); + } + } else { + lv_checkbox_set_checked(cbOption[i], false); + } + } + } +} diff --git a/src/displayapp/screens/settings/SettingChimes.h b/src/displayapp/screens/settings/SettingChimes.h new file mode 100644 index 0000000..a251e95 --- /dev/null +++ b/src/displayapp/screens/settings/SettingChimes.h @@ -0,0 +1,27 @@ +#pragma once + +#include <cstdint> +#include <lvgl/lvgl.h> +#include "components/settings/Settings.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingChimes : public Screen { + public: + SettingChimes(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); + ~SettingChimes() override; + + void UpdateSelected(lv_obj_t* object, lv_event_t event); + + private: + Controllers::Settings& settingsController; + uint8_t optionsTotal; + lv_obj_t* cbOption[3]; + }; + } + } +} diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index 3d257ae..9e19d20 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -37,7 +37,7 @@ std::unique_ptr<Screen> Settings::CreateScreen1() { {Symbols::sun, "Display", Apps::SettingDisplay}, {Symbols::eye, "Wake Up", Apps::SettingWakeUp}, {Symbols::clock, "Time format", Apps::SettingTimeFormat}, - {Symbols::none, "None", Apps::None} + {Symbols::clock, "Chimes", Apps::SettingChimes}, }}; return std::make_unique<Screens::List>(0, 1, app, settingsController, applications); |
