update sound mode
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Tue, 29 Aug 2023 07:37:20 +0000 (09:37 +0200)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Thu, 7 Sep 2023 10:49:48 +0000 (12:49 +0200)
SettingMainGadget/SettingMainGadget/Sound/SoundGadget.cs
SettingMainGadget/SettingMainGadget/Sound/SoundmodeManager.cs

index 6df4f1d7dad916e83f883beca96575425a890365..5b5bfa76c267dab8eee0633ed488202961c88c3d 100644 (file)
@@ -10,11 +10,15 @@ using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
 using Tizen.System;
+using Tizen.Applications;
 
 namespace Setting.Menu
 {
     public class SoundGadget : SettingCore.MainMenuGadget
     {
+        private const string soundSliderIconDefault = "sound/sound_slider_icon_default.svg";
+        private const string soundSliderIconMute = "sound/sound_slider_icon_mute.svg";
+
         private View content;
         private Sections sections = new Sections();
         private AudioVolume audioVolume = AudioManager.VolumeController;
@@ -22,6 +26,8 @@ namespace Setting.Menu
         private TextListItem soundMode;
         private TextListItem notificationSound;
         private SliderListItem mediaSlider;
+        private SliderListItem notificationSlider;
+        private SliderListItem systemSlider;
 
         public override Color ProvideIconColor() => new Color(IsLightTheme  ? "#DB3069" : "#DF4679");
 
@@ -189,26 +195,29 @@ namespace Setting.Menu
             Logger.Debug($"GET {AudioVolumeType.Notification} Volume : {SettingAudioManager.GetVolumeLevel(AudioVolumeType.Notification)}");
             Logger.Debug($"GET {AudioVolumeType.System} Volume : {SettingAudioManager.GetVolumeLevel(AudioVolumeType.System)}");
 
-            string soundSliderIconPath = GetResourcePath("sound/sound_slider_icon_default.png");
+            bool soundsEnabled = SoundmodeManager.GetSoundmode() == Soundmode.SOUND_MODE_SOUND;
+            string soundSliderIconPath = soundsEnabled ? GetResourcePath(soundSliderIconDefault) : GetResourcePath(soundSliderIconMute);
 
             // section: media
 
-            mediaSlider = new SliderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_MEDIA)), soundSliderIconPath, SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.Media));
+            mediaSlider = new SliderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_MEDIA)), GetResourcePath(soundSliderIconDefault), SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.Media));
             mediaSlider.Slider.SlidingFinished += OnMediaSlidingFinished;
             mediaSlider.Margin = new Extents(0, 0, 16, 0).SpToPx();
             sections.Add(MainMenuProvider.Sound_MediaSlider, mediaSlider);
 
             // section: notification
 
-            var notificationSlider = new SliderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_NOTIFICATIONS)), soundSliderIconPath, SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.Notification));
+            notificationSlider = new SliderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_NOTIFICATIONS)), soundSliderIconPath, SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.Notification));
             notificationSlider.Slider.ValueChanged += OnNofificationSlider_ValueChanged;
+            notificationSlider.Slider.IsEnabled = soundsEnabled;
             notificationSlider.Margin = new Extents(0, 0, 16, 0).SpToPx();
             sections.Add(MainMenuProvider.Sound_NotificationSlider, notificationSlider);
 
             // section: system
 
-            var systemSlider = new SliderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_SYSTEM)), soundSliderIconPath, SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.System));
+            systemSlider = new SliderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_SYSTEM)), soundSliderIconPath, SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.System));
             systemSlider.Slider.ValueChanged += OnSystemSlider_ValueChanged;
+            systemSlider.Slider.IsEnabled = soundsEnabled;
             systemSlider.Margin = new Extents(0, 0, 16, 0).SpToPx();
             sections.Add(MainMenuProvider.Sound_SystemSlider, systemSlider);
 
@@ -235,6 +244,25 @@ namespace Setting.Menu
         {
             if (soundMode != null)
                 soundMode.Secondary = SoundmodeManager.GetSoundmodeName(this, SoundmodeManager.GetSoundmode());
+
+            bool soundsEnabled = SoundmodeManager.GetSoundmode() == Soundmode.SOUND_MODE_SOUND;
+            string soundSliderIconPath = soundsEnabled ? GetResourcePath(soundSliderIconDefault) : GetResourcePath(soundSliderIconMute);
+
+            if (notificationSlider != null)
+            {
+                notificationSlider.Slider.IsEnabled = soundsEnabled;
+                notificationSlider.IconPath = soundSliderIconPath;
+                notificationSlider.Slider.CurrentValue = SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.Notification);
+            }
+
+            if (systemSlider != null)
+            {
+                systemSlider.Slider.IsEnabled = soundsEnabled;
+                systemSlider.IconPath = soundSliderIconPath;
+                systemSlider.Slider.CurrentValue = SettingAudioManager.GetPercentageVolumeLevel(AudioVolumeType.System);
+            }
+
+            Logger.Debug($"Sound silent mode: {e.Value}");
         }
 
         private void SystemSettings_VibrationChanged(object sender, VibrationChangedEventArgs e)
index 70ef7b8a1a4976a2235140ec52e39332951a31b7..979328d66c1cdcd752c251ab01d5aca7f6ca54b5 100644 (file)
@@ -1,6 +1,8 @@
 using SettingMainGadget.TextResources;
 using SettingCore;
 using Tizen.NUI;
+using Tizen.Applications;
+using Tizen.Multimedia;
 
 namespace SettingMainGadget.Sound
 {
@@ -15,6 +17,8 @@ namespace SettingMainGadget.Sound
     {
         private const string VconfSoundOn = "db/setting/sound/sound_on";
         private const string VconfVibrationOn = "db/setting/sound/vibration_on";
+        private const string SoundSystemLevel = "sound_system_level";
+        private const string SoundNotificationLevel = "sound_notification_level";
 
         public static Soundmode GetSoundmode()
         {
@@ -64,6 +68,31 @@ namespace SettingMainGadget.Sound
             {
                 Logger.Warn($"could not set key {VconfVibrationOn} with value {have_vibrations}");
             }
+
+            if(soundmode == Soundmode.SOUND_MODE_SOUND)
+            {
+                // restore the previous sound level
+
+                if (Preference.Contains(SoundSystemLevel))
+                {
+                    SettingAudioManager.SetVolumeLevel(AudioVolumeType.System, Preference.Get<int>(SoundSystemLevel));
+                }
+
+                if (Preference.Contains(SoundNotificationLevel))
+                {
+                    SettingAudioManager.SetVolumeLevel(AudioVolumeType.Notification, Preference.Get<int>(SoundNotificationLevel));
+                }
+            }
+            else
+            {
+                // save the current sound level and set the value to 0
+
+                Preference.Set(SoundSystemLevel, SettingAudioManager.GetVolumeLevel(AudioVolumeType.System));
+                Preference.Set(SoundNotificationLevel, SettingAudioManager.GetVolumeLevel(AudioVolumeType.Notification));
+
+                SettingAudioManager.SetVolumeLevel(AudioVolumeType.System, 0);
+                SettingAudioManager.SetVolumeLevel(AudioVolumeType.Notification, 0);
+            }
         }
 
         public static string GetSoundmodeName(NUIGadget gadget, Soundmode soundmode)