Replace airplane mode with a bluetooth toggle

This commit is contained in:
Riku Isokoski
2022-04-02 16:03:20 +03:00
committed by JF
parent 8f436e1d74
commit 78365548f7
14 changed files with 72 additions and 90 deletions

View File

@@ -2,11 +2,7 @@
#include "displayapp/screens/Symbols.h"
using namespace Pinetime::Applications::Screens;
const char* BleIcon::GetIcon(bool isRadioEnabled, bool isConnected) {
if(!isRadioEnabled) {
return Symbols::airplane;
}
const char* BleIcon::GetIcon(bool isConnected) {
if (isConnected) {
return Symbols::bluetooth;
}

View File

@@ -7,7 +7,7 @@ namespace Pinetime {
namespace Screens {
class BleIcon {
public:
static const char* GetIcon(bool isRadioEnabled, bool isConnected);
static const char* GetIcon(bool isConnected);
};
}
}

View File

@@ -345,11 +345,10 @@ void PineTimeStyle::SetBatteryIcon() {
void PineTimeStyle::AlignIcons() {
bool isBleIconVisible = IsBleIconVisible(bleRadioEnabled.Get(), bleState.Get());
if (notificationState.Get() && isBleIconVisible) {
if (notificationState.Get() && bleState.Get()) {
lv_obj_align(bleIcon, sidebar, LV_ALIGN_IN_TOP_MID, 8, 25);
lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, -8, 25);
} else if (notificationState.Get() && !isBleIconVisible) {
} else if (notificationState.Get() && !bleState.Get()) {
lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 25);
} else {
lv_obj_align(bleIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 25);
@@ -375,7 +374,7 @@ void PineTimeStyle::Refresh() {
bleState = bleController.IsConnected();
bleRadioEnabled = bleController.IsRadioEnabled();
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleRadioEnabled.Get(), bleState.Get()));
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get()));
AlignIcons();
}

View File

@@ -44,7 +44,6 @@ namespace Pinetime {
static constexpr const char* chartLine = "\xEF\x88\x81";
static constexpr const char* eye = "\xEF\x81\xAE";
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* airplane = "\xEF\x81\xB2";
// lv_font_sys_48.c
static constexpr const char* settings = "\xEE\xA4\x82"; // e902

View File

@@ -121,7 +121,7 @@ void WatchFaceDigital::Refresh() {
bleState = bleController.IsConnected();
bleRadioEnabled = bleController.IsRadioEnabled();
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleRadioEnabled.Get(), bleState.Get()));
lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get()));
}
lv_obj_realign(batteryIcon);
lv_obj_realign(batteryPlug);

View File

@@ -1,4 +1,4 @@
#include "displayapp/screens/settings/SettingAirplaneMode.h"
#include "displayapp/screens/settings/SettingBluetooth.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/Messages.h"
@@ -9,18 +9,18 @@
using namespace Pinetime::Applications::Screens;
namespace {
static void OnAirplaneModeEnabledEvent(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<SettingAirplaneMode*>(obj->user_data);
screen->OnAirplaneModeEnabled(obj, event);
static void OnBluetoothDisabledEvent(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<SettingBluetooth*>(obj->user_data);
screen->OnBluetoothDisabled(obj, event);
}
static void OnAirplaneModeDisabledEvent(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<SettingAirplaneMode*>(obj->user_data);
screen->OnAirplaneModeDisabled(obj, event);
static void OnBluetoothEnabledEvent(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<SettingBluetooth*>(obj->user_data);
screen->OnBluetoothEnabled(obj, event);
}
}
SettingAirplaneMode::SettingAirplaneMode(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
SettingBluetooth::SettingBluetooth(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: Screen(app), settingsController {settingsController} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
@@ -36,38 +36,38 @@ SettingAirplaneMode::SettingAirplaneMode(Pinetime::Applications::DisplayApp* app
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Airplane mode");
lv_label_set_text_static(title, "Bluetooth");
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::airplane);
lv_label_set_text_static(icon, Symbols::bluetooth);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
cbEnabled = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text(cbEnabled, " Enable");
lv_checkbox_set_text(cbEnabled, " Enabled");
cbEnabled->user_data = this;
lv_obj_set_event_cb(cbEnabled, OnAirplaneModeEnabledEvent);
lv_obj_set_event_cb(cbEnabled, OnBluetoothEnabledEvent);
SetRadioButtonStyle(cbEnabled);
cbDisabled = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text(cbDisabled, " Disable");
lv_checkbox_set_text(cbDisabled, " Disabled");
cbDisabled->user_data = this;
lv_obj_set_event_cb(cbDisabled, OnAirplaneModeDisabledEvent);
lv_obj_set_event_cb(cbDisabled, OnBluetoothDisabledEvent);
SetRadioButtonStyle(cbDisabled);
if (settingsController.GetBleRadioEnabled()) {
lv_checkbox_set_checked(cbDisabled, true);
lv_checkbox_set_checked(cbEnabled, true);
priorMode = true;
} else {
lv_checkbox_set_checked(cbEnabled, true);
lv_checkbox_set_checked(cbDisabled, true);
priorMode = false;
}
}
SettingAirplaneMode::~SettingAirplaneMode() {
SettingBluetooth::~SettingBluetooth() {
lv_obj_clean(lv_scr_act());
// Do not call SaveSettings - see src/components/settings/Settings.h
if (priorMode != settingsController.GetBleRadioEnabled()) {
@@ -75,18 +75,18 @@ SettingAirplaneMode::~SettingAirplaneMode() {
}
}
void SettingAirplaneMode::OnAirplaneModeEnabled(lv_obj_t* object, lv_event_t event) {
void SettingBluetooth::OnBluetoothDisabled(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
lv_checkbox_set_checked(cbEnabled, true);
lv_checkbox_set_checked(cbDisabled, false);
lv_checkbox_set_checked(cbEnabled, false);
lv_checkbox_set_checked(cbDisabled, true);
settingsController.SetBleRadioEnabled(false);
}
}
void SettingAirplaneMode::OnAirplaneModeDisabled(lv_obj_t* object, lv_event_t event) {
void SettingBluetooth::OnBluetoothEnabled(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
lv_checkbox_set_checked(cbEnabled, false);
lv_checkbox_set_checked(cbDisabled, true);
lv_checkbox_set_checked(cbEnabled, true);
lv_checkbox_set_checked(cbDisabled, false);
settingsController.SetBleRadioEnabled(true);
}
}

View File

@@ -12,13 +12,13 @@ namespace Pinetime {
namespace Applications {
namespace Screens {
class SettingAirplaneMode : public Screen {
class SettingBluetooth : public Screen {
public:
SettingAirplaneMode(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
~SettingAirplaneMode() override;
SettingBluetooth(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
~SettingBluetooth() override;
void OnAirplaneModeEnabled(lv_obj_t* object, lv_event_t event);
void OnAirplaneModeDisabled(lv_obj_t* object, lv_event_t event);
void OnBluetoothEnabled(lv_obj_t* object, lv_event_t event);
void OnBluetoothDisabled(lv_obj_t* object, lv_event_t event);
private:
Controllers::Settings& settingsController;

View File

@@ -64,7 +64,7 @@ std::unique_ptr<Screen> Settings::CreateScreen3() {
{Symbols::clock, "Chimes", Apps::SettingChimes},
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
{Symbols::check, "Firmware", Apps::FirmwareValidation},
{Symbols::airplane, "Airplane mode", Apps::SettingAirplaneMode}
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth}
}};
return std::make_unique<Screens::List>(2, 4, app, settingsController, applications);