TizenRefApp-8210 Implement handling of alert during call 66/120366/3
authorSergei Kobec <s.kobec@samsung.com>
Thu, 23 Mar 2017 15:31:52 +0000 (17:31 +0200)
committerSergei Kobec <s.kobec@samsung.com>
Thu, 23 Mar 2017 15:31:52 +0000 (17:31 +0200)
Change-Id: I1d92bf37c6928a0b92036e561ec2dc51558b2e52
Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
alarm-app/inc/Alert/AlertView.h
alarm-app/src/Alert/AlertView.cpp

index 7bfdd12eb80b4df9946a8fb017c8625089be6711..1196acf48422cae3a6f3b9b6b565aab9a97ea9bb 100644 (file)
@@ -55,9 +55,11 @@ namespace Alert
                Evas_Object *createSnoozeButton(Evas_Object *parent);
                Eina_Bool onRotaryEvent(Evas_Object *obj, Eext_Rotary_Event_Info *eventInfo);
 
-               Eina_Bool onCancel();
+               bool onClose(bool isAutoClose = false);
                void onDismissClicked(Evas_Object *button, void *eventInfo);
                void onSnoozeClicked(Evas_Object *button, void *eventInfo);
+               void onFocusChanged(sound_stream_focus_mask_e mask, sound_stream_focus_state_e state,
+                               sound_stream_focus_change_reason_e reason);
                static void onButtonPressed(const char *signal, Evas_Object *button, void *eventInfo);
                static Eina_Bool onButtonActivated(Evas_Object *button, Evas_Object *obj,
                                Elm_Access_Action_Info *accessInfo);
index 27a23dd9399ef1d04d030a72ee32f7ddad3e616b..2131880dbea384f901e196c72ca4887e724db268 100644 (file)
@@ -35,6 +35,7 @@
 using namespace Alert;
 using namespace Common;
 using namespace Common::Model;
+using namespace std::placeholders;
 
 AlertView::AlertView(Common::Model::Alarm alarm)
        : m_DismissButton(nullptr), m_SnoozeButton(nullptr),
@@ -44,6 +45,7 @@ AlertView::AlertView(Common::Model::Alarm alarm)
 {
        player_set_sound_stream_info(m_Player, m_SoundManager.getStreamInfo());
        m_SoundManager.acquireFocus();
+       m_SoundManager.setFocusChangeCallback(std::bind(&AlertView::onFocusChanged, this, _1, _2, _3));
 }
 
 AlertView::~AlertView()
@@ -88,8 +90,10 @@ Evas_Object *AlertView::onCreate(Evas_Object *parent)
        elm_object_color_class_color_set(layout, COLOR_CLASS_SNOOZE_HIDDEN,
                        COLOR_BUTTON_SNOOZE, 0);
 
-       m_Timer = ecore_timer_add(ALERT_MAX_TIME, makeCallback(&AlertView::onCancel), this);
-
+       m_Timer = ecore_timer_add(ALERT_MAX_TIME, [](void *data) -> Eina_Bool {
+               auto view = (AlertView *)data;
+               return view->onClose(true);
+       }, this);
        return layout;
 }
 
@@ -105,7 +109,8 @@ void AlertView::onNavigation(bool isCurrent)
                ecore_timer_del(m_FeedbackTimer);
                m_FeedbackTimer = nullptr;;
                if (!elm_win_focus_get(findParent<Ui::Window>()->getEvasObject())) {
-                       onCancel();
+                       //Todo: Check if sound focus taken by someone else
+                       onClose();
                }
        }
 }
@@ -117,7 +122,7 @@ void AlertView::onPageAttached(Ui::NavigatorPage *page)
 
 bool AlertView::onBackPressed()
 {
-       return onCancel();
+       return onClose();
 }
 
 player_h AlertView::createPlayer()
@@ -203,17 +208,21 @@ Eina_Bool AlertView::onRotaryEvent(Evas_Object *obj, Eext_Rotary_Event_Info *eve
        return EINA_TRUE;
 }
 
-Eina_Bool AlertView::onCancel()
+bool AlertView::onClose(bool isAutoClose)
 {
-       if (m_Alarm.getSnoozeCount() < SNOOZE_MAX_COUNT) {
-               m_Alarm.snooze();
-       } else {
+       if (isAutoClose && SoundManager::isSoundFocusedByCall(SoundManager::MediaTypePlayer)) {
                m_Alarm.dismiss();
+       } else {
+               if (m_Alarm.getSnoozeCount() < SNOOZE_MAX_COUNT) {
+                       m_Alarm.snooze();
+               } else {
+                       m_Alarm.dismiss();
+               }
        }
        AlarmConsumer::getInstance().updateDataItem(m_Alarm, nullptr);
        getPage()->close();
 
-       return EINA_FALSE;
+       return false;
 }
 
 void AlertView::onDismissClicked(Evas_Object *button, void *eventInfo)
@@ -230,6 +239,20 @@ void AlertView::onSnoozeClicked(Evas_Object *button, void *eventInfo)
        getPage()->close();
 }
 
+void AlertView::onFocusChanged(sound_stream_focus_mask_e mask, sound_stream_focus_state_e state,
+               sound_stream_focus_change_reason_e reason)
+{
+       switch (state) {
+               case SOUND_STREAM_FOCUS_STATE_ACQUIRED:
+                       player_start(m_Player);
+                       ecore_timer_thaw(m_FeedbackTimer);
+                       break;
+               case SOUND_STREAM_FOCUS_STATE_RELEASED:
+                       ecore_timer_freeze(m_FeedbackTimer);
+                       break;
+       }
+}
+
 void AlertView::onButtonPressed(const char *signal, Evas_Object *button, void *eventInfo)
 {
        elm_layout_signal_emit(elm_object_parent_widget_get(button), signal, "");