From 4d1113dd917a88dfe1a7b9ba8287768ae127f3c7 Mon Sep 17 00:00:00 2001 From: Igor Kuksiuk Date: Tue, 27 Jun 2017 10:29:42 +0300 Subject: [PATCH] TizenRefApp-8720 [Call UI] Implement Volume control functionality in KeypadPage Change-Id: I405290f4da8cbb280d7d547ac34e3dc547d513e7 --- edc/buttons.edc | 5 + inc/presenters/KeypadPage.h | 23 +++ src/presenters/AccessoryPresenter.cpp | 9 +- src/presenters/KeypadPage.cpp | 265 ++++++++++++++++++++++++-- src/presenters/common.h | 5 + 5 files changed, 281 insertions(+), 26 deletions(-) diff --git a/edc/buttons.edc b/edc/buttons.edc index 298ab68..b5af325 100644 --- a/edc/buttons.edc +++ b/edc/buttons.edc @@ -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" ""; + } } } diff --git a/inc/presenters/KeypadPage.h b/inc/presenters/KeypadPage.h index e561813..9d20a9c 100644 --- a/inc/presenters/KeypadPage.h +++ b/inc/presenters/KeypadPage.h @@ -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; }; } diff --git a/src/presenters/AccessoryPresenter.cpp b/src/presenters/AccessoryPresenter.cpp index d4c667d..e0ea5c5 100644 --- a/src/presenters/AccessoryPresenter.cpp +++ b/src/presenters/AccessoryPresenter.cpp @@ -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 { diff --git a/src/presenters/KeypadPage.cpp b/src/presenters/KeypadPage.cpp index c88d26f..cf5c2ad 100644 --- a/src/presenters/KeypadPage.cpp +++ b/src/presenters/KeypadPage.cpp @@ -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(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(widget.getData(impl::BTN_DATA_KEY)); - ILOG("button pressed: %c", btn->str); + impl::ButtonInfo *btn = + static_cast(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(widget.getData(impl::BTN_DATA_KEY)); - ILOG("button unpressed: %c", btn->str); + impl::ButtonInfo *btn = + static_cast(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(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(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)); + } } diff --git a/src/presenters/common.h b/src/presenters/common.h index 879c2c1..d07af88 100644 --- a/src/presenters/common.h +++ b/src/presenters/common.h @@ -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__ -- 2.34.1