mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Settings for date/time
This commit is contained in:
@@ -15,6 +15,7 @@ app_settings_src = $(addprefix apps/settings/,\
|
||||
sub_menu/about_controller_non_official.cpp:-official \
|
||||
sub_menu/exam_mode_controller_official.cpp:+official \
|
||||
sub_menu/exam_mode_controller_non_official.cpp:-official \
|
||||
sub_menu/datetime_controller.cpp \
|
||||
sub_menu/display_mode_controller.cpp \
|
||||
sub_menu/exam_mode_controller.cpp \
|
||||
sub_menu/generic_sub_controller.cpp \
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Leer "
|
||||
SymbolArgDefaultFunction = "Argument "
|
||||
PythonFont = "Python Schriftart"
|
||||
MemUse = "Speicher"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Empty "
|
||||
SymbolArgDefaultFunction = "Argument "
|
||||
PythonFont = "Python Font"
|
||||
MemUse = "Memory"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Vacío "
|
||||
SymbolArgDefaultFunction = "Argumento "
|
||||
PythonFont = "Fuente Python"
|
||||
MemUse = "Memoria"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Vide "
|
||||
SymbolArgDefaultFunction = "Arguments "
|
||||
PythonFont = "Police Python"
|
||||
MemUse = "Mémoire"
|
||||
DateTime = "Date/heure"
|
||||
ActivateClock = "Activer horloge"
|
||||
Date = "Date"
|
||||
Time = "Heure"
|
||||
RTCWarning1 = "Activer l'horloge décharge la batterie plus"
|
||||
RTCWarning2 = "vite quand la calculatrice est éteinte."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Üres "
|
||||
SymbolArgDefaultFunction = "Argumentummal "
|
||||
PythonFont = "Python Betütipus"
|
||||
MemUse = "Memória"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Empty "
|
||||
SymbolArgDefaultFunction = "Argument "
|
||||
PythonFont = "Python Font"
|
||||
MemUse = "Memory"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Empty "
|
||||
SymbolArgDefaultFunction = "Argument "
|
||||
PythonFont = "Python Font"
|
||||
MemUse = "Memory"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -62,3 +62,9 @@ SymbolArgFunction = "Vazio "
|
||||
SymbolArgDefaultFunction = "Argumento "
|
||||
PythonFont = "Fonte Python"
|
||||
MemUse = "Memória"
|
||||
DateTime = "Date/time"
|
||||
ActivateClock = "Activate clock"
|
||||
Date = "Date"
|
||||
Time = "Time"
|
||||
RTCWarning1 = "Enabling the clock drains the battery faster"
|
||||
RTCWarning2 = "when the calculator is powered off."
|
||||
|
||||
@@ -13,6 +13,7 @@ constexpr SettingsMessageTree s_modelAngleChildren[3] = {SettingsMessageTree(I18
|
||||
constexpr SettingsMessageTree s_modelEditionModeChildren[2] = {SettingsMessageTree(I18n::Message::Edition2D), SettingsMessageTree(I18n::Message::EditionLinear)};
|
||||
constexpr SettingsMessageTree s_modelFloatDisplayModeChildren[4] = {SettingsMessageTree(I18n::Message::Decimal), SettingsMessageTree(I18n::Message::Scientific), SettingsMessageTree(I18n::Message::Engineering), SettingsMessageTree(I18n::Message::SignificantFigures)};
|
||||
constexpr SettingsMessageTree s_modelComplexFormatChildren[3] = {SettingsMessageTree(I18n::Message::Real), SettingsMessageTree(I18n::Message::Cartesian), SettingsMessageTree(I18n::Message::Polar)};
|
||||
constexpr SettingsMessageTree s_modelDateTimeChildren[3] = {SettingsMessageTree(I18n::Message::ActivateClock), SettingsMessageTree(I18n::Message::Date), SettingsMessageTree(I18n::Message::Time)};
|
||||
constexpr SettingsMessageTree s_symbolChildren[4] = {SettingsMessageTree(I18n::Message::SymbolMultiplicationCross),SettingsMessageTree(I18n::Message::SymbolMultiplicationMiddleDot),SettingsMessageTree(I18n::Message::SymbolMultiplicationStar),SettingsMessageTree(I18n::Message::SymbolMultiplicationAutoSymbol)};
|
||||
constexpr SettingsMessageTree s_symbolFunctionChildren[3] = {SettingsMessageTree(I18n::Message::SymbolDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgFunction)};
|
||||
constexpr SettingsMessageTree s_modelMathOptionsChildren[6] = {SettingsMessageTree(I18n::Message::AngleUnit, s_modelAngleChildren), SettingsMessageTree(I18n::Message::DisplayMode, s_modelFloatDisplayModeChildren), SettingsMessageTree(I18n::Message::EditionMode, s_modelEditionModeChildren), SettingsMessageTree(I18n::Message::SymbolFunction, s_symbolFunctionChildren), SettingsMessageTree(I18n::Message::ComplexFormat, s_modelComplexFormatChildren), SettingsMessageTree(I18n::Message::SymbolMultiplication, s_symbolChildren)};
|
||||
@@ -33,6 +34,7 @@ MainController::MainController(Responder * parentResponder, InputEventHandlerDel
|
||||
m_mathOptionsController(this, inputEventHandlerDelegate),
|
||||
m_languageController(this, Metric::CommonTopMargin),
|
||||
m_accessibilityController(this),
|
||||
m_dateTimeController(this),
|
||||
m_examModeController(this),
|
||||
m_aboutController(this),
|
||||
m_preferencesController(this)
|
||||
@@ -100,6 +102,8 @@ bool MainController::handleEvent(Ion::Events::Event event) {
|
||||
subController = &m_aboutController;
|
||||
} else if (title == I18n::Message::Accessibility) {
|
||||
subController = &m_accessibilityController;
|
||||
} else if (title == I18n::Message::DateTime) {
|
||||
subController = &m_dateTimeController;
|
||||
} else if (title == I18n::Message::MathOptions) {
|
||||
subController = &m_mathOptionsController;
|
||||
} else {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "message_table_cell_with_gauge_with_separator.h"
|
||||
#include "sub_menu/about_controller.h"
|
||||
#include "sub_menu/accessibility_controller.h"
|
||||
#include "sub_menu/datetime_controller.h"
|
||||
#include "sub_menu/exam_mode_controller.h"
|
||||
#include "sub_menu/language_controller.h"
|
||||
#include "sub_menu/math_options_controller.h"
|
||||
@@ -21,6 +22,7 @@ extern const Shared::SettingsMessageTree s_symbolChildren[4];
|
||||
extern const Shared::SettingsMessageTree s_symbolFunctionChildren[3];
|
||||
extern const Shared::SettingsMessageTree s_modelMathOptionsChildren[6];
|
||||
extern const Shared::SettingsMessageTree s_modelFontChildren[2];
|
||||
extern const Shared::SettingsMessageTree s_modelDateTimeChildren[3];
|
||||
extern const Shared::SettingsMessageTree s_accessibilityChildren[6];
|
||||
extern const Shared::SettingsMessageTree s_contributorsChildren[20];
|
||||
#ifdef OMEGA_USERNAME
|
||||
@@ -71,6 +73,7 @@ private:
|
||||
MathOptionsController m_mathOptionsController;
|
||||
LanguageController m_languageController;
|
||||
AccessibilityController m_accessibilityController;
|
||||
DateTimeController m_dateTimeController;
|
||||
ExamModeController m_examModeController;
|
||||
AboutController m_aboutController;
|
||||
PreferencesController m_preferencesController;
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Settings {
|
||||
constexpr SettingsMessageTree s_modelMenu[] =
|
||||
{SettingsMessageTree(I18n::Message::MathOptions, s_modelMathOptionsChildren),
|
||||
SettingsMessageTree(I18n::Message::Brightness),
|
||||
SettingsMessageTree(I18n::Message::DateTime, s_modelDateTimeChildren),
|
||||
SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren),
|
||||
SettingsMessageTree(I18n::Message::Language),
|
||||
SettingsMessageTree(I18n::Message::ExamMode, ExamModeConfiguration::s_modelExamChildren),
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Settings {
|
||||
constexpr SettingsMessageTree s_modelMenu[] =
|
||||
{SettingsMessageTree(I18n::Message::MathOptions, s_modelMathOptionsChildren),
|
||||
SettingsMessageTree(I18n::Message::Brightness),
|
||||
SettingsMessageTree(I18n::Message::DateTime, s_modelDateTimeChildren),
|
||||
SettingsMessageTree(I18n::Message::Language),
|
||||
SettingsMessageTree(I18n::Message::ExamMode, ExamModeConfiguration::s_modelExamChildren),
|
||||
SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren),
|
||||
|
||||
@@ -9,6 +9,7 @@ using namespace Shared;
|
||||
constexpr SettingsMessageTree s_modelMenu[] =
|
||||
{SettingsMessageTree(I18n::Message::MathOptions, s_modelMathOptionsChildren),
|
||||
SettingsMessageTree(I18n::Message::Brightness),
|
||||
SettingsMessageTree(I18n::Message::DateTime, s_modelDateTimeChildren),
|
||||
SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren),
|
||||
SettingsMessageTree(I18n::Message::Language),
|
||||
SettingsMessageTree(I18n::Message::ExamMode, ExamModeConfiguration::s_modelExamChildren),
|
||||
|
||||
141
apps/settings/sub_menu/datetime_controller.cpp
Normal file
141
apps/settings/sub_menu/datetime_controller.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "../app.h"
|
||||
#include "datetime_controller.h"
|
||||
#include "../../global_preferences.h"
|
||||
#include "../../apps_container.h"
|
||||
#include <assert.h>
|
||||
|
||||
using namespace Shared;
|
||||
|
||||
namespace Settings {
|
||||
|
||||
DateTimeController::DateTimeController(Responder * parentResponder) :
|
||||
GenericSubController(parentResponder),
|
||||
m_textCells{
|
||||
MessageTableCellWithEditableText{this, nullptr, this},
|
||||
MessageTableCellWithEditableText{this, nullptr, this},
|
||||
}
|
||||
{
|
||||
for (int i = 0; i < k_totalNumberOfSwitchCells; i++) {
|
||||
m_switchCells[i].setMessageFont(KDFont::LargeFont);
|
||||
}
|
||||
for (int i = 0; i < k_totalNumberOfTextCells; i++) {
|
||||
m_textCells[i].setMessageFont(KDFont::LargeFont);
|
||||
}
|
||||
}
|
||||
|
||||
bool DateTimeController::handleEvent(Ion::Events::Event event) {
|
||||
bool clockEnabled = Ion::RTC::mode() != Ion::RTC::Mode::Disabled;
|
||||
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
if (selectedRow() == 0) {
|
||||
clockEnabled = !clockEnabled;
|
||||
if (clockEnabled) {
|
||||
Container::activeApp()->displayWarning(I18n::Message::RTCWarning1, I18n::Message::RTCWarning2);
|
||||
}
|
||||
Ion::RTC::setMode(clockEnabled ? Ion::RTC::Mode::HSE : Ion::RTC::Mode::Disabled);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return GenericSubController::handleEvent(event);
|
||||
}
|
||||
for (int i = 0; i < numberOfRows(); i++) {
|
||||
m_selectableTableView.reloadCellAtLocation(0, i);
|
||||
}
|
||||
AppsContainer::sharedAppsContainer()->redrawWindow(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
HighlightCell * DateTimeController::reusableCell(int index, int type) {
|
||||
assert(type == 1 || type == 2);
|
||||
if (type == 2) {
|
||||
assert(index >= 0 && index < k_totalNumberOfSwitchCells);
|
||||
return &m_switchCells[index];
|
||||
}
|
||||
else if (type == 1) {
|
||||
assert(index >= 0 && index < k_totalNumberOfTextCells);
|
||||
return &m_textCells[index];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int DateTimeController::reusableCellCount(int type) {
|
||||
assert(type == 1 || type == 2);
|
||||
if (type == 2) {
|
||||
return k_totalNumberOfSwitchCells;
|
||||
}
|
||||
else if (type == 1) {
|
||||
return k_totalNumberOfTextCells;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DateTimeController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
GenericSubController::willDisplayCellForIndex(cell, index);
|
||||
|
||||
MessageTableCellWithSwitch * mySwitchCell = (MessageTableCellWithSwitch *)cell;
|
||||
|
||||
if (index == 0) {
|
||||
SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView();
|
||||
mySwitch->setState(Ion::RTC::mode() != Ion::RTC::Mode::Disabled);
|
||||
}
|
||||
else {
|
||||
TextField * myTextField = (TextField *)mySwitchCell->accessoryView();
|
||||
Ion::RTC::DateTime dateTime = Ion::RTC::dateTime();
|
||||
if (index == 1) {
|
||||
Ion::RTC::toStringDate(dateTime, m_timeBuffer);
|
||||
myTextField->setText(m_timeBuffer);
|
||||
}
|
||||
else {
|
||||
Ion::RTC::toStringTime(dateTime, m_dateBuffer);
|
||||
myTextField->setText(m_dateBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DateTimeController::typeAtLocation(int i, int j) {
|
||||
switch (j) {
|
||||
case 0:
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool DateTimeController::textFieldShouldFinishEditing(TextField * view, Ion::Events::Event event) {
|
||||
return event == Ion::Events::Up || event == Ion::Events::Down || event == Ion::Events::EXE || event == Ion::Events::OK;
|
||||
}
|
||||
|
||||
bool DateTimeController::textFieldDidReceiveEvent(TextField * view, Ion::Events::Event event) {
|
||||
if (view->isEditing() && view->shouldFinishEditing(event)) {
|
||||
Ion::RTC::DateTime dateTime = Ion::RTC::dateTime();
|
||||
|
||||
if (((TextField*)m_textCells[0].accessoryView()) == view) {
|
||||
if (!Ion::RTC::parseDate(view->text(), dateTime)) {
|
||||
Container::activeApp()->displayWarning(I18n::Message::SyntaxError);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Ion::RTC::parseTime(view->text(), dateTime)) {
|
||||
Container::activeApp()->displayWarning(I18n::Message::SyntaxError);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Ion::RTC::setDateTime(dateTime);
|
||||
}
|
||||
if (event == Ion::Events::Up || event == Ion::Events::Down) {
|
||||
m_selectableTableView.handleEvent(event);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DateTimeController::textFieldDidFinishEditing(TextField * view, const char * text, Ion::Events::Event event)
|
||||
{
|
||||
for (int i = 0; i < numberOfRows(); i++) {
|
||||
m_selectableTableView.reloadCellAtLocation(0, i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
30
apps/settings/sub_menu/datetime_controller.h
Normal file
30
apps/settings/sub_menu/datetime_controller.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef SETTINGS_DATETIME_CONTROLLER_H
|
||||
#define SETTINGS_DATETIME_CONTROLLER_H
|
||||
|
||||
#include "generic_sub_controller.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class DateTimeController : public GenericSubController, public TextFieldDelegate {
|
||||
public:
|
||||
DateTimeController(Responder * parentResponder);
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
HighlightCell * reusableCell(int index, int type) override;
|
||||
int reusableCellCount(int type) override;
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
int typeAtLocation(int i, int j) override;
|
||||
bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override;
|
||||
bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override;
|
||||
bool textFieldDidFinishEditing(TextField * view, const char * text, Ion::Events::Event event) override;
|
||||
private:
|
||||
constexpr static int k_totalNumberOfSwitchCells = 1;
|
||||
constexpr static int k_totalNumberOfTextCells = 2;
|
||||
MessageTableCellWithEditableText m_textCells[k_totalNumberOfTextCells];
|
||||
MessageTableCellWithSwitch m_switchCells[k_totalNumberOfSwitchCells];
|
||||
char m_timeBuffer[9];
|
||||
char m_dateBuffer[11];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user