fix the volume conversion upon user interaction

move the conversion formula to a new method in core.util.Converter
This commit is contained in:
Domingos Lopes 2016-02-20 09:02:50 -05:00
parent 844dd17cb1
commit 13f5b09d56
3 changed files with 21 additions and 27 deletions

View File

@ -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

View File

@ -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() {

View File

@ -119,4 +119,15 @@ public final class Converter {
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)));
}
}