IncreaseVolumeActivity & DecreaseVolumeActivity 43/154043/2
authorPawel Kurowski <p.kurowski2@samsung.com>
Thu, 5 Oct 2017 12:12:11 +0000 (14:12 +0200)
committerPawel Kurowski <p.kurowski2@samsung.com>
Thu, 5 Oct 2017 12:19:40 +0000 (14:19 +0200)
Change-Id: I9714ed1ddd55ff356503b37c30f6bee0fd27bd0d

res/po/en_US.po
src/VolumeControlActivity.cpp

index 5e6252c..9c0e8f7 100644 (file)
@@ -397,6 +397,12 @@ msgstr "More options"
 msgid "IDS_ACTIVITY_NAME_OPEN_QUICKPANEL"
 msgstr "Open notifications"
 
+msgid "IDS_ACTIVITY_NAME_INCREASE_VOLUME"
+msgstr "Increase volume"
+
+msgid "IDS_ACTIVITY_NAME_DECREASE_VOLUME"
+msgstr "Decrease volume"
+
 # PROVIDERS
 
 msgid "IDS_SWITCH_PROVIDER_NAME_AccessoriesSwitchProvider"
index 68586b6..345497c 100644 (file)
@@ -5,15 +5,25 @@
 
 #include <sound_manager.h>
 
-#define RETURN_ON_ERROR(status) do {                                   \
-               if (status != SOUND_MANAGER_ERROR_NONE) {               \
-                       ERROR("Sound manager error %d", status);        \
-                       return true;                                                            \
-               }                                                                                               \
+#define RETURN_ON_ERROR(status) do {                                                                                           \
+               if (status != SOUND_MANAGER_ERROR_NONE) {                                                                       \
+                       ERROR("Sound manager error %d", status);                                                                \
+                       return true;                                                                                                                    \
+               }                                                                                                                                                       \
        } while (false)
 
-template <typename DerivedType>
-class VolumeControlActivity : public Activity, private RegisterActivity<DerivedType>
+#define RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(status) do {                                                                \
+               if (status != SOUND_MANAGER_ERROR_NONE) {                                                                       \
+                       if (status == SOUND_MANAGER_ERROR_NO_PLAYING_SOUND)                                             \
+                               DEBUG("Sound isn't playing on any channel");                                            \
+                       else                                                                                                                                    \
+                               ERROR("sound_manager_get_current_sound_type error: %d", status);        \
+                       return soundType;                                                                                                               \
+               }                                                                                                                                                       \
+       } while (false)
+
+template <typename DerivedType, bool bindable>
+class VolumeControlActivity : public Activity, private RegisterActivity<DerivedType, bindable>
 {
 public:
        constexpr static const char *activityType = DerivedType::activityType;
@@ -26,20 +36,26 @@ public:
                int volume = 0;
                int maxVolume = 0;
                int minVolume = 0;
+               sound_type_e soundType = getSoundType();
 
-               RETURN_ON_ERROR(sound_manager_get_max_volume(DerivedType::soundType, &maxVolume));
-               RETURN_ON_ERROR(sound_manager_get_volume(DerivedType::soundType, &volume));
+               RETURN_ON_ERROR(sound_manager_get_max_volume(soundType, &maxVolume));
+               RETURN_ON_ERROR(sound_manager_get_volume(soundType, &volume));
 
                volume = utils::clamp(volume + DerivedType::step, minVolume, maxVolume);
-               RETURN_ON_ERROR(sound_manager_set_volume(DerivedType::soundType, volume));
+               RETURN_ON_ERROR(sound_manager_set_volume(soundType, volume));
 
                return true;
        }
 
+       virtual sound_type_e getSoundType() const
+       {
+               return DerivedType::soundType;
+       }
+
 };
 
 
-class IncreaseMediaVolumeActivity : public VolumeControlActivity<IncreaseMediaVolumeActivity>
+class IncreaseMediaVolumeActivity : public VolumeControlActivity<IncreaseMediaVolumeActivity, false>
 {
 public:
        static constexpr const char *activityType = "INCREASE_MEDIA_VOLUME";
@@ -47,7 +63,7 @@ public:
        static constexpr const sound_type_e soundType = SOUND_TYPE_MEDIA;
 };
 
-class DecreaseMediaVolumeActivity : public VolumeControlActivity<DecreaseMediaVolumeActivity>
+class DecreaseMediaVolumeActivity : public VolumeControlActivity<DecreaseMediaVolumeActivity, false>
 {
 public:
        static constexpr const char *activityType = "DECREASE_MEDIA_VOLUME";
@@ -55,7 +71,7 @@ public:
        static constexpr const sound_type_e soundType = SOUND_TYPE_MEDIA;
 };
 
-class IncreaseRingtoneVolumeActivity : public VolumeControlActivity<IncreaseRingtoneVolumeActivity>
+class IncreaseRingtoneVolumeActivity : public VolumeControlActivity<IncreaseRingtoneVolumeActivity, false>
 {
 public:
        static constexpr const char *activityType = "INCREASE_RINGTONE_VOLUME";
@@ -63,7 +79,7 @@ public:
        static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
 };
 
-class DecreaseRingtoneVolumeActivity : public VolumeControlActivity<DecreaseRingtoneVolumeActivity>
+class DecreaseRingtoneVolumeActivity : public VolumeControlActivity<DecreaseRingtoneVolumeActivity, false>
 {
 public:
        static constexpr const char *activityType = "DECREASE_RINGTONE_VOLUME";
@@ -71,7 +87,7 @@ public:
        static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
 };
 
-class IncreaseNotificationsVolumeActivity : public VolumeControlActivity<IncreaseNotificationsVolumeActivity>
+class IncreaseNotificationsVolumeActivity : public VolumeControlActivity<IncreaseNotificationsVolumeActivity, false>
 {
 public:
        static constexpr const char *activityType = "INCREASE_NOTIFICATIONS_VOLUME";
@@ -79,10 +95,40 @@ public:
        static constexpr const sound_type_e soundType = SOUND_TYPE_NOTIFICATION;
 };
 
-class DecreaseNotificationsVolumeActivity : public VolumeControlActivity<DecreaseNotificationsVolumeActivity>
+class DecreaseNotificationsVolumeActivity : public VolumeControlActivity<DecreaseNotificationsVolumeActivity, false>
 {
 public:
        static constexpr const char *activityType = "DECREASE_NOTIFICATIONS_VOLUME";
        static constexpr const int step = -1;
        static constexpr const sound_type_e soundType = SOUND_TYPE_NOTIFICATION;
+};
+
+class IncreaseVolumeActivity : public VolumeControlActivity<IncreaseVolumeActivity, true>
+{
+public:
+       sound_type_e getSoundType() const override
+       {
+               sound_type_e type;
+               RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(sound_manager_get_current_sound_type(&type));
+               return type;
+       }
+
+       static constexpr const char *activityType = "INCREASE_VOLUME";
+       static constexpr const int step = 1;
+       static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
+};
+
+class DecreaseVolumeActivity : public VolumeControlActivity<DecreaseVolumeActivity, true>
+{
+public:
+       sound_type_e getSoundType() const override
+       {
+               sound_type_e type;
+               RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(sound_manager_get_current_sound_type(&type));
+               return type;
+       }
+
+       static constexpr const char *activityType = "DECREASE_VOLUME";
+       static constexpr const int step = -1;
+       static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
 };
\ No newline at end of file