From f891ccbc251a4bb974d63c02b49cefccb51a322c Mon Sep 17 00:00:00 2001 From: Igor Olshevskyi Date: Mon, 22 May 2017 16:13:54 +0300 Subject: [PATCH] TizenRefApp-8531 [Call UI] Implement handling Power button press Change-Id: I1d9bc5ee478acfb44452df7cf6ee3c5f25e47105 --- inc/presenters/Instance.h | 4 ++++ inc/presenters/MainPage.h | 3 +++ inc/presenters/Presenter.h | 6 ++++-- src/common.h | 5 ++++- src/model/CallManager.cpp | 8 +++++++- src/model/SoundManager.cpp | 2 +- src/presenters/Instance.cpp | 40 +++++++++++++++++++++++++++++++++++- src/presenters/MainPage.cpp | 38 +++++++++++++++++++++++++++++++--- src/presenters/Presenter.cpp | 19 +++++++++-------- tizen-manifest.xml | 1 + 10 files changed, 108 insertions(+), 18 deletions(-) diff --git a/inc/presenters/Instance.h b/inc/presenters/Instance.h index 4060d48..66c2ecf 100644 --- a/inc/presenters/Instance.h +++ b/inc/presenters/Instance.h @@ -51,6 +51,8 @@ namespace callui { void onSysEvent(const ucl::SysEvent sysEvent); void onPageExitRequest(Page &page); + Eina_Bool onKeyUpEventCb(int type, void *event); + private: ucl::SysEventProvider &m_sysEventProvider; ucl::IInstanceContext *m_context; @@ -62,6 +64,8 @@ namespace callui { ucl::Theme m_theme; PageWRef m_page; + + Ecore_Event_Handler *m_keyUpEventHandler; }; } diff --git a/inc/presenters/MainPage.h b/inc/presenters/MainPage.h index 3b29211..97fe7d9 100644 --- a/inc/presenters/MainPage.h +++ b/inc/presenters/MainPage.h @@ -68,6 +68,9 @@ namespace callui { void stopEndCallTimer(); Eina_Bool onEndCallTimerCb(); + void onPowerKeyUp(ucl::Widget &widget, void *eventInfo); + void processKeyPress(); + // Presenter virtual void onActivateBy(const DeactivatorInfo &info) final override; diff --git a/inc/presenters/Presenter.h b/inc/presenters/Presenter.h index 677abe0..d67e25d 100644 --- a/inc/presenters/Presenter.h +++ b/inc/presenters/Presenter.h @@ -19,7 +19,7 @@ #include -#include "ucl/gui/ElmWidget.h" +#include "ucl/gui/Window.h" #include "types.h" @@ -45,6 +45,8 @@ namespace callui { ucl::Result prepare(ucl::ElmWidget &widget); + ucl::Window &getWindow(); + void addDeactivatorSource(ucl::Widget &source); void addDeactivatorException(void *deactivator); @@ -76,7 +78,7 @@ namespace callui { private: std::unordered_set m_deactivatorExceptions; std::unordered_set m_deactivators; - ucl::WidgetWRef m_topWidget; + ucl::WindowSRef m_window; bool m_isPrepared; }; } diff --git a/src/common.h b/src/common.h index b2d0927..8d05486 100644 --- a/src/common.h +++ b/src/common.h @@ -33,7 +33,10 @@ namespace callui { - constexpr auto TEL_NUMBER_MAX_SIZE = 82; + using namespace ucl; + + constexpr SmartEvent WIN_POWER_KEY_UP_EVENT {"callui,powerkey,up"}; + } #endif // __CALLUI_COMMON_H__ diff --git a/src/model/CallManager.cpp b/src/model/CallManager.cpp index e036d89..df9089c 100644 --- a/src/model/CallManager.cpp +++ b/src/model/CallManager.cpp @@ -30,6 +30,12 @@ #include "common.h" +namespace callui { namespace { namespace impl { + + constexpr auto TEL_NUMBER_MAX_SIZE = 82; + +}}} + namespace callui { using namespace ucl; @@ -162,7 +168,7 @@ namespace callui { Result CallManager::dialVoiceCall(const std::string &number) { - char buff[TEL_NUMBER_MAX_SIZE] = { 0 }; + char buff[impl::TEL_NUMBER_MAX_SIZE] = { 0 }; snprintf(buff, sizeof(buff), "%s", number.c_str()); return convertCMResult( diff --git a/src/model/SoundManager.cpp b/src/model/SoundManager.cpp index 6092986..ce60020 100644 --- a/src/model/SoundManager.cpp +++ b/src/model/SoundManager.cpp @@ -45,7 +45,7 @@ namespace callui { void SoundManager::audioStateChangedCb(cm_audio_state_type_e state) { if (state == CM_AUDIO_STATE_NONE_E) { - ELOG("Unhandled state [%d]", state); + ILOG("Ignore. Unhandled state [%d]", state); return; } diff --git a/src/presenters/Instance.cpp b/src/presenters/Instance.cpp index 4e3caae..51e2a34 100644 --- a/src/presenters/Instance.cpp +++ b/src/presenters/Instance.cpp @@ -30,18 +30,33 @@ #include "resources.h" #include "common.h" +namespace callui { namespace { namespace impl { + + using namespace ucl; + + const char *STR_POWER_KEY = "XF86PowerOff"; + +}}} + namespace callui { using namespace ucl; Instance::Instance(SysEventProvider &sysEventProvider) : m_sysEventProvider(sysEventProvider), - m_context(nullptr) + m_context(nullptr), + m_keyUpEventHandler(nullptr) { } Instance::~Instance() { + elm_win_keygrab_unset(*m_win, impl::STR_POWER_KEY, 0, 0); + + if (m_keyUpEventHandler) { + ecore_event_handler_del(m_keyUpEventHandler); + } + if (m_page) { m_page->exitNoTransition(); } @@ -53,6 +68,15 @@ namespace callui { m_win = m_context->getWindow(); + elm_win_keygrab_set(*m_win, impl::STR_POWER_KEY, 0, 0, 0, + ELM_WIN_KEYGRAB_EXCLUSIVE); + + m_keyUpEventHandler = ecore_event_handler_add(ECORE_EVENT_KEY_UP, + CALLBACK_A(Instance::onKeyUpEventCb), this); + if (!m_keyUpEventHandler) { + LOG_RETURN(RES_FAIL, "m_eventHandler is NULL"); + } + FAIL_RETURN(setupTheme(), "setupTheme() failed!"); m_call = CallBuilder().build(); @@ -127,6 +151,20 @@ namespace callui { return RES_OK; } + Eina_Bool Instance::onKeyUpEventCb(int type, void *event) + { + if (!event) { + LOG_RETURN_VALUE(RES_FAIL, ECORE_CALLBACK_DONE, "event is NULL"); + } + + Ecore_Event_Key *ev = static_cast(event); + if (!strcmp(ev->keyname, impl::STR_POWER_KEY)) { + DLOG("Key power [Up]"); + m_win->callEvent(WIN_POWER_KEY_UP_EVENT, nullptr); + } + return ECORE_CALLBACK_DONE; + } + void Instance::onPageExitRequest(Page &page) { m_context->exitApp(); diff --git a/src/presenters/MainPage.cpp b/src/presenters/MainPage.cpp index 7bfe62d..db250f9 100644 --- a/src/presenters/MainPage.cpp +++ b/src/presenters/MainPage.cpp @@ -139,6 +139,7 @@ namespace callui { Result MainPage::prepare() { + DLOG(); m_cm = m_call->getCallManager(); if (!m_cm) { LOG_RETURN(RES_FAIL, "Call manager is NULL!"); @@ -161,6 +162,13 @@ namespace callui { m_widget->setContent(m_indicator->getWidget().getEo(), impl::PART_SWL_INDICATOR); + auto win = m_widget->getWindow(); + if (!win) { + LOG_RETURN(RES_FAIL, "win is NULL!"); + } + win->addEventHandler(WIN_POWER_KEY_UP_EVENT, WEAK_DELEGATE( + MainPage::onPowerKeyUp, asWeak(*this))); + return Page::prepare([this]() { return getNaviframe(). push(*m_widget); @@ -193,11 +201,35 @@ namespace callui { } } - void MainPage::onBackKey() + void MainPage::processKeyPress() { - if (m_cm->getAvailableCalls() - == CALL_FLAG_END) { + switch (m_mode) { + case CallMode::INCOMING: + { + auto incom = m_cm->getIncomingCall(); + if (!incom) { + LOG_RETURN_VOID(RES_FAIL, "incom is NULL"); + } + incom->stopAlert(); + break; + } + case CallMode::END: requestExit(); + break; + default: + break; + } + } + + void MainPage::onBackKey() + { + processKeyPress(); + } + + void MainPage::onPowerKeyUp(ucl::Widget &widget, void *eventInfo) + { + if (isActive()) { + processKeyPress(); } } diff --git a/src/presenters/Presenter.cpp b/src/presenters/Presenter.cpp index 0dddce7..c0435aa 100644 --- a/src/presenters/Presenter.cpp +++ b/src/presenters/Presenter.cpp @@ -42,18 +42,23 @@ namespace callui { Result Presenter::prepare(ElmWidget &widget) { - m_topWidget = asWeak(asWidget(widget.getTopWidget())); - if (!m_topWidget) { - LOG_RETURN(RES_FAIL, "m_topWidget is NULL!"); + m_window = asShared(widget.getWindow()); + if (!m_window) { + LOG_RETURN(RES_FAIL, "m_window is NULL!"); } - addDeactivatorSource(*m_topWidget); + addDeactivatorSource(*m_window); m_isPrepared = true; return RES_OK; } + Window &Presenter::getWindow() + { + return *m_window; + } + void Presenter::addDeactivatorSource(Widget &source) { source.addEventHandler(impl::ACTIVATE_BY, @@ -99,11 +104,7 @@ namespace callui { void Presenter::broadcastDeactivator(const SmartEvent event, void *const deactivator) { - if (m_topWidget) { - sendDeactivatorInfo(*m_topWidget, event, {deactivator, true}); - } else { - ELOG("m_topWidget is NULL!"); - } + sendDeactivatorInfo(*m_window, event, {deactivator, true}); } void Presenter::sendDeactivatorInfo(Widget &sender, diff --git a/tizen-manifest.xml b/tizen-manifest.xml index cfdf0c6..b2aae8f 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml @@ -23,5 +23,6 @@ http://tizen.org/privilege/notification http://tizen.org/privilege/message.read http://tizen.org/privilege/display + http://tizen.org/privilege/keygrab -- 2.34.1