summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDomingos Lopes <domingos86lopes@gmail.com>2016-02-20 09:02:50 -0500
committerDomingos Lopes <domingos86lopes@gmail.com>2016-02-20 09:02:50 -0500
commit13f5b09d56d5dd0e21a4e13f438e35ed3c7ebb19 (patch)
tree3667823f66c1a41b258ccc6c26f8d169a6d994be
parent844dd17cb195c6fd81d83f5ca560d65612a9cdcb (diff)
downloadAntennaPod-13f5b09d56d5dd0e21a4e13f438e35ed3c7ebb19.zip
fix the volume conversion upon user interaction
move the conversion formula to a new method in core.util.Converter
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java22
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java13
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/Converter.java13
3 files changed, 21 insertions, 27 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
index e890f03b7..bad6bdf0a 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
@@ -493,14 +493,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- float leftVolume = 1.0f, rightVolume = 1.0f;
- if (progress < 100) {
- leftVolume = progress / 100.0f;
- }
- if (barRightVolume.getProgress() < 100) {
- rightVolume = barRightVolume.getProgress() / 100.0f;
- }
- controller.setVolume(leftVolume, rightVolume);
+ controller.setVolume(
+ Converter.getVolumeFromPercentage(progress),
+ Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
}
@Override
@@ -514,14 +509,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- float leftVolume = 1.0f, rightVolume = 1.0f;
- if (progress < 100) {
- rightVolume = progress / 100.0f;
- }
- if (barLeftVolume.getProgress() < 100) {
- leftVolume = barLeftVolume.getProgress() / 100.0f;
- }
- controller.setVolume(leftVolume, rightVolume);
+ controller.setVolume(
+ Converter.getVolumeFromPercentage(barLeftVolume.getProgress()),
+ Converter.getVolumeFromPercentage(progress));
}
@Override
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
index 6c0aff15e..293514ec7 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
@@ -29,6 +29,7 @@ import de.danoeh.antennapod.core.storage.APCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
+import de.danoeh.antennapod.core.util.Converter;
/**
* Provides access to preferences set by the user in the settings screen. A
@@ -260,20 +261,12 @@ public class UserPreferences {
public static float getLeftVolume() {
int volume = prefs.getInt(PREF_LEFT_VOLUME, 100);
- if(volume == 100) {
- return 1.0f;
- } else {
- return (float) (1 - (Math.log(100 - volume) / Math.log(100)));
- }
+ return Converter.getVolumeFromPercentage(volume);
}
public static float getRightVolume() {
int volume = prefs.getInt(PREF_RIGHT_VOLUME, 100);
- if(volume == 100) {
- return 1.0f;
- } else {
- return (float) (1 - (Math.log(100 - volume) / Math.log(100)));
- }
+ return Converter.getVolumeFromPercentage(volume);
}
public static boolean shouldPauseForFocusLoss() {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java
index 1b929b214..74fb9e709 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java
@@ -118,5 +118,16 @@ public final class Converter {
result += minutes;
return result;
}
-
+
+ /**
+ * Converts the volume as read as the progress from a SeekBar scaled to 100 and as saved in
+ * UserPreferences to the format taken by setVolume methods.
+ * @param progress integer between 0 to 100 taken from the SeekBar progress
+ * @return the appropriate volume as float taken by setVolume methods
+ */
+ public static float getVolumeFromPercentage(int progress){
+ if (progress==100)
+ return 1f;
+ return (float) (1 - (Math.log(101 - progress) / Math.log(101)));
+ }
}