2021-04-04 02:08:51 +00:00
|
|
|
#include "QuickSettings.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
|
|
|
#include "displayapp/screens/BatteryIcon.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
2021-04-18 17:28:14 +00:00
|
|
|
static void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
2021-06-06 13:56:03 +00:00
|
|
|
auto* screen = static_cast<QuickSettings*>(obj->user_data);
|
2021-04-04 02:08:51 +00:00
|
|
|
screen->OnButtonEvent(obj, event);
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
static void lv_update_task(struct _lv_task_t* task) {
|
2021-06-06 13:56:03 +00:00
|
|
|
auto* user_data = static_cast<QuickSettings*>(task->user_data);
|
2021-04-04 02:08:51 +00:00
|
|
|
user_data->UpdateScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
|
|
|
Pinetime::Controllers::Battery& batteryController,
|
|
|
|
Controllers::DateTime& dateTimeController,
|
|
|
|
Controllers::BrightnessController& brightness,
|
2021-04-20 11:31:40 +00:00
|
|
|
Controllers::MotorController& motorController,
|
2021-04-18 17:28:14 +00:00
|
|
|
Pinetime::Controllers::Settings& settingsController)
|
|
|
|
: Screen(app),
|
|
|
|
batteryController {batteryController},
|
|
|
|
dateTimeController {dateTimeController},
|
|
|
|
brightness {brightness},
|
2021-07-25 14:54:05 +00:00
|
|
|
motorController {motorController},
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsController {settingsController} {
|
2021-04-04 02:08:51 +00:00
|
|
|
|
2021-06-13 09:47:12 +00:00
|
|
|
// This is the distance (padding) between all objects on this screen.
|
|
|
|
const int innerDistance = 10;
|
|
|
|
|
2021-04-04 02:08:51 +00:00
|
|
|
// Time
|
2021-04-18 17:28:14 +00:00
|
|
|
label_time = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
|
|
|
|
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_style_init(&btn_style);
|
|
|
|
lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, (LV_VER_RES - 20 - 2 * innerDistance) / 8);
|
|
|
|
lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
btn1 = lv_btn_create(lv_scr_act(), nullptr);
|
|
|
|
btn1->user_data = this;
|
|
|
|
lv_obj_set_event_cb(btn1, ButtonEventHandler);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_add_style(btn1, LV_BTN_PART_MAIN, &btn_style);
|
|
|
|
lv_obj_set_size(btn1, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2);
|
|
|
|
lv_obj_align(btn1, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 20 + innerDistance);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
btn1_lvl = lv_label_create(btn1, nullptr);
|
|
|
|
lv_obj_set_style_local_text_font(btn1_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
|
|
|
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
|
|
|
|
|
|
|
|
btn2 = lv_btn_create(lv_scr_act(), nullptr);
|
|
|
|
btn2->user_data = this;
|
|
|
|
lv_obj_set_event_cb(btn2, ButtonEventHandler);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &btn_style);
|
|
|
|
lv_obj_set_size(btn2, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2);
|
|
|
|
lv_obj_align(btn2, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 20 + innerDistance);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_t* lbl_btn;
|
2021-04-04 02:08:51 +00:00
|
|
|
lbl_btn = lv_label_create(btn2, nullptr);
|
|
|
|
lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
|
|
|
lv_label_set_text_static(lbl_btn, Symbols::highlight);
|
|
|
|
|
|
|
|
btn3 = lv_btn_create(lv_scr_act(), nullptr);
|
|
|
|
btn3->user_data = this;
|
|
|
|
lv_obj_set_event_cb(btn3, ButtonEventHandler);
|
|
|
|
lv_btn_set_checkable(btn3, true);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_set_size(btn3, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2);
|
|
|
|
lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
btn3_lvl = lv_label_create(btn3, nullptr);
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::ON) {
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_obj_add_state(btn3, LV_STATE_CHECKED);
|
|
|
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
|
|
|
} else {
|
|
|
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
|
|
|
}
|
|
|
|
|
|
|
|
btn4 = lv_btn_create(lv_scr_act(), nullptr);
|
|
|
|
btn4->user_data = this;
|
|
|
|
lv_obj_set_event_cb(btn4, ButtonEventHandler);
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_obj_add_style(btn4, LV_BTN_PART_MAIN, &btn_style);
|
|
|
|
lv_obj_set_size(btn4, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2);
|
|
|
|
lv_obj_align(btn4, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
2021-04-04 02:08:51 +00:00
|
|
|
|
|
|
|
lbl_btn = lv_label_create(btn4, nullptr);
|
|
|
|
lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
|
|
|
lv_label_set_text_static(lbl_btn, Symbols::settings);
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text_static(backgroundLabel, "");
|
|
|
|
|
2021-07-07 12:47:47 +00:00
|
|
|
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
|
2021-04-04 02:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QuickSettings::~QuickSettings() {
|
2021-06-13 09:47:12 +00:00
|
|
|
lv_style_reset(&btn_style);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_task_del(taskUpdate);
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
settingsController.SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuickSettings::UpdateScreen() {
|
2021-04-18 17:28:14 +00:00
|
|
|
lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
|
|
|
|
if (object == btn2 && event == LV_EVENT_PRESSED) {
|
|
|
|
|
2021-04-04 02:08:51 +00:00
|
|
|
running = false;
|
|
|
|
app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::None);
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
} else if (object == btn1 && event == LV_EVENT_PRESSED) {
|
|
|
|
|
2021-04-04 02:08:51 +00:00
|
|
|
brightness.Step();
|
|
|
|
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsController.SetBrightness(brightness.Level());
|
|
|
|
|
|
|
|
} else if (object == btn3 && event == LV_EVENT_VALUE_CHANGED) {
|
2021-04-04 02:08:51 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
|
|
|
|
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::ON);
|
2021-08-01 10:05:48 +00:00
|
|
|
motorController.RunForDuration(35);
|
2021-04-04 02:08:51 +00:00
|
|
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
|
|
|
} else {
|
|
|
|
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::OFF);
|
|
|
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
} else if (object == btn4 && event == LV_EVENT_PRESSED) {
|
2021-04-04 02:08:51 +00:00
|
|
|
running = false;
|
|
|
|
settingsController.SetSettingsMenu(0);
|
|
|
|
app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QuickSettings::Refresh() {
|
|
|
|
return running;
|
|
|
|
}
|