Fixed the sounds setting issue(N_SE-36802)
authorHongryeol Gil <hr.gil@samsung.com>
Fri, 3 May 2013 02:29:28 +0000 (11:29 +0900)
committerHongryeol Gil <hr.gil@samsung.com>
Fri, 3 May 2013 02:29:28 +0000 (11:29 +0900)
Change-Id: Iaa8cc1367b103313aea9b7522eafb17ef548b3df
Signed-off-by: Hongryeol Gil <hr.gil@samsung.com>
inc/StSoundsForm.h
src/StSoundsForm.cpp

index 208fdd4..1df281b 100644 (file)
 #ifndef _ST_SOUNDS_FORM_H_
 #define _ST_SOUNDS_FORM_H_
 
+#include <FMedia.h>
 #include <FSystem.h>
 #include "StBaseForm.h"
 
 class SoundsForm
        : public BaseForm
+       , public Tizen::Media::IPlayerEventListener
        , public Tizen::Ui::IAdjustmentEventListener
+       , public Tizen::Ui::IFocusEventListener
        , public Tizen::Ui::Controls::ISliderEventListener
 {
 public:
@@ -66,11 +69,28 @@ public:
        virtual void OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjustment);
        virtual void OnSliderBarMoved(Tizen::Ui::Controls::Slider& source, int value){}
 
+       virtual void OnPlayerOpened(result r) {}
+       virtual void OnPlayerEndOfClip(void) {}
+       virtual void OnPlayerBuffering(int percent) {}
+       virtual void OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r) {}
+       virtual void OnPlayerInterrupted(void) {}
+       virtual void OnPlayerReleased(void) {}
+       virtual void OnPlayerSeekCompleted(result r) {}
+       virtual void OnPlayerAudioFocusChanged (void) {}
+
+       virtual void OnFocusGained(const Tizen::Ui::Control& source);
+       virtual void OnFocusLost(const Tizen::Ui::Control& source);
+
 private:
        void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);
+       void PlaySound(int type = -1);
 
 private:
        int __currentTableViewList;
+       Tizen::Media::Player* __pSoundPlay;
+       int __notificationVolume;
+       int __mediaVolume;
+       int __systemVolume;
 };
 
 #endif // _ST_SOUNDS_FORM_H_
\ No newline at end of file
index 2d0358d..82c9188 100644 (file)
@@ -26,6 +26,7 @@
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Graphics;
+using namespace Tizen::Media;
 using namespace Tizen::System;
 using namespace Tizen::Ui;
 using namespace Tizen::Ui::Controls;
@@ -87,6 +88,10 @@ static const int STRING_SIZE_LIMIT = 20;
 
 SoundsForm::SoundsForm(void)
        : __currentTableViewList(ID_SOUND_VOLUME_PAGE)
+       , __pSoundPlay(null)
+       , __notificationVolume(0)
+       , __mediaVolume(0)
+       , __systemVolume(0)
 {
 }
 
