Numworks Epsilon  1.4.1
Graphing Calculator Operating System
update_controller.cpp
Go to the documentation of this file.
1 #include "update_controller.h"
2 #include "../apps_container.h"
3 #include <assert.h>
4 
5 namespace OnBoarding {
6 
7 UpdateController::MessageViewWithSkip::MessageViewWithSkip(I18n::Message * messages, KDColor * colors, uint8_t numberOfMessages) :
8  MessageView(messages, colors, numberOfMessages),
9  m_skipView(KDText::FontSize::Small, I18n::Message::Skip, 1.0f, 0.5f),
10  m_okView()
11 {
12 }
13 
14 int UpdateController::MessageViewWithSkip::numberOfSubviews() const {
15  return MessageView::numberOfSubviews() + 2;
16 }
17 
18 View * UpdateController::MessageViewWithSkip::subviewAtIndex(int index) {
19  uint8_t numberOfMainMessages = MessageView::numberOfSubviews();
20  if (index < numberOfMainMessages) {
21  return MessageView::subviewAtIndex(index);
22  }
23  if (index == numberOfMainMessages) {
24  return &m_skipView;
25  }
26  if (index == numberOfMainMessages + 1) {
27  return &m_okView;
28  }
29  assert(false);
30  return nullptr;
31 }
32 
33 void UpdateController::MessageViewWithSkip::layoutSubviews() {
34  // Layout the main message
36  // Layout the "skip (OK)"
37  KDCoordinate height = bounds().height();
38  KDCoordinate width = bounds().width();
40  KDSize okSize = m_okView.minimalSizeForOptimalDisplay();
41  m_skipView.setFrame(KDRect(0, height-k_bottomMargin-textHeight, width-okSize.width()-k_okMargin-k_skipMargin, textHeight));
42  m_okView.setFrame(KDRect(width - okSize.width()-k_okMargin, height-okSize.height()-k_okMargin, okSize));
43 }
44 
45 static I18n::Message sOnBoardingMessages[] = {
46  I18n::Message::UpdateAvailable,
47  I18n::Message::UpdateMessage1,
48  I18n::Message::UpdateMessage2,
49  I18n::Message::BlankMessage,
50  I18n::Message::UpdateMessage3,
51  I18n::Message::UpdateMessage4};
52 
53 static KDColor sOnBoardingColors[] = {
60 
62  ViewController(nullptr),
63  m_messageViewWithSkip(sOnBoardingMessages, sOnBoardingColors, 6)
64 {
65 }
66 
68  if (event != Ion::Events::Back && event != Ion::Events::OnOff) {
70  AppsContainer * appsContainer = (AppsContainer *)app()->container();
71  if (appsContainer->activeApp()->snapshot() == appsContainer->onBoardingAppSnapshot()) {
72  appsContainer->refreshPreferences();
73  appsContainer->switchTo(appsContainer->appSnapshotAtIndex(0));
74  }
75  return true;
76  }
77  return false;
78 }
79 
80 }
bool handleEvent(Ion::Events::Event event) override
static constexpr KDColor YellowDark
Definition: palette.h:8
Definition: i18n.h:6
int numberOfSubviews() const override
Definition: message_view.h:11
#define assert(e)
Definition: assert.h:9
virtual App::Snapshot * appSnapshotAtIndex(int index)=0
void switchTo(App::Snapshot *snapshot) override
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
Snapshot * snapshot()
Definition: app.cpp:41
unsigned char uint8_t
Definition: stdint.h:4
Definition: text.h:8
constexpr Event Back
Definition: events.h:66
View * subviewAtIndex(int index) override
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
App::Snapshot * onBoardingAppSnapshot()
constexpr KDColor KDColorBlack
Definition: color.h:41
constexpr Event OnOff
Definition: events.h:69
Definition: rect.h:26
Definition: color.h:6
const Container * container() const
Definition: app.cpp:102
Definition: view.h:23
void layoutSubviews() override
static constexpr KDSize charSize(FontSize size=FontSize::Large)
Definition: text.h:16
void refreshPreferences()
App * app()
Definition: responder.cpp:77
void dismissModalViewController()
Definition: app.cpp:93
App * activeApp()
Definition: container.cpp:34
constexpr KDCoordinate height() const
Definition: size.h:11