From 48201cbbc91a055a9752e48cabdb8af59e9411a6 Mon Sep 17 00:00:00 2001
From: Pawel Kurowski
Date: Thu, 5 Oct 2017 14:12:11 +0200
Subject: [PATCH] IncreaseVolumeActivity & DecreaseVolumeActivity
Change-Id: I9714ed1ddd55ff356503b37c30f6bee0fd27bd0d
---
res/po/en_US.po | 6 ++++
src/VolumeControlActivity.cpp | 78 ++++++++++++++++++++++++++++++++++---------
2 files changed, 68 insertions(+), 16 deletions(-)
diff --git a/res/po/en_US.po b/res/po/en_US.po
index 5e6252c..9c0e8f7 100644
--- a/res/po/en_US.po
+++ b/res/po/en_US.po
@@ -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"
diff --git a/src/VolumeControlActivity.cpp b/src/VolumeControlActivity.cpp
index 68586b6..345497c 100644
--- a/src/VolumeControlActivity.cpp
+++ b/src/VolumeControlActivity.cpp
@@ -5,15 +5,25 @@
#include
-#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
-class VolumeControlActivity : public Activity, private RegisterActivity
+#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
+class VolumeControlActivity : public Activity, private RegisterActivity
{
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
+class IncreaseMediaVolumeActivity : public VolumeControlActivity
{
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
+class DecreaseMediaVolumeActivity : public VolumeControlActivity
{
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
+class IncreaseRingtoneVolumeActivity : public VolumeControlActivity
{
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
+class DecreaseRingtoneVolumeActivity : public VolumeControlActivity
{
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
+class IncreaseNotificationsVolumeActivity : public VolumeControlActivity
{
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
+class DecreaseNotificationsVolumeActivity : public VolumeControlActivity
{
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
+{
+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
+{
+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
--
2.7.4