@@ -125,18 +130,44 @@ SoundsForm::CreateFooter(void)
 result
 SoundsForm::OnInitializing(void)
 {
+       result r = E_SUCCESS;
        BaseForm::CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_SOUNDS"));
        CreateFooter();
        CreateTableView();
+       AddFocusEventListener(*this);
+
+       SettingInfo::GetValue(SETTING_INFO_KEY_SOUND_NOTIFICATION_VOLUME, __notificationVolume);
+       SettingInfo::GetValue(SETTING_INFO_KEY_SOUND_MEDIA_VOLUME, __mediaVolume);
+       SettingInfo::GetValue(SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, __systemVolume);
+
+       SettingInfo::SetValue(SETTING_INFO_KEY_SOUND_MEDIA_VOLUME, 15);
+       SettingInfo::SetValue(SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, 0);
+
+       __pSoundPlay = new (std::nothrow) Player();
+       r = __pSoundPlay->Construct(*this);
+       if (IsFailed(r))
+       {
+               AppLogDebug("Construct fail(%s)", GetErrorMessage(r));
+       }
 
-       AppLogDebug("ENTER");
        return E_SUCCESS;
 }
 
 result
 SoundsForm::OnTerminating(void)
 {
-       __pTableView = null;
+       PlayerState estate = __pSoundPlay->GetState();
+       if ((estate == PLAYER_STATE_OPENED) || (estate == PLAYER_STATE_PAUSED)
+               || (estate == PLAYER_STATE_PLAYING)
+               || (estate == PLAYER_STATE_ENDOFCLIP) || (estate == PLAYER_STATE_STOPPED))
+       {
+               __pSoundPlay->Stop();
+               __pSoundPlay->Close();
+       }
+       if (__pSoundPlay != null)
+       {
+               delete __pSoundPlay;
+       }
 
        SetFormBackEventListener(null);
        return E_SUCCESS;
@@ -183,6 +214,8 @@ SoundsForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
 void
 SoundsForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
 {
+       PlaySound();
+
        SceneManager* pSceneManager = SceneManager::GetInstance();
        AppAssert(pSceneManager);
 
@@ -499,36 +532,25 @@ SoundsForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
                {
                        String sliderItemName;
                        sliderItemName.Format(STRING_SIZE_LIMIT, L"volumeItem_%d", itemIndex);
-                       String settingInfoVolumeKey = SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME;
+
+                       pSlider = new (std::nothrow) Slider();
+
+                       pSlider->Construct(itemSliderRectangle, BACKGROUND_STYLE_NONE, true, GROUP_ITEM_SLIDER_MIN_VALUE, GROUP_ITEM_SLIDER_MAX_VALUE);
 
                        if (itemIndex == ID_ITEM_VOLUME_SYSTEM)
                        {
-                               itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SYSTEM");
+                               pSlider->SetTitleText(ResourceManager::GetString(L"IDS_ST_BODY_SYSTEM"));
+                               pSlider->SetValue(__systemVolume);
                        }
                        else if (itemIndex == ID_ITEM_VOLUME_MEDIA)
                        {
-                               itemMainText = ResourceManager::GetString(L"IDS_COM_BODY_MEDIA");
-                               settingInfoVolumeKey = SETTING_INFO_KEY_SOUND_MEDIA_VOLUME;
+                               pSlider->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_MEDIA"));
+                               pSlider->SetValue(__mediaVolume);
                        }
                        else if (itemIndex == ID_ITEM_VOLUME_NOTIFICATION)
                        {
-                               itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NOTIFICATION");
-                               settingInfoVolumeKey = SETTING_INFO_KEY_SOUND_NOTIFICATION_VOLUME;
-                       }
-
-                       pSlider = new (std::nothrow) Slider();
-
-                       pSlider->Construct(itemSliderRectangle, BACKGROUND_STYLE_NONE, true, GROUP_ITEM_SLIDER_MIN_VALUE, GROUP_ITEM_SLIDER_MAX_VALUE);
-                       pSlider->SetTitleText(itemMainText);
-
-                       int systemVolume = 0;
-                       if (SettingInfo::GetValue(settingInfoVolumeKey, systemVolume) != E_SUCCESS)
-                       {
-                               pSlider->SetValue(GROUP_ITEM_SLIDER_DEFAULT_VALUE);
-                       }
-                       else
-                       {
-                               pSlider->SetValue(systemVolume);
+                               pSlider->SetTitleText(ResourceManager::GetString(L"IDS_ST_BODY_NOTIFICATION"));
+                               pSlider->SetValue(__notificationVolume);
                        }
 
                        pBitmapSoundMin = ResourceManager::GetBitmapN(IDB_SOUND_MIN);
@@ -704,6 +726,8 @@ SoundsForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
 void
 SoundsForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
 {
+       PlaySound();
+
        AppLogDebug("Group(%d) index(%d)", groupIndex, itemIndex);
        bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
 
@@ -855,27 +879,24 @@ SoundsForm::OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjus
                {
                        AppLogDebug("Set system volume fail... - %s", GetErrorMessage(GetLastResult()));
                }
+               else
+               {
+                       __notificationVolume = adjustment;
+                       PlaySound(ID_ITEM_VOLUME_NOTIFICATION);
+               }
        }
        else if (sourceName == L"volumeItem_1")
        {
-               if(SettingInfo::SetVolume (SETTING_INFO_KEY_SOUND_MEDIA_VOLUME, adjustment) != E_SUCCESS)
-               {
-                       AppLogDebug("NotificationSoundVolume Fail..  - %s", GetErrorMessage(GetLastResult()));
-               }
+               __mediaVolume = adjustment;
+               PlaySound(ID_ITEM_VOLUME_MEDIA);
        }
        else if (sourceName == L"volumeItem_2")
        {
-               if (SettingInfo::SetVolume (SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, adjustment) != E_SUCCESS)
-               {
-                       AppLogDebug("MediaSoundVolume Fail..  - %s", GetErrorMessage(GetLastResult()));
-               }
+               __systemVolume = adjustment;
+               PlaySound();
        }
        else if (sourceName == L"volumeItem_3")
        {
-               if (SettingInfo::SetVolume (SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, adjustment) != E_SUCCESS)
-               {
-                       AppLogDebug("SystemSoundVolume Fail..  - %s", GetErrorMessage(GetLastResult()));
-               }
        }
        else if (sourceName == L"vibrationItem_0")
        {
@@ -885,10 +906,6 @@ SoundsForm::OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjus
        {
                // TODO: Haptic feedback Vibration Control.
        }
-       else
-       {
-               // Empty statement
-       }
 
        AppLogDebug("control by name[%ls]", sourceName.GetPointer());
 }
@@ -1030,4 +1047,77 @@ SoundsForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::I
                        delete pArgs;
                }
        }
-}
\ No newline at end of file
+}
+void
+SoundsForm::OnFocusGained(const Tizen::Ui::Control& source)
+{
+       SettingInfo::GetValue(SETTING_INFO_KEY_SOUND_NOTIFICATION_VOLUME, __notificationVolume);
+       SettingInfo::GetValue(SETTING_INFO_KEY_SOUND_MEDIA_VOLUME, __mediaVolume);
+       SettingInfo::GetValue(SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, __systemVolume);
+
+       SettingInfo::SetValue(SETTING_INFO_KEY_SOUND_MEDIA_VOLUME, 15);
+       SettingInfo::SetValue(SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, 0);
+}
+
+void
+SoundsForm::OnFocusLost(const Tizen::Ui::Control& source)
+{
+       SettingInfo::SetValue(SETTING_INFO_KEY_SOUND_MEDIA_VOLUME, __mediaVolume);
+       SettingInfo::SetValue(SETTING_INFO_KEY_SOUND_SYSTEM_VOLUME, __systemVolume);
+}
+
+void
+SoundsForm::PlaySound(int type)
+{
+       String filePath;
+       int adjustment;
+
+       if (type == ID_ITEM_VOLUME_NOTIFICATION)
+       {
+               filePath = L"/opt/share/settings/Alerts/General notification_sdk.wav";
+               adjustment = __notificationVolume;
+       }
+       else if (type == ID_ITEM_VOLUME_MEDIA)
+       {
+               filePath = L"/opt/share/settings/Ringtones/ringtone_sdk.mp3";
+               adjustment = __mediaVolume;
+       }
+       else
+       {
+               filePath = L"/opt/share/svi/sound/touch/touch.wav";
+               adjustment = __systemVolume;
+       }
+
+       result r= E_SUCCESS;
+       if (__pSoundPlay == null)
+       {
+               return;
+       }
+       PlayerState estate = __pSoundPlay->GetState();
+       if ((estate == PLAYER_STATE_PAUSED)
+               || (estate == PLAYER_STATE_PLAYING) || (estate == PLAYER_STATE_ENDOFCLIP))
+       {
+               if (__pSoundPlay != null)
+               {
+                       delete __pSoundPlay;
+                       __pSoundPlay = null;
+               }
+               __pSoundPlay = new (std::nothrow) Player();
+               __pSoundPlay->Construct(*this);
+       }
+
+       r = __pSoundPlay->OpenFile(filePath, false);
+       if (IsFailed(r))
+       {
+               AppLog("%s", GetErrorMessage(r));
+               return;
+       }
+
+       int volume = adjustment * 100.0 / 15.0;
+       if (volume)
+       {
+               __pSoundPlay->SetVolume(volume);
+               __pSoundPlay->Play();
+       }
+       __pSoundPlay->Close();
+}