From 4bbdb1d3b0d16b8d00f70786539cbfc18220aab7 Mon Sep 17 00:00:00 2001 From: Pawel Paprocki <69140352+pawpMudita@users.noreply.github.com> Date: Thu, 3 Dec 2020 14:10:29 +0100 Subject: [PATCH] [EGD-4465] Create info window for incoming MMI messages (#1078) --- changelog.md | 1 + module-apps/CMakeLists.txt | 2 +- .../ApplicationDesktop.cpp | 10 +++ .../ApplicationDesktop.hpp | 1 + .../application-desktop/CMakeLists.txt | 3 + module-apps/application-desktop/data/Mmi.hpp | 17 ++++ .../windows/MmiPullWindow.cpp | 15 +--- .../windows/MmiPullWindow.hpp | 1 - .../windows/MmiPushWindow.cpp | 82 +++++++++++++++++++ .../windows/MmiPushWindow.hpp | 27 ++++++ .../application-desktop/windows/Names.hpp | 1 + 11 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 module-apps/application-desktop/data/Mmi.hpp create mode 100644 module-apps/application-desktop/windows/MmiPushWindow.cpp create mode 100644 module-apps/application-desktop/windows/MmiPushWindow.hpp diff --git a/changelog.md b/changelog.md index a76d865d43b4c606f76a432deb74ef3bfa6d2ee7..c9db8df8ba2f7f32529ec0d789bfa9c45b56d7d1 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ * `[notes]` MMI/USSD communication window * `[notes]` Notes application implemented. * `[notes]` Notes search engine implemented. +* `[desktop]` info window for incoming MMI messages. ### Changed diff --git a/module-apps/CMakeLists.txt b/module-apps/CMakeLists.txt index 5628020088a65222d48e8443a0fec47c06f7946d..9654ccc550787f69093d3fd42e13e30b81f9a79a 100644 --- a/module-apps/CMakeLists.txt +++ b/module-apps/CMakeLists.txt @@ -30,7 +30,7 @@ set( SOURCES "widgets/BrightnessBox.cpp" "widgets/ModesBox.cpp" "widgets/BarGraph.cpp" - ) + ) add_library(${PROJECT_NAME} STATIC ${SOURCES} ${BOARD_SOURCES}) diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 9078915be26882645b9f2b92f01f004ace82807b..50e8df5a9d50cf79e34bf3b470554ca3c842b190 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -12,6 +12,8 @@ #include "windows/Reboot.hpp" #include "windows/Update.hpp" #include "windows/MmiPullWindow.hpp" +#include "windows/MmiPushWindow.hpp" + #include "AppWindow.hpp" #include "data/LockPhoneData.hpp" @@ -69,6 +71,11 @@ namespace app switchWindow(app::window::name::desktop_mmi_pull, std::move(data)); return msgHandled(); }); + + addActionReceiver(app::manager::actions::ShowMMIPush, [this](auto &&data) { + switchWindow(app::window::name::desktop_mmi_push, std::move(data)); + return msgHandled(); + }); } ApplicationDesktop::~ApplicationDesktop() @@ -336,6 +343,9 @@ namespace app windowsFactory.attach(desktop_mmi_pull, [](Application *app, const std::string newname) { return std::make_unique(app, desktop_mmi_pull); }); + windowsFactory.attach(desktop_mmi_push, [](Application *app, const std::string newname) { + return std::make_unique(app, desktop_mmi_push); + }); } void ApplicationDesktop::destroyUserInterface() diff --git a/module-apps/application-desktop/ApplicationDesktop.hpp b/module-apps/application-desktop/ApplicationDesktop.hpp index 45a559774a5152a87985575a266e4857801b94a4..30d1a00c6b26e0dd8a335086ca3dfa2a73421629 100644 --- a/module-apps/application-desktop/ApplicationDesktop.hpp +++ b/module-apps/application-desktop/ApplicationDesktop.hpp @@ -101,6 +101,7 @@ namespace app manager::actions::UnlockSim, manager::actions::BlockSim, manager::actions::ShowMMIResponse, + manager::actions::ShowMMIPush, manager::actions::DisplayCMEError}}; } }; diff --git a/module-apps/application-desktop/CMakeLists.txt b/module-apps/application-desktop/CMakeLists.txt index 03a4714fa908dbb65fac459b2b5fba61c7e0cfdf..3c0410beb2526b3942de1c7f5720452857fe766f 100644 --- a/module-apps/application-desktop/CMakeLists.txt +++ b/module-apps/application-desktop/CMakeLists.txt @@ -31,10 +31,12 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/windows/Reboot.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Update.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPullWindow.cpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPushWindow.cpp" PUBLIC "${CMAKE_CURRENT_LIST_DIR}/ApplicationDesktop.hpp" "${CMAKE_CURRENT_LIST_DIR}/data/LockPhoneData.hpp" "${CMAKE_CURRENT_LIST_DIR}/data/Style.hpp" + "${CMAKE_CURRENT_LIST_DIR}/data/Mmi.hpp" "${CMAKE_CURRENT_LIST_DIR}/widgets/PinHash.hpp" "${CMAKE_CURRENT_LIST_DIR}/widgets/PinLock.hpp" "${CMAKE_CURRENT_LIST_DIR}/widgets/DesktopInputWidget.hpp" @@ -54,6 +56,7 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/windows/Update.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Names.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPullWindow.hpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPushWindow.hpp" ) target_link_libraries(${PROJECT_NAME} diff --git a/module-apps/application-desktop/data/Mmi.hpp b/module-apps/application-desktop/data/Mmi.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2d9cf60dda1e4a1e8ce4ce2a33497ebfb99761ee --- /dev/null +++ b/module-apps/application-desktop/data/Mmi.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +namespace mmi +{ + static inline std::string removePhrase(std::string str, std::string phrase) + { + auto find_pos = str.find(phrase); + while (find_pos != std::string::npos) { + str.replace(find_pos, phrase.size(), ""); + find_pos = str.find(phrase, find_pos); + } + return str; + } +} // namespace mmi diff --git a/module-apps/application-desktop/windows/MmiPullWindow.cpp b/module-apps/application-desktop/windows/MmiPullWindow.cpp index 53b067f079ce16393f42cf47f11aa1f186cece06..863148c9a70113dcb47bab657a212810b7557d13 100644 --- a/module-apps/application-desktop/windows/MmiPullWindow.cpp +++ b/module-apps/application-desktop/windows/MmiPullWindow.cpp @@ -2,7 +2,8 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "MmiPullWindow.hpp" -#include "application-desktop/widgets/DesktopInputWidget.hpp" +#include +#include #include #include @@ -65,21 +66,11 @@ MmiPullWindow::MmiPullWindow(app::Application *app, const std::string &name) : g addWidget(InputBox); } -std::string MmiPullWindow::removePhrase(std::string str, std::string phrase) -{ - auto find_pos = str.find(phrase); - while (find_pos != std::string::npos) { - str.replace(find_pos, phrase.size(), ""); - find_pos = str.find(phrase, find_pos); - } - return str; -} - void MmiPullWindow::onBeforeShow(ShowMode mode, SwitchData *data) { auto metadata = dynamic_cast(data); if (metadata != nullptr) { - text->setText(removePhrase(metadata->getData(), "\r")); + text->setText(mmi::removePhrase(metadata->getData(), "\r")); } InputBox->setVisible(true); setFocusItem(InputBox->inputText); diff --git a/module-apps/application-desktop/windows/MmiPullWindow.hpp b/module-apps/application-desktop/windows/MmiPullWindow.hpp index db44807548e1880f1268feb492b829a2acf00564..d2153de7e3c134540599f68c3b0c2f935b8daf7d 100644 --- a/module-apps/application-desktop/windows/MmiPullWindow.hpp +++ b/module-apps/application-desktop/windows/MmiPullWindow.hpp @@ -26,7 +26,6 @@ namespace gui void onBeforeShow(ShowMode mode, SwitchData *data) override; bool onInput(const InputEvent &inputEvent) override; void destroyInterface() override; - std::string removePhrase(std::string str, std::string phrase); }; }; // namespace gui diff --git a/module-apps/application-desktop/windows/MmiPushWindow.cpp b/module-apps/application-desktop/windows/MmiPushWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75eb3558c88eba22f458d134977aa33df2603ad1 --- /dev/null +++ b/module-apps/application-desktop/windows/MmiPushWindow.cpp @@ -0,0 +1,82 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "MmiPushWindow.hpp" +#include +#include +#include +#include + +using namespace gui; + +// move to style +namespace style::desktop +{ + namespace image + { + constexpr uint32_t x = 176; + constexpr uint32_t y = 135; + } // namespace image + namespace text + { + constexpr uint32_t x = 40; + constexpr uint32_t y = 260; + constexpr uint32_t w = 400; + constexpr uint32_t h = 135; + } // namespace text + +} // namespace style::desktop + +MmiPushWindow::MmiPushWindow(app::Application *app, const std::string &name) : gui::AppWindow(app, name) +{ + AppWindow::buildInterface(); + + topBar->setActive(TopBar::Elements::TIME, true); + topBar->setActive(TopBar::Elements::SIM, false); + bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::ok)); + icon = new Image(this, style::desktop::image::x, style::desktop::image::y, ""); + icon->set("info_big_circle_W_G"); + text = new Text( + this, style::desktop::text::x, style::desktop::text::y, style::desktop::text::w, style::desktop::text::h); + text->setTextType(TextType::MULTI_LINE); + text->setEditMode(EditMode::BROWSE); + text->setEdges(RectangleEdge::None); + text->setFont(style::window::font::medium); + text->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); + setTitle(utils::localize.get("app_desktop_info")); +} + +void MmiPushWindow::onBeforeShow(ShowMode mode, SwitchData *data) +{ + if (auto metadata = dynamic_cast(data); metadata != nullptr) { + text->setText(mmi::removePhrase(metadata->getData(), "\r")); + } +} + +bool MmiPushWindow::onInput(const InputEvent &inputEvent) +{ + if (inputEvent.isShortPress()) { + switch (inputEvent.keyCode) { + case KeyCode::KEY_ENTER: { + application->returnToPreviousWindow(); + return true; + } + case KeyCode::KEY_RF: { + return true; + } + default: + break; + } + } + return AppWindow::onInput(inputEvent); +} + +void MmiPushWindow::destroyInterface() +{ + erase(); +} + +MmiPushWindow::~MmiPushWindow() +{ + destroyInterface(); +} diff --git a/module-apps/application-desktop/windows/MmiPushWindow.hpp b/module-apps/application-desktop/windows/MmiPushWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..942eb7f4ecaf9cc423a4dbd2761acc7f689ccfd9 --- /dev/null +++ b/module-apps/application-desktop/windows/MmiPushWindow.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include +#include + +namespace gui +{ + class MmiPushWindow : public AppWindow + { + protected: + Text *text = nullptr; + Image *icon = nullptr; + + public: + MmiPushWindow(app::Application *app, const std::string &name); + ~MmiPushWindow() override; + void onBeforeShow(ShowMode mode, SwitchData *data) override; + bool onInput(const InputEvent &inputEvent) override; + void destroyInterface() override; + }; + +}; // namespace gui diff --git a/module-apps/application-desktop/windows/Names.hpp b/module-apps/application-desktop/windows/Names.hpp index f10e283d21eec2f34d3a28e3fb3483f8ccb3a518..4f5e029d6164ff4f0b3bcd4a0926ddeaa6f935fa 100644 --- a/module-apps/application-desktop/windows/Names.hpp +++ b/module-apps/application-desktop/windows/Names.hpp @@ -14,4 +14,5 @@ namespace app::window::name inline constexpr auto desktop_locked = "LockedInfoWindow"; inline constexpr auto desktop_update = "Update"; inline constexpr auto desktop_mmi_pull = "MmiPullWindow"; + inline constexpr auto desktop_mmi_push = "MmiPushWindow"; }; // namespace app::window::name