~aleteoryx/muditaos

d6968d836319718211b2e159473058a4f1c3a29c — Wojtek Rzepecki 4 years ago 66db7b0
[EGD-5968] Fix PowerOff window

PowerOff window lifting done
to comply with given design.
A art/phone/application_desktop/menu/turn_off_W_G.png => art/phone/application_desktop/menu/turn_off_W_G.png +0 -0
A image/assets/images/turn_off_W_G.vpi => image/assets/images/turn_off_W_G.vpi +0 -0
M image/assets/lang/Deutsch.json => image/assets/lang/Deutsch.json +2 -2
@@ 88,8 88,8 @@
  "app_desktop_tools_calculator": "CALCULATOR",
  "app_desktop_tools_recorder": "RECORDER",
  "app_desktop_tools_antenna": "ANTENNA TEST",
  "app_desktop_poweroff_title": "Turn Off",
  "app_desktop_poweroff_question": "Select Yes to power down",
  "app_desktop_poweroff_title": "Turn off",
  "app_desktop_poweroff_question": "Turn off the phone?",
  "app_desktop_update_success": "MuditaOS has been updated succesfully.",
  "app_call_call": "CALL",
  "app_call_clear": "CLEAR",

M image/assets/lang/English.json => image/assets/lang/English.json +2 -2
@@ 271,8 271,8 @@
  "app_desktop_tools_calculator": "CALCULATOR",
  "app_desktop_tools_recorder": "RECORDER",
  "app_desktop_tools_antenna": "ANTENNA TEST",
  "app_desktop_poweroff_title": "Turn Off",
  "app_desktop_poweroff_question": "Select Yes to power down",
  "app_desktop_poweroff_title": "Turn off",
  "app_desktop_poweroff_question": "Turn off the phone?",
  "app_desktop_show": "SHOW",
  "app_desktop_calls": "CALLS",
  "app_desktop_clear": "CLEAR",

M image/assets/lang/Espanol.json => image/assets/lang/Espanol.json +2 -2
@@ 89,8 89,8 @@
  "app_desktop_tools_calculator": "CALCULATOR",
  "app_desktop_tools_recorder": "RECORDER",
  "app_desktop_tools_antenna": "ANTENNA TEST",
  "app_desktop_poweroff_title": "Turn Off",
  "app_desktop_poweroff_question": "Select Yes to power down",
  "app_desktop_poweroff_title": "Turn off",
  "app_desktop_poweroff_question": "Turn off the phone?",
  "app_desktop_update_success": "MuditaOS has been updated succesfully.",
  "app_call_call": "CALL",
  "app_call_clear": "CLEAR",

M image/assets/lang/Francais.json => image/assets/lang/Francais.json +2 -2
@@ 88,8 88,8 @@
  "app_desktop_tools_calculator": "CALCULATOR",
  "app_desktop_tools_recorder": "RECORDER",
  "app_desktop_tools_antenna": "ANTENNA TEST",
  "app_desktop_poweroff_title": "Turn Off",
  "app_desktop_poweroff_question": "Select Yes to power down",
  "app_desktop_poweroff_title": "Turn off",
  "app_desktop_poweroff_question": "Turn off the phone?",
  "app_desktop_update_success": "MuditaOS has been updated succesfully.",
  "app_call_call": "CALL",
  "app_call_clear": "CLEAR",

M image/assets/lang/Polski.json => image/assets/lang/Polski.json +1 -1
@@ 91,7 91,7 @@
  "app_desktop_tools_recorder": "DYKTAFON",
  "app_desktop_tools_antenna": "ANTENNA TEST",
  "app_desktop_poweroff_title": "Wyłączanie",
  "app_desktop_poweroff_question": "Wybierz Tak by wyłączyć",
  "app_desktop_poweroff_question": "Czy wyłączyć telefon?",
  "app_desktop_update_success": "MuditaOS został zaktualizowany.",
  "app_call_call": "DZWOŃ",
  "app_call_clear": "WYCZYŚĆ",

M module-apps/application-desktop/windows/DesktopMainWindow.cpp => module-apps/application-desktop/windows/DesktopMainWindow.cpp +1 -1
@@ 151,7 151,7 @@ namespace gui
        }

        if (inputEvent.is(KeyCode::KEY_RF)) {
            application->switchWindow("PowerOffWindow");
            application->switchWindow(app::window::name::desktop_poweroff);
            return true;
        }
        // check if any of the lower inheritance onInput methods catch the event

