Skip to content

Commit ac37822

Browse files
committed
activity: Add settings interface to change threshold
1 parent 5226689 commit ac37822

6 files changed

Lines changed: 143 additions & 7 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ list(APPEND SOURCE_FILES
424424
displayapp/screens/settings/SettingChimes.cpp
425425
displayapp/screens/settings/SettingShakeThreshold.cpp
426426
displayapp/screens/settings/SettingBluetooth.cpp
427+
displayapp/screens/settings/SettingActivity.cpp
427428

428429
## Watch faces
429430
displayapp/icons/bg_clock.c

src/displayapp/Apps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Pinetime {
3737
SettingChimes,
3838
SettingShakeThreshold,
3939
SettingBluetooth,
40+
SettingActivity,
4041
Error
4142
};
4243
}

src/displayapp/DisplayApp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "displayapp/screens/settings/SettingChimes.h"
4848
#include "displayapp/screens/settings/SettingShakeThreshold.h"
4949
#include "displayapp/screens/settings/SettingBluetooth.h"
50+
#include "displayapp/screens/settings/SettingActivity.h"
5051

5152
#include "libs/lv_conf.h"
5253

@@ -491,6 +492,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
491492
case Apps::SettingBluetooth:
492493
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
493494
break;
495+
case Apps::SettingActivity:
496+
currentScreen = std::make_unique<Screens::SettingActivity>(settingsController);
497+
break;
494498
case Apps::BatteryInfo:
495499
currentScreen = std::make_unique<Screens::BatteryInfo>(batteryController);
496500
break;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "displayapp/screens/settings/SettingActivity.h"
2+
3+
#include <cstdint>
4+
#include <cinttypes>
5+
6+
#include "displayapp/DisplayApp.h"
7+
#include "displayapp/screens/Symbols.h"
8+
9+
using namespace Pinetime::Applications::Screens;
10+
11+
namespace {
12+
void EventHandler(lv_obj_t* obj, lv_event_t event) {
13+
SettingActivity* screen = static_cast<SettingActivity*>(obj->user_data);
14+
screen->UpdateSelected(obj, event);
15+
}
16+
}
17+
18+
SettingActivity::SettingActivity(Controllers::Settings& settingsController) : settingsController {settingsController} {
19+
lv_obj_t* container = lv_cont_create(lv_scr_act(), nullptr);
20+
21+
lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
22+
lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
23+
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
24+
lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
25+
lv_obj_set_pos(container, 30, 60);
26+
lv_obj_set_width(container, LV_HOR_RES - 50);
27+
lv_obj_set_height(container, LV_VER_RES - 60);
28+
lv_cont_set_layout(container, LV_LAYOUT_COLUMN_LEFT);
29+
30+
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
31+
lv_label_set_text_static(title, "Activity notifications");
32+
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
33+
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);
34+
35+
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
36+
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
37+
38+
lv_label_set_text_static(icon, Symbols::shoe);
39+
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
40+
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
41+
42+
enabled = lv_checkbox_create(container, nullptr);
43+
lv_checkbox_set_text(enabled, "Enabled");
44+
if (settingsController.GetActivity() == Controllers::Settings::Activity::On) {
45+
lv_checkbox_set_checked(enabled, true);
46+
}
47+
enabled->user_data = this;
48+
lv_obj_set_event_cb(enabled, EventHandler);
49+
50+
stepValue = lv_label_create(lv_scr_act(), nullptr);
51+
lv_obj_set_style_local_text_font(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
52+
lv_label_set_text_fmt(stepValue, "%" PRIu32, settingsController.GetActivityThresh());
53+
lv_label_set_align(stepValue, LV_LABEL_ALIGN_CENTER);
54+
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);
55+
56+
btnPlus = lv_btn_create(lv_scr_act(), nullptr);
57+
btnPlus->user_data = this;
58+
lv_obj_set_size(btnPlus, 80, 50);
59+
lv_obj_align(btnPlus, lv_scr_act(), LV_ALIGN_CENTER, 55, 80);
60+
lv_obj_t* lblPlus = lv_label_create(btnPlus, nullptr);
61+
lv_label_set_text_static(lblPlus, "+");
62+
lv_obj_set_event_cb(btnPlus, EventHandler);
63+
64+
btnMinus = lv_btn_create(lv_scr_act(), nullptr);
65+
btnMinus->user_data = this;
66+
lv_obj_set_size(btnMinus, 80, 50);
67+
lv_obj_set_event_cb(btnMinus, EventHandler);
68+
lv_obj_align(btnMinus, lv_scr_act(), LV_ALIGN_CENTER, -55, 80);
69+
lv_obj_t* lblMinus = lv_label_create(btnMinus, nullptr);
70+
lv_label_set_text_static(lblMinus, "-");
71+
}
72+
73+
SettingActivity::~SettingActivity() {
74+
lv_obj_clean(lv_scr_act());
75+
settingsController.SaveSettings();
76+
}
77+
78+
void SettingActivity::UpdateSelected(lv_obj_t* object, lv_event_t event) {
79+
uint16_t value = settingsController.GetActivityThresh();
80+
if (object == btnPlus && event == LV_EVENT_PRESSED) {
81+
value += 1;
82+
if (value <= 15000) {
83+
settingsController.SetActivityThresh(value);
84+
lv_label_set_text_fmt(stepValue, "%" PRIu16, settingsController.GetActivityThresh());
85+
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);
86+
}
87+
}
88+
89+
if (object == btnMinus && event == LV_EVENT_PRESSED) {
90+
value -= 1;
91+
if (value >= 1) {
92+
settingsController.SetActivityThresh(value);
93+
lv_label_set_text_fmt(stepValue, "%" PRIu16, settingsController.GetActivityThresh());
94+
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);
95+
}
96+
}
97+
98+
if (object == enabled && event == LV_EVENT_VALUE_CHANGED) {
99+
bool currentState = settingsController.GetActivity() == Controllers::Settings::Activity::On;
100+
settingsController.SetActivity(currentState ? Controllers::Settings::Activity::Off : Controllers::Settings::Activity::On);
101+
lv_checkbox_set_checked(enabled, !currentState);
102+
}
103+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <lvgl/lvgl.h>
4+
5+
#include "components/settings/Settings.h"
6+
#include "displayapp/screens/Screen.h"
7+
8+
namespace Pinetime {
9+
namespace Applications {
10+
namespace Screens {
11+
class SettingActivity : public Screen {
12+
public:
13+
explicit SettingActivity(Controllers::Settings& settingsController);
14+
~SettingActivity() override;
15+
16+
void UpdateSelected(lv_obj_t* object, lv_event_t event);
17+
18+
private:
19+
Controllers::Settings& settingsController;
20+
21+
lv_obj_t* enabled;
22+
lv_obj_t* stepValue;
23+
lv_obj_t* btnPlus;
24+
lv_obj_t* btnMinus;
25+
};
26+
}
27+
}
28+
}

src/displayapp/screens/settings/Settings.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Pinetime {
2929
static constexpr int entriesPerScreen = 4;
3030

3131
// Increment this when more space is needed
32-
static constexpr int nScreens = 3;
32+
static constexpr int nScreens = 4;
3333

3434
static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
3535
{Symbols::sun, "Display", Apps::SettingDisplay},
@@ -45,13 +45,12 @@ namespace Pinetime {
4545
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
4646
{Symbols::check, "Firmware", Apps::FirmwareValidation},
4747
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
48-
{Symbols::list, "About", Apps::SysInfo},
49-
50-
// {Symbols::none, "None", Apps::None},
51-
// {Symbols::none, "None", Apps::None},
52-
// {Symbols::none, "None", Apps::None},
53-
// {Symbols::none, "None", Apps::None},
48+
{Symbols::shoe, "Activity", Apps::SettingActivity},
5449

50+
{Symbols::list, "About", Apps::SysInfo},
51+
{Symbols::none, "None", Apps::None},
52+
{Symbols::none, "None", Apps::None},
53+
{Symbols::none, "None", Apps::None},
5554
}};
5655
ScreenList<nScreens> screens;
5756
};

0 commit comments

Comments
 (0)