Skip to content

Commit

Permalink
activity: Add settings interface to change threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
FintasticMan committed Apr 1, 2023
1 parent 5226689 commit ac37822
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingChimes.cpp
displayapp/screens/settings/SettingShakeThreshold.cpp
displayapp/screens/settings/SettingBluetooth.cpp
displayapp/screens/settings/SettingActivity.cpp

## Watch faces
displayapp/icons/bg_clock.c
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Pinetime {
SettingChimes,
SettingShakeThreshold,
SettingBluetooth,
SettingActivity,
Error
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "displayapp/screens/settings/SettingChimes.h"
#include "displayapp/screens/settings/SettingShakeThreshold.h"
#include "displayapp/screens/settings/SettingBluetooth.h"
#include "displayapp/screens/settings/SettingActivity.h"

#include "libs/lv_conf.h"

Expand Down Expand Up @@ -491,6 +492,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::SettingBluetooth:
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
break;
case Apps::SettingActivity:
currentScreen = std::make_unique<Screens::SettingActivity>(settingsController);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(batteryController);
break;
Expand Down
103 changes: 103 additions & 0 deletions src/displayapp/screens/settings/SettingActivity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "displayapp/screens/settings/SettingActivity.h"

#include <cstdint>
#include <cinttypes>

#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Symbols.h"

using namespace Pinetime::Applications::Screens;

namespace {
void EventHandler(lv_obj_t* obj, lv_event_t event) {
SettingActivity* screen = static_cast<SettingActivity*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
}

SettingActivity::SettingActivity(Controllers::Settings& settingsController) : settingsController {settingsController} {
lv_obj_t* container = lv_cont_create(lv_scr_act(), nullptr);

lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_obj_set_pos(container, 30, 60);
lv_obj_set_width(container, LV_HOR_RES - 50);
lv_obj_set_height(container, LV_VER_RES - 60);
lv_cont_set_layout(container, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Activity notifications");
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::shoe);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);

enabled = lv_checkbox_create(container, nullptr);
lv_checkbox_set_text(enabled, "Enabled");
if (settingsController.GetActivity() == Controllers::Settings::Activity::On) {
lv_checkbox_set_checked(enabled, true);
}
enabled->user_data = this;
lv_obj_set_event_cb(enabled, EventHandler);

stepValue = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_fmt(stepValue, "%" PRIu32, settingsController.GetActivityThresh());
lv_label_set_align(stepValue, LV_LABEL_ALIGN_CENTER);
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);

btnPlus = lv_btn_create(lv_scr_act(), nullptr);
btnPlus->user_data = this;
lv_obj_set_size(btnPlus, 80, 50);
lv_obj_align(btnPlus, lv_scr_act(), LV_ALIGN_CENTER, 55, 80);
lv_obj_t* lblPlus = lv_label_create(btnPlus, nullptr);
lv_label_set_text_static(lblPlus, "+");
lv_obj_set_event_cb(btnPlus, EventHandler);

btnMinus = lv_btn_create(lv_scr_act(), nullptr);
btnMinus->user_data = this;
lv_obj_set_size(btnMinus, 80, 50);
lv_obj_set_event_cb(btnMinus, EventHandler);
lv_obj_align(btnMinus, lv_scr_act(), LV_ALIGN_CENTER, -55, 80);
lv_obj_t* lblMinus = lv_label_create(btnMinus, nullptr);
lv_label_set_text_static(lblMinus, "-");
}

SettingActivity::~SettingActivity() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

void SettingActivity::UpdateSelected(lv_obj_t* object, lv_event_t event) {
uint16_t value = settingsController.GetActivityThresh();
if (object == btnPlus && event == LV_EVENT_PRESSED) {
value += 1;
if (value <= 15000) {
settingsController.SetActivityThresh(value);
lv_label_set_text_fmt(stepValue, "%" PRIu16, settingsController.GetActivityThresh());
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);
}
}

if (object == btnMinus && event == LV_EVENT_PRESSED) {
value -= 1;
if (value >= 1) {
settingsController.SetActivityThresh(value);
lv_label_set_text_fmt(stepValue, "%" PRIu16, settingsController.GetActivityThresh());
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);
}
}

if (object == enabled && event == LV_EVENT_VALUE_CHANGED) {
bool currentState = settingsController.GetActivity() == Controllers::Settings::Activity::On;
settingsController.SetActivity(currentState ? Controllers::Settings::Activity::Off : Controllers::Settings::Activity::On);
lv_checkbox_set_checked(enabled, !currentState);
}
}
28 changes: 28 additions & 0 deletions src/displayapp/screens/settings/SettingActivity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <lvgl/lvgl.h>

#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"

namespace Pinetime {
namespace Applications {
namespace Screens {
class SettingActivity : public Screen {
public:
explicit SettingActivity(Controllers::Settings& settingsController);
~SettingActivity() override;

void UpdateSelected(lv_obj_t* object, lv_event_t event);

private:
Controllers::Settings& settingsController;

lv_obj_t* enabled;
lv_obj_t* stepValue;
lv_obj_t* btnPlus;
lv_obj_t* btnMinus;
};
}
}
}
13 changes: 6 additions & 7 deletions src/displayapp/screens/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Pinetime {
static constexpr int entriesPerScreen = 4;

// Increment this when more space is needed
static constexpr int nScreens = 3;
static constexpr int nScreens = 4;

static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
{Symbols::sun, "Display", Apps::SettingDisplay},
Expand All @@ -45,13 +45,12 @@ namespace Pinetime {
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
{Symbols::check, "Firmware", Apps::FirmwareValidation},
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
{Symbols::list, "About", Apps::SysInfo},

// {Symbols::none, "None", Apps::None},
// {Symbols::none, "None", Apps::None},
// {Symbols::none, "None", Apps::None},
// {Symbols::none, "None", Apps::None},
{Symbols::shoe, "Activity", Apps::SettingActivity},

{Symbols::list, "About", Apps::SysInfo},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
}};
ScreenList<nScreens> screens;
};
Expand Down

0 comments on commit ac37822

Please sign in to comment.