M module-apps/application-desktop/windows/PowerOffWindow.cpp => module-apps/application-desktop/windows/PowerOffWindow.cpp +20 -157
@@ 18,177 18,40 @@
#include "service-cellular/ServiceCellular.hpp"
#include <Style.hpp>
#include <application-desktop/windows/Names.hpp>
#include <module-apps/messages/DialogMetadataMessage.hpp>

namespace gui
{

    PowerOffWindow::PowerOffWindow(app::Application *app, std::unique_ptr<PowerOffPresenter> &&presenter)
        : AppWindow(app, app::window::name::desktop_poweroff), presenter(std::move(presenter))
        : DialogYesNo(app, app::window::name::desktop_poweroff), presenter(std::move(presenter))
    {
        buildInterface();
        topBar->configure(std::move(configureTopBar(application->getTopBarConfiguration())));
    }

    void PowerOffWindow::rebuild()
    top_bar::Configuration PowerOffWindow::configureTopBar(top_bar::Configuration appConfiguration)
    {
        // find which widget has focus
        uint32_t index = 0;
        for (uint32_t i = 0; i < selectionLabels.size(); i++)
            if (selectionLabels[i] == getFocusItem()) {
                index = i;
                break;
            }

        destroyInterface();
        buildInterface();
        setFocusItem(selectionLabels[index]);
        appConfiguration.enable(top_bar::Indicator::Time);
        appConfiguration.disable(top_bar::Indicator::Lock);
        appConfiguration.disable(top_bar::Indicator::Battery);
        appConfiguration.disable(top_bar::Indicator::NetworkAccessTechnology);
        appConfiguration.disable(top_bar::Indicator::Signal);
        appConfiguration.disable(top_bar::Indicator::SimCard);
        return appConfiguration;
    }
    void PowerOffWindow::buildInterface()
    {
        AppWindow::buildInterface();
        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::confirm));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));

        powerImage     = new gui::Image(this, 177, 132, 0, 0, "pin_lock_info");

        // title label
        titleLabel = new gui::Label(this, 0, 60, 480, 40);
        titleLabel->setFilled(false);
        titleLabel->setBorderColor(gui::ColorFullBlack);
        titleLabel->setFont(style::header::font::title);
        titleLabel->setText(utils::localize.get("app_desktop_poweroff_title"));
        titleLabel->setEdges(RectangleEdge::None);
        titleLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));

        // label with question for powering down
        infoLabel = new gui::Label(this, 0, 294, 480, 30);
        infoLabel->setFilled(false);
        infoLabel->setBorderColor(gui::ColorNoColor);
        infoLabel->setFont(style::window::font::medium);
        infoLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));
        infoLabel->setText(utils::localize.get("app_desktop_poweroff_question"));

        uint32_t pinLabelX = 46;
        uint32_t pinLabelY = 350;
        for (uint32_t i = 0; i < 4; i++) {
            gui::Label *label = new gui::Label(this, pinLabelX, pinLabelY, 193, 75);
            label->setFilled(false);
            label->setBorderColor(gui::ColorFullBlack);
            label->setPenWidth(0);
            label->setPenFocusWidth(2);
            label->setRadius(5);
            label->setFont(style::window::font::medium);
            label->setEdges(RectangleEdge::All);
            label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
            selectionLabels.push_back(label);
            pinLabelX += 193;
        }

        selectionLabels[0]->setText(utils::localize.get(style::strings::common::no));
        selectionLabels[1]->setText(utils::localize.get(style::strings::common::yes));

        pinLabelX = 46;
        pinLabelY += 75;
        eventMgrLabel = new gui::Label(this, pinLabelX, pinLabelY, 193 * 2, 75);
        eventMgrLabel->setFilled(false);
        eventMgrLabel->setBorderColor(gui::ColorFullBlack);
        eventMgrLabel->setPenWidth(0);
        eventMgrLabel->setPenFocusWidth(2);
        eventMgrLabel->setRadius(5);
        eventMgrLabel->setFont(style::window::font::bigbold);
        eventMgrLabel->setText("TURN PWR MGR OFF");
        eventMgrLabel->setEdges(RectangleEdge::All);
        eventMgrLabel->setAlignment(
            gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));

        // define navigation between labels
        selectionLabels[0]->setNavigationItem(NavigationDirection::LEFT, selectionLabels[1]);
        selectionLabels[0]->setNavigationItem(NavigationDirection::RIGHT, selectionLabels[1]);
        selectionLabels[0]->setNavigationItem(NavigationDirection::DOWN, eventMgrLabel);

        selectionLabels[1]->setNavigationItem(NavigationDirection::LEFT, selectionLabels[0]);
        selectionLabels[1]->setNavigationItem(NavigationDirection::RIGHT, selectionLabels[0]);
        selectionLabels[1]->setNavigationItem(NavigationDirection::DOWN, eventMgrLabel);

        eventMgrLabel->setNavigationItem(NavigationDirection::UP, selectionLabels[0]);

        // callbacks for getting focus
        selectionLabels[0]->focusChangedCallback = [=](gui::Item &item) {
            if (item.focus)
                this->state = State::Return;
            return true;
        };

        selectionLabels[1]->focusChangedCallback = [=](gui::Item &item) {
            if (item.focus)
                this->state = State::PowerDown;
            return true;
        };

        selectionLabels[1]->activatedCallback = [=](gui::Item &item) {
    void PowerOffWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        DialogMetadata metadata;
        metadata.action = [=]() -> bool {
            LOG_INFO("User call close system");

            presenter->powerOff();

            return true;
        };

        eventMgrLabel->activatedCallback = [=](gui::Item &item) {
            static bool state = false;
            if (state == false) {
                LOG_INFO("SUSPEND SYSTEM");
                state = true;
            }
            else {
                LOG_INFO("RESUME SYSTEM");
                state = false;
            }
            return true;
        };
    }

    void PowerOffWindow::destroyInterface()
    {
        erase();
        invalidate();
    }

    void PowerOffWindow::invalidate() noexcept
    {
        titleLabel     = nullptr;
        infoLabel      = nullptr;
        eventMgrLabel  = nullptr;
        powerImage     = nullptr;
        selectionLabels.clear();
    }

    void PowerOffWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        // on entering screen always set default result as returning to home screen and set focus to "No" label
        state = State::Return;
        setFocusItem(selectionLabels[0]);
    }

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

        // process only short press, consume rest
        if (inputEvent.state != gui::InputEvent::State::keyReleasedShort)
            return true;

        // if enter was pressed check state and power down or return to main desktop's window
        if (inputEvent.keyCode == KeyCode::KEY_ENTER) {
            if (state != State::PowerDown) {
                application->switchWindow("MainWindow");
            }
        }

        return false;
        metadata.title = utils::localize.get("app_desktop_poweroff_title");
        metadata.text  = utils::localize.get("app_desktop_poweroff_question");
        metadata.icon  = "turn_off_W_G";
        auto msg       = std::make_unique<DialogMetadataMessage>(std::move(metadata));
        DialogYesNo::onBeforeShow(mode, msg.get());
    }

} /* namespace gui */

