TizenRefApp-8720 [Call UI] Implement Volume control functionality in KeypadPage 81/135881/4
authorIgor Kuksiuk <i.kuksiuk@partner.samsung.com>
Tue, 27 Jun 2017 07:29:42 +0000 (10:29 +0300)
committerIgor Kuksiuk <i.kuksiuk@partner.samsung.com>
Tue, 27 Jun 2017 13:33:50 +0000 (16:33 +0300)
Change-Id: I405290f4da8cbb280d7d547ac34e3dc547d513e7

edc/buttons.edc
inc/presenters/KeypadPage.h
src/presenters/AccessoryPresenter.cpp
src/presenters/KeypadPage.cpp
src/presenters/common.h

index 298ab68f8ac6f90373d681d033be5777767a3b13..b5af325390e9cb80e4c3c8fe41d46ca9762e642c 100644 (file)
@@ -1126,6 +1126,11 @@ group { "elm/button/base/callui/keypad_speaker";
                        action: SIGNAL_EMIT "elm,action,unpress" "";
                        after: "mouse_up";
                }
+               program { "clicked";
+                       signal: "mouse,clicked,1";
+                       source: "event";
+                       action: SIGNAL_EMIT "elm,action,click" "";
+               }
        }
 }
 
index e5618131e535ef62118868eda168fef691f495de..9d20a9c73401d17fd3e231a2177f649e90e96e6e 100644 (file)
@@ -54,16 +54,33 @@ namespace callui {
 
                void onBtnPressed(ucl::Widget &widget, void *eventInfo);
                void onBtnUnpressed(ucl::Widget &widget, void *eventInfo);
+               void onBtnClicked(ucl::Widget &widget, void *eventInfo);
 
                ucl::Result createWidget();
                ucl::Result createEntry();
                ucl::Result createButtons();
+               ucl::Result createVolumeControl();
 
                //sound manager-> play dtmf for digit
                void startDtmf(const unsigned char digit);
                //sound manager-> stop dtmf if still playing
                void stopDtmf();
 
+               void onAudioStateChanged(AudioStateType state);
+               void onVolumeControlEventCb(VolumeControlEvent event);
+               Eina_Bool onVCTimerCb();
+               void startVCTimer();
+               void restartVCTimer();
+               void stopVCTimer();
+               void tryIncreaseVolume();
+               void tryDecreaseVolume();
+               void updateVolume(int value);
+               void onVolumeLevelChanged(int value);
+               Eina_Bool onRotaryEvent(Eext_Rotary_Event_Info *info);
+
+               void registerCallbacks();
+               void unregisterCallbacks();
+
        private:
                ucl::LayoutSRef m_widget;
                ucl::ElmWidgetSRef m_entry;
@@ -71,6 +88,12 @@ namespace callui {
                //sound manager usage
                ISoundManagerSRef m_sm;
                bool m_smInUse;
+
+               //volume control usage
+               VolumeControlSRef m_vc;
+               Ecore_Timer *m_vcTimer;
+
+               AudioStateType m_audioState;
        };
 }
 
