-
-
Notifications
You must be signed in to change notification settings - Fork 954
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
settings: Add sleep/wake notification times
Add configure screens for sleep and wake notification times, so the watch can automatically set notifications to sleep or on as applicable.
- Loading branch information
1 parent
2135e12
commit 3ab8460
Showing
12 changed files
with
427 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/displayapp/screens/settings/SettingSetSleepTime.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "displayapp/screens/settings/SettingSetSleepTime.h" | ||
#include <lvgl/lvgl.h> | ||
#include <nrf_log.h> | ||
#include "displayapp/DisplayApp.h" | ||
#include "displayapp/screens/Symbols.h" | ||
#include "components/settings/Settings.h" | ||
#include "displayapp/InfiniTimeTheme.h" | ||
|
||
using namespace Pinetime::Applications::Screens; | ||
|
||
namespace { | ||
constexpr int16_t POS_Y_TEXT = -7; | ||
|
||
void SetTimeEventHandler(lv_obj_t* obj, lv_event_t event) { | ||
auto* screen = static_cast<SettingSetSleepTime*>(obj->user_data); | ||
if (event == LV_EVENT_CLICKED) { | ||
screen->SetTime(); | ||
} | ||
} | ||
|
||
void ValueChangedHandler(void* userData) { | ||
auto* screen = static_cast<SettingSetSleepTime*>(userData); | ||
screen->UpdateScreen(); | ||
} | ||
} | ||
|
||
SettingSetSleepTime::SettingSetSleepTime(Pinetime::Controllers::DateTime& dateTimeController, | ||
Pinetime::Controllers::Settings& settingsController, | ||
Pinetime::Applications::Screens::SettingSetSleepWakeTime& settingSetSleepWakeTime) | ||
: dateTimeController {dateTimeController}, settingsController {settingsController}, settingSetSleepWakeTime {settingSetSleepWakeTime} { | ||
|
||
uint8_t h, m; | ||
|
||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); | ||
lv_label_set_text_static(title, "Set sleep time"); | ||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); | ||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 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); | ||
|
||
lv_obj_t* staticLabel = lv_label_create(lv_scr_act(), nullptr); | ||
lv_obj_set_style_local_text_font(staticLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); | ||
lv_label_set_text_static(staticLabel, "00:00:00"); | ||
lv_obj_align(staticLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, POS_Y_TEXT); | ||
|
||
hourCounter.Create(); | ||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { | ||
hourCounter.EnableTwelveHourMode(); | ||
} | ||
settingsController.GetSleepTime(h, m); | ||
hourCounter.SetValue(h); | ||
lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_CENTER, -75, POS_Y_TEXT); | ||
hourCounter.SetValueChangedEventCallback(this, ValueChangedHandler); | ||
|
||
minuteCounter.Create(); | ||
minuteCounter.SetValue(m); | ||
lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_CENTER, 0, POS_Y_TEXT); | ||
minuteCounter.SetValueChangedEventCallback(this, ValueChangedHandler); | ||
|
||
lblampm = lv_label_create(lv_scr_act(), nullptr); | ||
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); | ||
lv_label_set_text_static(lblampm, " "); | ||
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 75, -50); | ||
|
||
btnSetTime = lv_btn_create(lv_scr_act(), nullptr); | ||
btnSetTime->user_data = this; | ||
lv_obj_set_size(btnSetTime, 120, 50); | ||
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); | ||
lblSetTime = lv_label_create(btnSetTime, nullptr); | ||
lv_label_set_text_static(lblSetTime, "Set"); | ||
lv_obj_set_style_local_bg_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); | ||
lv_obj_set_style_local_text_color(lblSetTime, LV_LABEL_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_GRAY); | ||
lv_obj_set_event_cb(btnSetTime, SetTimeEventHandler); | ||
|
||
UpdateScreen(); | ||
} | ||
|
||
SettingSetSleepTime::~SettingSetSleepTime() { | ||
lv_obj_clean(lv_scr_act()); | ||
} | ||
|
||
void SettingSetSleepTime::UpdateScreen() { | ||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { | ||
if (hourCounter.GetValue() >= 12) { | ||
lv_label_set_text_static(lblampm, "PM"); | ||
} else { | ||
lv_label_set_text_static(lblampm, "AM"); | ||
} | ||
} | ||
} | ||
|
||
void SettingSetSleepTime::SetTime() { | ||
const int hoursValue = hourCounter.GetValue(); | ||
const int minutesValue = minuteCounter.GetValue(); | ||
NRF_LOG_INFO("Setting sleep time to %02d:%02d:00", hoursValue, minutesValue); | ||
settingsController.SetSleepTime(static_cast<uint8_t>(hoursValue), | ||
static_cast<uint8_t>(minutesValue)); | ||
settingSetSleepWakeTime.Quit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <lvgl/lvgl.h> | ||
#include "components/datetime/DateTimeController.h" | ||
#include "components/settings/Settings.h" | ||
#include "displayapp/widgets/Counter.h" | ||
#include "displayapp/screens/Screen.h" | ||
#include "displayapp/widgets/DotIndicator.h" | ||
#include "displayapp/screens/settings/SettingSetSleepWakeTime.h" | ||
|
||
namespace Pinetime { | ||
namespace Applications { | ||
namespace Screens { | ||
class SettingSetSleepTime : public Screen { | ||
public: | ||
SettingSetSleepTime(Pinetime::Controllers::DateTime& dateTimeController, | ||
Pinetime::Controllers::Settings& settingsController, | ||
Pinetime::Applications::Screens::SettingSetSleepWakeTime& settingSetSleepWakeTime); | ||
~SettingSetSleepTime() override; | ||
|
||
void SetTime(); | ||
void UpdateScreen(); | ||
|
||
private: | ||
Controllers::DateTime& dateTimeController; | ||
Controllers::Settings& settingsController; | ||
Pinetime::Applications::Screens::SettingSetSleepWakeTime& settingSetSleepWakeTime; | ||
|
||
lv_obj_t* lblampm; | ||
lv_obj_t* btnSetTime; | ||
lv_obj_t* lblSetTime; | ||
Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_42); | ||
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_42); | ||
}; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/displayapp/screens/settings/SettingSetSleepWakeTime.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "displayapp/screens/settings/SettingSetSleepWakeTime.h" | ||
#include "displayapp/screens/settings/SettingSetSleepTime.h" | ||
#include "displayapp/screens/settings/SettingSetWakeTime.h" | ||
#include "displayapp/DisplayApp.h" | ||
#include "displayapp/screens/ScreenList.h" | ||
#include "components/settings/Settings.h" | ||
#include "displayapp/widgets/DotIndicator.h" | ||
|
||
using namespace Pinetime::Applications::Screens; | ||
|
||
bool SettingSetSleepWakeTime::OnTouchEvent(Pinetime::Applications::TouchEvents event) { | ||
return screens.OnTouchEvent(event); | ||
} | ||
|
||
SettingSetSleepWakeTime::SettingSetSleepWakeTime(Pinetime::Applications::DisplayApp* app, | ||
Pinetime::Controllers::DateTime& dateTimeController, | ||
Pinetime::Controllers::Settings& settingsController) | ||
: app {app}, | ||
dateTimeController {dateTimeController}, | ||
settingsController {settingsController}, | ||
screens {app, | ||
0, | ||
{[this]() -> std::unique_ptr<Screen> { | ||
return screenSetSleepTime(); | ||
}, | ||
[this]() -> std::unique_ptr<Screen> { | ||
return screenSetWakeTime(); | ||
}}, | ||
Screens::ScreenListModes::UpDown} { | ||
} | ||
|
||
std::unique_ptr<Screen> SettingSetSleepWakeTime::screenSetSleepTime() { | ||
Widgets::DotIndicator dotIndicator(0, 2); | ||
dotIndicator.Create(); | ||
return std::make_unique<Screens::SettingSetSleepTime>(dateTimeController, settingsController, *this); | ||
} | ||
|
||
std::unique_ptr<Screen> SettingSetSleepWakeTime::screenSetWakeTime() { | ||
Widgets::DotIndicator dotIndicator(1, 2); | ||
dotIndicator.Create(); | ||
return std::make_unique<Screens::SettingSetWakeTime>(dateTimeController, settingsController, *this); | ||
} | ||
|
||
SettingSetSleepWakeTime::~SettingSetSleepWakeTime() { | ||
lv_obj_clean(lv_scr_act()); | ||
} | ||
|
||
void SettingSetSleepWakeTime::Advance() { | ||
screens.OnTouchEvent(Pinetime::Applications::TouchEvents::SwipeUp); | ||
} | ||
|
||
void SettingSetSleepWakeTime::Quit() { | ||
running = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <lvgl/lvgl.h> | ||
#include "displayapp/screens/Screen.h" | ||
#include "displayapp/screens/ScreenList.h" | ||
|
||
namespace Pinetime { | ||
namespace Applications { | ||
namespace Screens { | ||
class SettingSetSleepWakeTime : public Screen { | ||
public: | ||
SettingSetSleepWakeTime(DisplayApp* app, | ||
Pinetime::Controllers::DateTime& dateTimeController, | ||
Pinetime::Controllers::Settings& settingsController); | ||
~SettingSetSleepWakeTime() override; | ||
|
||
bool OnTouchEvent(TouchEvents event) override; | ||
void Advance(); | ||
void Quit(); | ||
|
||
private: | ||
DisplayApp* app; | ||
Controllers::DateTime& dateTimeController; | ||
Controllers::Settings& settingsController; | ||
|
||
ScreenList<2> screens; | ||
std::unique_ptr<Screen> screenSetSleepTime(); | ||
std::unique_ptr<Screen> screenSetWakeTime(); | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.