~aleteoryx/muditaos

ref: 0ef0d615f34e275f088890a1244dd480dd467920 muditaos/module-apps/windows/AppWindow.cpp -rw-r--r-- 6.7 KiB
0ef0d615 — Krzysztof Mozdzynski [EGD-4150] Change filename i18 to i18n (#1108) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AppWindow.hpp"
#include "Application.hpp"
#include "InputEvent.hpp"
#include <Style.hpp>
#include <application-desktop/ApplicationDesktop.hpp>
#include <module-utils/i18n/i18n.hpp>
#include <service-appmgr/Controller.hpp>
#include <service-audio/AudioServiceAPI.hpp>

using namespace style::header;

namespace gui
{

    AppWindow::AppWindow(app::Application *app, std::string name) : Window(name), application{app}
    {
        setSize(style::window_width, style::window_height);
    }

    void AppWindow::destroyInterface()
    {
        erase(bottomBar);
        erase(topBar);
        erase(title);
        title     = nullptr;
        bottomBar = nullptr;
        topBar    = nullptr;
    }

    void AppWindow::rebuild()
    {}

    void AppWindow::buildInterface()
    {
        bottomBar = new gui::BottomBar(this, 0, 599 - 50, 480, 50);
        bottomBar->setActive(BottomBar::Side::LEFT, false);
        bottomBar->setActive(BottomBar::Side::CENTER, false);
        bottomBar->setActive(BottomBar::Side::RIGHT, false);

        title = new gui::Label(this, 0, 52, 480, 52);
        title->setFilled(false);
        title->setFont(font::title);
        title->clear();
        title->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top));
        title->setEdges(RectangleEdge::Bottom);
        title->setEllipsis(Ellipsis::Right);
        title->visible = false;

        topBar = new gui::TopBar(this, 0, 0, 480, 50);
        topBar->setActive(TopBar::Elements::LOCK, false);
        topBar->setActive(TopBar::Elements::BATTERY, false);
        topBar->setActive(TopBar::Elements::SIGNAL, false);
    }

    bool AppWindow::batteryCharging(bool charging)
    {
        topBar->setBatteryCharging(charging);
        return true;
    }

    bool AppWindow::setSIM()
    {
        topBar->simSet();
        return true;
    }

    // updates battery level in the window
    bool AppWindow::updateBatteryLevel(uint32_t percentage)
    {
        // get old value of battery level, calcualte new level and comapre both
        // if they are different make a change and return true, otherwise return false;
        if (topBar != nullptr) {
            return topBar->setBatteryLevel(percentage);
        }
        return false;
    }
    // updates battery level in the window
    bool AppWindow::updateSignalStrength()
    {
        return topBar->updateSignalStrength();
    }

    bool AppWindow::updateNetworkAccessTechnology()
    {
        return topBar->updateNetworkAccessTechnology();
    }

    bool AppWindow::updateTime(const UTF8 &timeStr)
    {
        topBar->setTime(timeStr);
        return true;
    }

    bool AppWindow::updateTime(const uint32_t &timestamp, bool mode24H)
    {
        topBar->setTime(timestamp, mode24H);
        return true;
    }

    void AppWindow::setTitle(const UTF8 &text)
    {
        if (title != nullptr) {
            title->setText(text);
            title->setVisible(text.length() != 0);
        }
        else {
            LOG_ERROR("cant set title - it doesn't exist!");
        }
    }

    bool AppWindow::onDatabaseMessage(sys::Message *msg)
    {
        return false;
    }

    bool AppWindow::onInput(const InputEvent &inputEvent)
    {
        // check if any of the lower inheritance onInput methods catch the event
        if (Window::onInput(inputEvent)) {
            return true;
        }

        if (inputEvent.state == InputEvent::State::keyReleasedLong && inputEvent.keyCode == gui::KeyCode::KEY_RF) {
            LOG_INFO("exit to main menu");
            app::manager::Controller::sendAction(application, app::manager::actions::Home);
        }
        // process only if key is released
        if ((inputEvent.state != InputEvent::State::keyReleasedShort))
            return false;

        switch (inputEvent.keyCode) {
        case KeyCode::KEY_VOLUP: {
            application->increaseCurrentVolume();
            return true;
        }
        case KeyCode::KEY_VOLDN: {
            application->decreaseCurrentVolume();
            return true;
        }
        case KeyCode::KEY_RF: {
            application->returnToPreviousWindow();
            return true;
        }
        case KeyCode::KEY_TORCH: {
            application->toggleTorchAndColourTemps();
            return true;
        }
        default:
            break;
        }

        return false;
    }

    void AppWindow::bottomBarTemporaryMode(const UTF8 &text, bool emptyOthers)
    {
        bottomBarTemporaryMode(text, BottomBar::Side::LEFT, emptyOthers);
    }

    void AppWindow::bottomBarTemporaryMode(const UTF8 &text, BottomBar::Side side, bool emptyOthers)
    {
        if (bottomBar == nullptr) {
            return;
        }

        bottomBar->store();

        if (emptyOthers) {
            bottomBar->setText(BottomBar::Side::LEFT, "");
            bottomBar->setText(BottomBar::Side::CENTER, "");
            bottomBar->setText(BottomBar::Side::RIGHT, "");
        }

        switch (side) {
        case BottomBar::Side::LEFT:
            bottomBar->setText(BottomBar::Side::LEFT, text);
            break;
        case BottomBar::Side::CENTER:
            bottomBar->setText(BottomBar::Side::CENTER, text);
            break;
        case BottomBar::Side::RIGHT:
            bottomBar->setText(BottomBar::Side::RIGHT, text);
            break;
        }
        application->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
    }

    void AppWindow::bottomBarRestoreFromTemporaryMode()
    {
        if (bottomBar == nullptr) {
            return;
        }

        bottomBar->restore();
        application->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
    }

    void AppWindow::setBottomBarText(const UTF8 &text, BottomBar::Side side)
    {
        bottomBar->setText(side, text);
    }

    void AppWindow::clearBottomBarText(BottomBar::Side side)
    {
        bottomBar->setText(side, "");
    }

    bool AppWindow::selectSpecialCharacter()
    {
        return app::manager::Controller::sendAction(
            application,
            app::manager::actions::ShowSpecialInput,
            std::make_unique<gui::SwitchSpecialChar>(gui::SwitchSpecialChar::Type::Request, application->GetName()),
            app::manager::OnSwitchBehaviour::RunInBackground);
    }

    BoundingBox AppWindow::bodySize()
    {
        return {0,
                title->offset_h(),
                this->getWidth(),
                this->getHeight() - this->title->offset_h() - bottomBar->getHeight()};
    }

    void AppWindow::setBottomBarActive(BottomBar::Side side, bool value)
    {
        bottomBar->setActive(side, value);
    }

} /* namespace gui */