*/
#include "presenters/KeypadPage.h"
+#include "view/VolumeControl.h"
+#include "resources.h"
#include "common.h"
namespace callui { namespace { namespace impl {
return *this;
}
- KeypadPage::Builder &KeypadPage::Builder::setSoundManager(const ISoundManagerSRef &sm)
+ KeypadPage::Builder
+ &KeypadPage::Builder::setSoundManager(const ISoundManagerSRef &sm)
{
m_sm = sm;
return *this;
"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)
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!");
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!");
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);
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!");
}
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);
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));
+ }
}