index d4c667df194a223f76a23aa3d965f25f1a445a9d..e0ea5c53bd02ecb36cfce6ad86d5fc4db5f5ccd0 100644 (file)
@@ -26,9 +26,6 @@ namespace callui { namespace { namespace impl {
 
        using namespace ucl;
 
-       constexpr auto CALL_VC_TIMER_INTERVAL = 1.5;
-       constexpr auto VOLUME_LEVEL_MIN = 1;
-
        constexpr LayoutTheme LAYOUT_ACCESSORY_WIDGET
                {"layout", "callui", "accessory"};
 
@@ -301,7 +298,7 @@ namespace callui {
        {
                stopVCTimer();
 
-               m_vcTimer = ecore_timer_add(impl::CALL_VC_TIMER_INTERVAL,
+               m_vcTimer = ecore_timer_add(CALL_VC_TIMER_INTERVAL,
                                CALLBACK_B(AccessoryPresenter::onVCTimerCb),
                                this);
        }
@@ -382,7 +379,7 @@ namespace callui {
        {
                auto cur = m_sm->getVolume();
 
-               if (cur - 1 >= impl::VOLUME_LEVEL_MIN) {
+               if (cur - 1 >= VOLUME_LEVEL_MIN) {
                        m_sm->setVolume(cur - 1);
                }
        }
@@ -417,7 +414,7 @@ namespace callui {
                if (cur == max) {
                        m_vc->setIncreaseBtnEnable(false);
                        m_vc->setDecreaseBtnEnable(true);
-               } else if (cur <= impl::VOLUME_LEVEL_MIN) {
+               } else if (cur <= VOLUME_LEVEL_MIN) {
                        m_vc->setIncreaseBtnEnable(true);
                        m_vc->setDecreaseBtnEnable(false);
                } else {
index c88d26f7b57c4af897b852a1d285d06c022f9d6b..cf5c2ad6010be6930ac7de9716f0141964c0f44a 100644 (file)
@@ -15,7 +15,9 @@
  */
 
 #include "presenters/KeypadPage.h"
+#include "view/VolumeControl.h"
 
+#include "resources.h"
 #include "common.h"
 
 namespace callui { namespace { namespace impl {
@@ -99,7 +101,8 @@ namespace callui {
                return *this;
        }
 
-       KeypadPage::Builder &KeypadPage::Builder::setSoundManager(const ISoundManagerSRef &sm)
+       KeypadPage::Builder
+       &KeypadPage::Builder::setSoundManager(const ISoundManagerSRef &sm)
        {
                m_sm = sm;
                return *this;
@@ -117,6 +120,10 @@ namespace callui {
                                        "m_navi is NULL");
                }
 
+               if (!m_sm) {
+                       LOG_RETURN_VALUE(RES_FAIL, {}, "m_sm is NULL");
+               }
+
                auto result = makeShared<KeypadPage>(m_sm, m_navi, onExitRequest);
 
                FAIL_RETURN_VALUE(result->prepare([&result](NaviItem &item)
@@ -136,38 +143,52 @@ namespace callui {
                        const ExitRequestHandler onExitRequest):
                Page(rc, navi, onExitRequest),
                m_sm(sm),
-               m_smInUse(false)
+               m_smInUse(false),
+               m_vcTimer(nullptr),
+               m_audioState(m_sm->getAudioState())
        {
        }
 
        KeypadPage::~KeypadPage()
        {
                stopDtmf();
+               stopVCTimer();
+               unregisterCallbacks();
        }
 
        void KeypadPage::onBtnPressed(Widget &widget, void *eventInfo)
        {
-               impl::ButtonInfo *btn = static_cast<impl::ButtonInfo*>(widget.getData(impl::BTN_DATA_KEY));
-               ILOG("button pressed: %c", btn->str);
+               impl::ButtonInfo *btn =
+                       static_cast<impl::ButtonInfo*>(widget.getData(impl::BTN_DATA_KEY));
+               ILOG("button pressed: %c", *(btn->str));
 
                if (btn->type == impl::OperationType::DTMF) {
                        elm_entry_entry_append(*m_entry, btn->str);
                        elm_entry_cursor_end_set(*m_entry);
                        startDtmf(*(btn->str));
                }
-
-               if (btn->type == impl::OperationType::VOLUME) {
-                       //volume control
-               }
        }
 
        void KeypadPage::onBtnUnpressed(Widget &widget, void *eventInfo)
        {
-               impl::ButtonInfo *btn = static_cast<impl::ButtonInfo*>(widget.getData(impl::BTN_DATA_KEY));
-               ILOG("button unpressed: %c", btn->str);
+               impl::ButtonInfo *btn =
+                       static_cast<impl::ButtonInfo*>(widget.getData(impl::BTN_DATA_KEY));
+               ILOG("button unpressed: %c", *(btn->str));
                stopDtmf();
        }
 
+       void KeypadPage::onBtnClicked(Widget &widget, void *eventInfo)
+       {
+               impl::ButtonInfo *btn =
+                       static_cast<impl::ButtonInfo*>(widget.getData(impl::BTN_DATA_KEY));
+
+               if(btn->type == impl::OperationType::VOLUME) {
+                       ILOG("button clicked: volume");
+                       show(*m_vc);
+                       startVCTimer();
+               }
+       }
+
        Result KeypadPage::doPrepare(NaviItem &item)
        {
                FAIL_RETURN(createWidget(), "createWidget() failed!");
@@ -176,6 +197,12 @@ namespace callui {
 
                FAIL_RETURN(createButtons(), "createButtons() failed!");
 
+               FAIL_RETURN(createVolumeControl(), "createVolumeControl() failed!");
+
+               registerCallbacks();
+
+               updateVolume(m_sm->getVolume());
+
                item = getNaviframe().push(*m_widget);
                if (!item) {
                        LOG_RETURN(RES_FAIL, "Naviframe::push() failed!");
@@ -201,7 +228,7 @@ namespace callui {
        ucl::Result KeypadPage::createEntry()
        {
                Evas_Object *entry = elm_entry_add(*m_widget);
-               if(!entry) {
+               if (!entry) {
                        LOG_RETURN(RES_FAIL, "elm_entry_add() failed!");
                }
                m_entry = makeShared<ElmWidget>(entry, true);
@@ -231,7 +258,7 @@ namespace callui {
                for (int i = 0; i < impl::KEYPAD_BTN_MAX_COUNT; ++i) {
                        button = elm_button_add(*m_widget);
 
-                       if(!button) {
+                       if (!button) {
                                LOG_RETURN(RES_FAIL, "elm_button_add() failed!");
                        }
 
@@ -239,13 +266,19 @@ namespace callui {
                        buttonSRef->setData(impl::BTN_DATA_KEY, &(impl::buttonsInfo[i]));
                        buttonSRef->setStyle(impl::buttonsInfo[i].style);
 
-                       buttonSRef->addEventHandler(impl::BTN_PRESSED,
-                                       WEAK_DELEGATE(KeypadPage::onBtnPressed,
-                                                       asWeak(*this)));
-
-                       buttonSRef->addEventHandler(impl::BTN_UNPRESSED,
-                                       WEAK_DELEGATE(KeypadPage::onBtnUnpressed,
-                                                       asWeak(*this)));
+                       if (impl::buttonsInfo[i].type == impl::OperationType::DTMF) {
+                               buttonSRef->addEventHandler(impl::BTN_PRESSED,
+                                               WEAK_DELEGATE(KeypadPage::onBtnPressed,
+                                                               asWeak(*this)));
+
+                               buttonSRef->addEventHandler(impl::BTN_UNPRESSED,
+                                               WEAK_DELEGATE(KeypadPage::onBtnUnpressed,
+                                                               asWeak(*this)));
+                       } else {
+                               buttonSRef->addEventHandler(BTN_CLICKED,
+                                               WEAK_DELEGATE(KeypadPage::onBtnClicked,
+                                                               asWeak(*this)));
+                       }
 
                        m_widget->setContent(button, impl::buttonsInfo[i].swlPart);
                        show(*buttonSRef);
@@ -263,9 +296,201 @@ namespace callui {
 
        void KeypadPage::stopDtmf()
        {
-               if(m_smInUse) {
+               if (m_smInUse) {
                        m_sm->stopDtmf();
                        m_smInUse = false;
                }
        }
+
+       Result KeypadPage::createVolumeControl()
+       {
+               m_vc = VolumeControl::Builder().
+                               setInfoText(STR_VOLUME).
+                               setMaxValue(m_sm->getMaxVolume()).
+                               setEventHandler(WEAK_DELEGATE(
+                                               KeypadPage::onVolumeControlEventCb,
+                                               asWeak(*this))).
+                               build(*m_widget);
+               if (!m_vc) {
+                       LOG_RETURN(RES_FAIL, "VolumeControl::build() failed");
+               }
+
+               auto window = m_vc->getWindow();
+               if (!window) {
+                       LOG_RETURN(RES_FAIL, "Window is NULL!");
+               }
+               int w = 0, h = 0;
+               window->getScreenSize(&w, &h);
+
+               m_vc->move(0, 0);
+               m_vc->resize(w, h);
+               hide(*m_vc);
+
+               return RES_OK;
+       }
+
+       void KeypadPage::onVolumeControlEventCb(VolumeControlEvent event)
+       {
+               if (!isActive()) {
+                       LOG_RETURN_VOID(RES_OK, "Presenter is not active. Ignore");
+               }
+
+               if (!m_vcTimer) {
+                       DLOG("Ignore as control is hidden");
+                       return;
+               }
+
+               restartVCTimer();
+
+               switch (event) {
+               case VolumeControlEvent::INCREASE:
+                       tryIncreaseVolume();
+                       break;
+               case VolumeControlEvent::DECREASE:
+                       tryDecreaseVolume();
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       void KeypadPage::updateVolume(int value)
+       {
+               m_vc->setValue(value);
+
+               auto max = m_sm->getMaxVolume();
+               auto cur = m_sm->getVolume();
+
+               if (cur == max) {
+                       m_vc->setIncreaseBtnEnable(false);
+                       m_vc->setDecreaseBtnEnable(true);
+               } else if (cur <= VOLUME_LEVEL_MIN) {
+                       m_vc->setIncreaseBtnEnable(true);
+                       m_vc->setDecreaseBtnEnable(false);
+               } else {
+                       m_vc->setIncreaseBtnEnable(true);
+                       m_vc->setDecreaseBtnEnable(true);
+               }
+       }
+
+       void KeypadPage::onAudioStateChanged(AudioStateType state)
+       {
+               if ((m_audioState != AudioStateType::BT &&
+                               state == AudioStateType::BT) ||
+                               (m_audioState == AudioStateType::BT &&
+                                               state != AudioStateType::BT)) {
+                       m_audioState = state;
+
+                       m_vc->setValue(0);
+
+                       auto maxVol = m_sm->getMaxVolume();
+                       m_vc->setMaxValue(maxVol);
+
+                       updateVolume(m_sm->getVolume());
+               }
+       }
+
+       void KeypadPage::onVolumeLevelChanged(int value)
+       {
+               updateVolume(value);
+       }
+
+       Eina_Bool KeypadPage::onVCTimerCb()
+       {
+               hide(*m_vc);
+               m_vcTimer = nullptr;
+
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       void KeypadPage::startVCTimer()
+       {
+               stopVCTimer();
+
+               m_vcTimer = ecore_timer_add(CALL_VC_TIMER_INTERVAL,
+                               CALLBACK_B(KeypadPage::onVCTimerCb),
+                               this);
+       }
+
+       void KeypadPage::restartVCTimer()
+       {
+               if (m_vcTimer) {
+                       ecore_timer_reset(m_vcTimer);
+               }
+       }
+
+       void KeypadPage::stopVCTimer()
+       {
+               if (m_vcTimer) {
+                       ecore_timer_del(m_vcTimer);
+                       m_vcTimer = nullptr;
+               }
+       }
+
+       void KeypadPage::tryIncreaseVolume()
+       {
+               auto max = m_sm->getMaxVolume();
+               auto cur = m_sm->getVolume();
+
+               if (max != cur) {
+                       m_sm->setVolume(cur + 1);
+               }
+       }
+
+       void KeypadPage::tryDecreaseVolume()
+       {
+               auto cur = m_sm->getVolume();
+
+               if (cur - 1 >= VOLUME_LEVEL_MIN) {
+                       m_sm->setVolume(cur - 1);
+               }
+       }
+
+       Eina_Bool KeypadPage::onRotaryEvent(Eext_Rotary_Event_Info *info)
+       {
+               if (!isActive()) {
+                       LOG_RETURN_VALUE(RES_OK,
+                                       EINA_TRUE,
+                                       "Presenter is not active. Ignore");
+               }
+
+               if (!m_vcTimer) {
+                       DLOG("Ignore as control is hidden");
+                       return EINA_FALSE;
+               }
+
+               restartVCTimer();
+
+               if (info->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE) {
+                       tryIncreaseVolume();
+               } else {
+                       tryDecreaseVolume();
+               }
+
+               return EINA_TRUE;
+       }
+
+       void KeypadPage::registerCallbacks()
+       {
+               addRotaryEventHandler(CALLBACK_A(
+                               KeypadPage::onRotaryEvent), this);
+
+               m_sm->addAudioStateHandler(DELEGATE(
+                               KeypadPage::onAudioStateChanged, this));
+
+               m_sm->addVolumeStateHandler(DELEGATE(
+                               KeypadPage::onVolumeLevelChanged, this));
+       }
+
+       void KeypadPage::unregisterCallbacks()
+       {
+               delRotaryEventHandler(
+                               CALLBACK_A(KeypadPage::onRotaryEvent), this);
+
+               m_sm->removeAudioStateHandler(DELEGATE(
+                               KeypadPage::onAudioStateChanged, this));
+
+               m_sm->removeVolumeStateHandler(DELEGATE(
+                               KeypadPage::onVolumeLevelChanged, this));
+       }
 }
index 879c2c14b64f75246e0e009e7ecb1b97135d750a..d07af888ec2a5b877df72b17e10dda4e4f80ce64 100644 (file)
@@ -27,4 +27,9 @@
 
 #include "../view/common.h"
 
+namespace callui {
+       constexpr auto CALL_VC_TIMER_INTERVAL = 1.5;
+       constexpr auto VOLUME_LEVEL_MIN = 1;
+}
+
 #endif // __CALLUI_PRESENTERS_COMMON_H__