TizenRefApp-8531 [Call UI] Implement handling Power button press 66/131166/2
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Mon, 22 May 2017 13:13:54 +0000 (16:13 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Tue, 30 May 2017 11:50:05 +0000 (14:50 +0300)
Change-Id: I1d9bc5ee478acfb44452df7cf6ee3c5f25e47105

inc/presenters/Instance.h
inc/presenters/MainPage.h
inc/presenters/Presenter.h
src/common.h
src/model/CallManager.cpp
src/model/SoundManager.cpp
src/presenters/Instance.cpp
src/presenters/MainPage.cpp
src/presenters/Presenter.cpp
tizen-manifest.xml

index 4060d48c55d4e6e637971cec9200f3f2b71ea515..66c2ecf1960a61dbe70c35aa92b9cd7199370348 100644 (file)
@@ -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;
        };
 }
 
index 3b29211412402121edcaa28629f031dfb380ce81..97fe7d9a61e3a56e8e45bbb0689a1964182aaf43 100644 (file)
@@ -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;
index 677abe090d1df1c039e685edbafd3027690f430d..d67e25da15fbf90c170953a41d7a279396490120 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <unordered_set>
 
-#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<void *> m_deactivatorExceptions;
                std::unordered_set<void *> m_deactivators;
-               ucl::WidgetWRef m_topWidget;
+               ucl::WindowSRef m_window;
                bool m_isPrepared;
        };
 }
index b2d0927db1fb34a5cf679e5e64e55f58f8822fac..8d0548624b83a0d0bee9821ab1adfebd62326ee4 100644 (file)
 
 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__
index e036d89168128ac941ec79980762d6e0e21f1c28..df9089c20787b757c3404ac9bc52433be2803fdf 100644 (file)
 
 #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(
index 6092986b9a8df9f32c62f498c341fa3e9ea2f2c1..ce60020a12e40e164444bd32f185b589a301e206 100644 (file)
@@ -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;
                }
 
index 4e3caaeb9d1bcdb80f4eef005bde1b20aad49386..51e2a3482c0a3ac8cabf6bd40a6be4a319b99677 100644 (file)
 #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<Ecore_Event_Key *>(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();
index 7bfe62de6f23b031f708229f7a6fadef362f8733..db250f9b26f872678f938f67ddb40569d8b1dbef 100644 (file)
@@ -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();
                }
        }
 
index 0dddce7191bf7a3a30e1f3a5086fe18dda27fa74..c0435aacb5256f0e6b5a76f8334044186656977a 100644 (file)
@@ -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,
index cfdf0c617e7a2ab617260984f8f65fd806cb345f..b2aae8f19658cdf95e500770aaba8d3f4b16fe5a 100644 (file)
@@ -23,5 +23,6 @@
         <privilege>http://tizen.org/privilege/notification</privilege>
         <privilege>http://tizen.org/privilege/message.read</privilege>
         <privilege>http://tizen.org/privilege/display</privilege>
+        <privilege>http://tizen.org/privilege/keygrab</privilege>
     </privileges>
 </manifest>