Skip to content

Commit 96959c5

Browse files
committed
settings: Add setting for auto-opening apps
Certain apps can be configured to auto-open based on component events: - battery: when charging the watch - music: when playing music from the paired device - navigation: when opening a maps app on the paired device
1 parent 2165fe6 commit 96959c5

File tree

10 files changed

+147
-3
lines changed

10 files changed

+147
-3
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ list(APPEND SOURCE_FILES
416416
displayapp/screens/settings/SettingSetDate.cpp
417417
displayapp/screens/settings/SettingSetTime.cpp
418418
displayapp/screens/settings/SettingChimes.cpp
419+
displayapp/screens/settings/SettingAutoOpen.cpp
419420
displayapp/screens/settings/SettingShakeThreshold.cpp
420421
displayapp/screens/settings/SettingBluetooth.cpp
421422

src/components/settings/Settings.h

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Pinetime {
1414
enum class Notification : uint8_t { On, Off, Sleep };
1515
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
1616
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
17+
enum class AutoOpen : uint8_t { Battery = 0, Music = 1, Navigation = 2 };
1718
enum class Colors : uint8_t {
1819
White,
1920
Silver,
@@ -268,6 +269,21 @@ namespace Pinetime {
268269
return getWakeUpModes()[static_cast<size_t>(mode)];
269270
}
270271

272+
void SetAutoOpen(AutoOpen app, bool enabled) {
273+
if (enabled != IsAutoOpenOn(app)) {
274+
settingsChanged = true;
275+
}
276+
settings.autoOpen.set(static_cast<size_t>(app), enabled);
277+
}
278+
279+
bool IsAutoOpenOn(const AutoOpen app) const {
280+
return GetAutoOpen()[static_cast<size_t>(app)];
281+
}
282+
283+
std::bitset<3> GetAutoOpen() const {
284+
return settings.autoOpen;
285+
}
286+
271287
void SetBrightness(Controllers::BrightnessController::Levels level) {
272288
if (level != settings.brightLevel) {
273289
settingsChanged = true;
@@ -325,6 +341,8 @@ namespace Pinetime {
325341
uint16_t shakeWakeThreshold = 150;
326342

327343
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
344+
345+
std::bitset<3> autoOpen {0b000};
328346
};
329347

330348
SettingsData settings;

src/displayapp/DisplayApp.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "displayapp/screens/settings/SettingSteps.h"
4848
#include "displayapp/screens/settings/SettingSetDateTime.h"
4949
#include "displayapp/screens/settings/SettingChimes.h"
50+
#include "displayapp/screens/settings/SettingAutoOpen.h"
5051
#include "displayapp/screens/settings/SettingShakeThreshold.h"
5152
#include "displayapp/screens/settings/SettingBluetooth.h"
5253

@@ -650,6 +651,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
650651
case Apps::SettingChimes:
651652
currentScreen = std::make_unique<Screens::SettingChimes>(settingsController);
652653
break;
654+
case Apps::SettingAutoOpen:
655+
currentScreen = std::make_unique<Screens::SettingAutoOpen>(settingsController);
656+
break;
653657
case Apps::SettingShakeThreshold:
654658
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(settingsController, motionController, *systemTask);
655659
break;

src/displayapp/apps/Apps.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace Pinetime {
4040
SettingSteps,
4141
SettingSetDateTime,
4242
SettingChimes,
43+
SettingAutoOpen,
4344
SettingShakeThreshold,
4445
SettingBluetooth,
4546
Error

src/displayapp/fonts/fonts.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{
99
"file": "FontAwesome5-Solid+Brands+Regular.woff",
10-
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743"
10+
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf0ad"
1111
}
1212
],
1313
"bpp": 1,

src/displayapp/screens/Symbols.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace Pinetime {
3939
static constexpr const char* eye = "\xEF\x81\xAE";
4040
static constexpr const char* home = "\xEF\x80\x95";
4141
static constexpr const char* sleep = "\xEE\xBD\x84";
42+
static constexpr const char* wrench = "\xEF\x82\xAD";
4243

4344
// fontawesome_weathericons.c
4445
// static constexpr const char* sun = "\xEF\x86\x85";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "displayapp/screens/settings/SettingAutoOpen.h"
2+
#include <lvgl/lvgl.h>
3+
#include "displayapp/DisplayApp.h"
4+
#include "displayapp/screens/Screen.h"
5+
#include "displayapp/screens/Symbols.h"
6+
7+
using namespace Pinetime::Applications::Screens;
8+
9+
constexpr std::array<SettingAutoOpen::Option, 3> SettingAutoOpen::options;
10+
11+
namespace {
12+
void event_handler(lv_obj_t* obj, lv_event_t event) {
13+
auto* screen = static_cast<SettingAutoOpen*>(obj->user_data);
14+
if (event == LV_EVENT_VALUE_CHANGED) {
15+
screen->UpdateSelected(obj);
16+
}
17+
}
18+
}
19+
20+
SettingAutoOpen::SettingAutoOpen(Pinetime::Controllers::Settings& settingsController) : settingsController {settingsController} {
21+
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
22+
23+
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
24+
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
25+
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
26+
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
27+
28+
lv_obj_set_pos(container1, 10, 35);
29+
lv_obj_set_width(container1, LV_HOR_RES - 20);
30+
lv_obj_set_height(container1, LV_VER_RES - 20);
31+
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
32+
33+
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
34+
lv_label_set_text_static(title, "Auto Open");
35+
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
36+
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);
37+
38+
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
39+
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
40+
lv_label_set_text_static(icon, Symbols::wrench);
41+
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
42+
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
43+
44+
for (unsigned int i = 0; i < options.size(); i++) {
45+
cbOption[i] = lv_checkbox_create(container1, nullptr);
46+
lv_checkbox_set_text(cbOption[i], options[i].name);
47+
if (settingsController.IsAutoOpenOn(static_cast<Controllers::Settings::AutoOpen>(i))) {
48+
lv_checkbox_set_checked(cbOption[i], true);
49+
}
50+
cbOption[i]->user_data = this;
51+
lv_obj_set_event_cb(cbOption[i], event_handler);
52+
}
53+
}
54+
55+
SettingAutoOpen::~SettingAutoOpen() {
56+
lv_obj_clean(lv_scr_act());
57+
settingsController.SaveSettings();
58+
}
59+
60+
void SettingAutoOpen::UpdateSelected(lv_obj_t* object) {
61+
// Find the index of the checkbox that triggered the event
62+
for (size_t i = 0; i < options.size(); i++) {
63+
if (cbOption[i] == object) {
64+
bool currentState = settingsController.IsAutoOpenOn(options[i].app);
65+
settingsController.SetAutoOpen(options[i].app, !currentState);
66+
break;
67+
}
68+
}
69+
70+
// Update checkbox according to current apps.
71+
auto apps = settingsController.GetAutoOpen();
72+
for (size_t i = 0; i < options.size(); ++i) {
73+
lv_checkbox_set_checked(cbOption[i], apps[i]);
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstdint>
5+
#include <lvgl/lvgl.h>
6+
7+
#include "components/settings/Settings.h"
8+
#include "displayapp/screens/Screen.h"
9+
10+
namespace Pinetime {
11+
12+
namespace Applications {
13+
namespace Screens {
14+
15+
class SettingAutoOpen : public Screen {
16+
public:
17+
SettingAutoOpen(Pinetime::Controllers::Settings& settingsController);
18+
~SettingAutoOpen() override;
19+
20+
void UpdateSelected(lv_obj_t* object);
21+
22+
private:
23+
struct Option {
24+
Controllers::Settings::AutoOpen app;
25+
const char* name;
26+
};
27+
28+
Controllers::Settings& settingsController;
29+
static constexpr std::array<Option, 3> options = {{
30+
{Controllers::Settings::AutoOpen::Battery, "Battery"},
31+
{Controllers::Settings::AutoOpen::Music, "Music"},
32+
{Controllers::Settings::AutoOpen::Navigation, "Navigation"},
33+
}};
34+
35+
lv_obj_t* cbOption[options.size()];
36+
};
37+
}
38+
}
39+
}

src/displayapp/screens/settings/Settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace Pinetime {
4747
{Symbols::check, "Firmware", Apps::FirmwareValidation},
4848
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
4949

50+
{Symbols::wrench, "Auto Open", Apps::SettingAutoOpen},
5051
{Symbols::list, "About", Apps::SysInfo},
5152

5253
// {Symbols::none, "None", Apps::None},

src/systemtask/SystemTask.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,14 @@ void SystemTask::Work() {
359359
}
360360
break;
361361
case Messages::OnMusicStarted:
362-
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
362+
if (settingsController.IsAutoOpenOn(Controllers::Settings::AutoOpen::Music)) {
363+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
364+
}
363365
break;
364366
case Messages::OnNavChange:
365-
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NavStarted);
367+
if (settingsController.IsAutoOpenOn(Controllers::Settings::AutoOpen::Navigation)) {
368+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NavStarted);
369+
}
366370
break;
367371
default:
368372
break;

0 commit comments

Comments
 (0)