Files
MuditaOS/module-apps/application-call/windows/EnterNumberWindow.cpp
T
Alek-Mudita 8585ea8cf4 Call app - contact recognition (#169)
* [EGD-2569] added # and * as numeric inputs

* [EGD-2569] added '+' input sign

* [EGD-2569] created defines with window names for call app

* [EGD-2547] contact recognition during call

* [EGD-2547] moved UiCommon

* [fix][EGD-2547] fix for setting empty UTF string to text gui field

* [EGD-2547] adding new contact from call enter window

* [EGD-2547] minor clean up and added param validation

* [EGD-2547] easier method to add contact

* [EGD-2569] added new keyboard profile (numeric with special signs)
Desktop is passing it properly to Call app.

* [EGD-2569] added transaltor to enternumberwindow

* [EGD-2569] reverted unnecessary changes

[EGD-2569] revert

[EGD-2569] revert of not needed changes

* [EGD-2569] fix in phone.kprof

* [EGD-2547] unified API to call and send sms

* [EGD-2547]  changed default to true

* [EGD-2547] minor clean up.

* [EGD-2569] revert changes in PinLockWindow.cpp

* [EGD-2569][fix] eneter as null char

* [EGD-2547] PR fixes

[EGD-2547] code review fixes / refactored UiCommon

[EGD-2547] more code review fixes

[EGD-2547] rem not needed cast

* [EGD-2547] PR fixes

* [EGD-2547] splitting of UiCommon

* [EGD-2547] typo fix

* [EGD-2547] revereted one line conversion from char to string.
2020-02-28 09:37:25 +01:00

213 lines
6.5 KiB
C++

/*
* @file EnterNumberWindow.cpp
* @author Robert Borzecki (robert.borzecki@mudita.com)
* @date 1 lip 2019
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
#include "EnterNumberWindow.hpp"
#include "../ApplicationCall.hpp"
#include "../data/CallAppStyle.hpp"
#include "../data/CallSwitchData.hpp"
#include "InputMode.hpp"
#include "UiCommonActions.hpp"
#include "i18/i18.hpp"
#include "service-appmgr/ApplicationManager.hpp"
#include "service-cellular/api/CellularServiceAPI.hpp"
namespace gui {
using namespace callAppStyle::enterNumberWindow;
EnterNumberWindow::EnterNumberWindow( app::Application* app, std::string windowName ) : AppWindow(app, windowName ) {
buildInterface();
}
void EnterNumberWindow::rebuild() {
}
void EnterNumberWindow::setNumberLabel(const std::string num)
{
auto app = dynamic_cast<app::ApplicationCall *>(application);
if (app == nullptr)
{
LOG_ERROR("app != ApplicationCall");
return;
}
app->setDisplayedNumber(num);
numberLabel->setText(num);
if(numberLabel->getText().length() == 0)
{
bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("common_back"));
return;
}
bottomBar->setText( BottomBar::Side::RIGHT, utils::localize.get("app_call_clear"));
}
void EnterNumberWindow::buildInterface() {
AppWindow::buildInterface();
bottomBar->setText( BottomBar::Side::LEFT, utils::localize.get("app_call_call"));
bottomBar->setText( BottomBar::Side::CENTER, utils::localize.get("app_call_add"));
bottomBar->setText( BottomBar::Side::RIGHT, utils::localize.get("app_call_clear"));
topBar->setActive(TopBar::Elements::SIGNAL, true );
topBar->setActive(TopBar::Elements::BATTERY, true );
topBar->setActive(TopBar::Elements::TIME, true );
numberLabel = new gui::Label(this, numberLabel::x, numberLabel::y, numberLabel::w, numberLabel::h);
numberLabel->setPenWidth(numberLabel::borderW);
numberLabel->setFont(style::window::font::verybig);
numberLabel->setEdges( RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM );
numberLabel->setAlignement( gui::Alignment(gui::Alignment::ALIGN_HORIZONTAL_CENTER, gui::Alignment::ALIGN_VERTICAL_TOP));
numberLabel->setDotsMode( true, false);
newContactIcon = new gui::Icon(this, newContactIcon::x, newContactIcon::y, "cross", utils::localize.get("app_call_contact"));
newContactIcon->activatedCallback = [=](gui::Item &item) {
auto app = dynamic_cast<app::ApplicationCall *>(application);
if (app != nullptr)
{
return app::contact(getApplication(), app::ContactOperation::Add, app->getDisplayedNumber());
}
return false;
};
setFocusItem(newContactIcon);
}
void EnterNumberWindow::destroyInterface() {
AppWindow::destroyInterface();
if( numberLabel ) { removeWidget(numberLabel); delete numberLabel; numberLabel= nullptr; }
if( newContactIcon ) { removeWidget(newContactIcon); delete newContactIcon; newContactIcon= nullptr; }
children.clear();
}
EnterNumberWindow::~EnterNumberWindow() {
destroyInterface();
}
bool EnterNumberWindow::onInput( const InputEvent& inputEvent ) {
auto app = dynamic_cast<app::ApplicationCall *>(application);
if (app == nullptr)
{
LOG_ERROR("app != ApplicationCall");
return AppWindow::onInput(inputEvent);
}
auto code = translator.handle(inputEvent.key, InputMode({InputMode::phone}).get());
if( inputEvent.state == InputEvent::State::keyReleasedShort ) {
if(inputEvent.keyCode == KeyCode::KEY_LF) {
std::string num = app->getDisplayedNumber();
LOG_INFO("number: [%s]", num.c_str());
auto ret = CellularServiceAPI::DialNumber(application,num.c_str());
LOG_INFO("CALL RESULT: %s", (ret?"OK":"FAIL"));
return true;
}
else if(inputEvent.keyCode == KeyCode::KEY_RF) {
std::string num = app->getDisplayedNumber();
//if there isn't any char in phone number field return to previous application
if( num.empty() ) {
sapm::ApplicationManager::messageSwitchPreviousApplication( application );
return true;
}
num = num.substr(0, num.size()-1);
setNumberLabel(num);
application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
return true;
}
else if (code != 0)
{
std::string num = app->getDisplayedNumber();
num += code;
setNumberLabel(num);
app->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
return true;
}
}
else if( inputEvent.state == InputEvent::State::keyReleasedLong) {
//erase all characters from phone number
if(inputEvent.keyCode == KeyCode::KEY_RF) {
std::string num = app->getDisplayedNumber();
//if there isn't any char in phone number field return to previous application
if( num.empty() ) {
sapm::ApplicationManager::messageSwitchPreviousApplication( application );
return true;
}
setNumberLabel("");
application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
return true;
}
// long press of '0' key is translated to '+'
else if (inputEvent.keyCode == KeyCode::KEY_0)
{
std::string num = app->getDisplayedNumber();
num += '+';
setNumberLabel(num);
application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
return true;
}
}
//check if any of the lower inheritance onInput methods catch the event
return AppWindow::onInput( inputEvent );
}
bool EnterNumberWindow::handleSwitchData( SwitchData* data ) {
if( data == nullptr )
{
LOG_ERROR("Received null pointer");
return false;
}
app::CallSwitchData *callData = dynamic_cast<app::CallSwitchData *>(data);
if (callData != nullptr)
{
std::string num = callData->getPhoneNumber();
setNumberLabel(num);
application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
switch (callData->getType())
{
case app::CallSwitchData::Type::EXECUTE_CALL: {
LOG_INFO("number: [%s]", num.c_str());
auto ret = CellularServiceAPI::DialNumber(application, num.c_str());
LOG_INFO("CALL RESULT: %s", (ret ? "OK" : "FAIL"));
return true;
}
case app::CallSwitchData::Type::ENTER_NUMBER: {
return true;
}
break;
default: {
LOG_ERROR("Unhandled callData type");
return false;
}
}
}
else
{
LOG_ERROR("Unrecognized SwitchData");
return false;
}
return false;
}
} /* namespace gui */