M module-apps/application-desktop/windows/PowerOffWindow.hpp => module-apps/application-desktop/windows/PowerOffWindow.hpp +3 -23
@@ 4,7 4,7 @@
#pragma once

#include <vector>
#include "AppWindow.hpp"
#include <module-apps/windows/Dialog.hpp>
#include "gui/widgets/Label.hpp"
#include "gui/widgets/Image.hpp"
#include "gui/widgets/BottomBar.hpp"


@@ 12,34 12,14 @@

namespace gui
{
    class PowerOffWindow : public AppWindow
    class PowerOffWindow : public DialogYesNo
    {
        enum class State
        {
            PowerDown,
            Return,
        };

        gui::Label *titleLabel = nullptr;
        gui::Label *infoLabel  = nullptr;

        std::unique_ptr<PowerOffPresenter> presenter;
        std::vector<gui::Label *> selectionLabels;
        gui::Label *eventMgrLabel  = nullptr;
        gui::Image *powerImage     = nullptr;
        gui::Image *powerDownImage = nullptr;
        State state                = State::Return;
      public:
        PowerOffWindow(app::Application *app, std::unique_ptr<PowerOffPresenter> &&presenter);
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        bool onInput(const InputEvent &inputEvent) override;

        void rebuild() override;
        void buildInterface() override;
        void destroyInterface() override;

      private:
        void invalidate() noexcept;
        top_bar::Configuration configureTopBar(top_bar::Configuration appConfiguration) override;
    };

} /* namespace gui */