Skip to content

Commit d5d6c62

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 7baf2a6 commit d5d6c62

File tree

10 files changed

+164
-12
lines changed

10 files changed

+164
-12
lines changed

src/CMakeLists.txt

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

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,
@@ -253,6 +254,21 @@ namespace Pinetime {
253254
return getWakeUpModes()[static_cast<size_t>(mode)];
254255
}
255256

257+
void SetAutoOpen(AutoOpen app, bool enabled) {
258+
if (enabled != IsAutoOpenOn(app)) {
259+
settingsChanged = true;
260+
}
261+
settings.autoOpen.set(static_cast<size_t>(app), enabled);
262+
}
263+
264+
bool IsAutoOpenOn(const AutoOpen app) const {
265+
return GetAutoOpen()[static_cast<size_t>(app)];
266+
}
267+
268+
std::bitset<3> GetAutoOpen() const {
269+
return settings.autoOpen;
270+
}
271+
256272
void SetBrightness(Controllers::BrightnessController::Levels level) {
257273
if (level != settings.brightLevel) {
258274
settingsChanged = true;
@@ -308,6 +324,8 @@ namespace Pinetime {
308324
uint16_t shakeWakeThreshold = 150;
309325

310326
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
327+
328+
std::bitset<3> autoOpen {0b000};
311329
};
312330

313331
SettingsData settings;

src/displayapp/DisplayApp.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "displayapp/screens/settings/SettingSteps.h"
4747
#include "displayapp/screens/settings/SettingSetDateTime.h"
4848
#include "displayapp/screens/settings/SettingChimes.h"
49+
#include "displayapp/screens/settings/SettingAutoOpen.h"
4950
#include "displayapp/screens/settings/SettingShakeThreshold.h"
5051
#include "displayapp/screens/settings/SettingBluetooth.h"
5152

@@ -399,15 +400,23 @@ void DisplayApp::Refresh() {
399400
break;
400401
case Messages::OnChargingEvent:
401402
RestoreBrightness();
402-
if (batteryController.IsCharging() && currentApp == Apps::Clock) {
403-
// Open the battery app if on the clock screen
404-
LoadNewScreen(Apps::BatteryInfo, DisplayApp::FullRefreshDirections::None);
405-
} else if (!batteryController.IsCharging() && currentApp == Apps::BatteryInfo) {
406-
// Close the battery app after being unplugged
407-
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
408-
} else {
409-
// Vibrate normally otherwise as to not close any open app
410-
motorController.RunForDuration(15);
403+
switch (currentApp) {
404+
case Apps::Clock:
405+
if (batteryController.IsCharging() && settingsController.IsAutoOpenOn(Controllers::Settings::AutoOpen::Battery)) {
406+
// Open the battery app if on the clock screen
407+
LoadNewScreen(Apps::BatteryInfo, DisplayApp::FullRefreshDirections::None);
408+
}
409+
break;
410+
case Apps::BatteryInfo:
411+
if (!batteryController.IsCharging()) {
412+
// Close the battery app after being unplugged
413+
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
414+
}
415+
break;
416+
default:
417+
// Vibrate normally otherwise as to not close any open app
418+
motorController.RunForDuration(15);
419+
break;
411420
}
412421
break;
413422
}
@@ -546,6 +555,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
546555
case Apps::SettingChimes:
547556
currentScreen = std::make_unique<Screens::SettingChimes>(settingsController);
548557
break;
558+
case Apps::SettingAutoOpen:
559+
currentScreen = std::make_unique<Screens::SettingAutoOpen>(settingsController);
560+
break;
549561
case Apps::SettingShakeThreshold:
550562
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(settingsController, motionController, *systemTask);
551563
break;

src/displayapp/apps/Apps.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace Pinetime {
3939
SettingSteps,
4040
SettingSetDateTime,
4141
SettingChimes,
42+
SettingAutoOpen,
4243
SettingShakeThreshold,
4344
SettingBluetooth,
4445
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
@@ -386,10 +386,14 @@ void SystemTask::Work() {
386386
}
387387
break;
388388
case Messages::OnMusicStarted:
389-
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
389+
if (settingsController.IsAutoOpenOn(Controllers::Settings::AutoOpen::Music)) {
390+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::MusicStarted);
391+
}
390392
break;
391393
case Messages::OnNavChange:
392-
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NavStarted);
394+
if (settingsController.IsAutoOpenOn(Controllers::Settings::AutoOpen::Navigation)) {
395+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NavStarted);
396+
}
393397
break;
394398
default:
395399
break;

0 commit comments

Comments
 (0)