fix the volume conversion upon user interaction
move the conversion formula to a new method in core.util.Converter
This commit is contained in:
parent
844dd17cb1
commit
13f5b09d56
|
@ -493,14 +493,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
|
||||||
barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
float leftVolume = 1.0f, rightVolume = 1.0f;
|
controller.setVolume(
|
||||||
if (progress < 100) {
|
Converter.getVolumeFromPercentage(progress),
|
||||||
leftVolume = progress / 100.0f;
|
Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
|
||||||
}
|
|
||||||
if (barRightVolume.getProgress() < 100) {
|
|
||||||
rightVolume = barRightVolume.getProgress() / 100.0f;
|
|
||||||
}
|
|
||||||
controller.setVolume(leftVolume, rightVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -514,14 +509,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
|
||||||
barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
float leftVolume = 1.0f, rightVolume = 1.0f;
|
controller.setVolume(
|
||||||
if (progress < 100) {
|
Converter.getVolumeFromPercentage(barLeftVolume.getProgress()),
|
||||||
rightVolume = progress / 100.0f;
|
Converter.getVolumeFromPercentage(progress));
|
||||||
}
|
|
||||||
if (barLeftVolume.getProgress() < 100) {
|
|
||||||
leftVolume = barLeftVolume.getProgress() / 100.0f;
|
|
||||||
}
|
|
||||||
controller.setVolume(leftVolume, rightVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,6 +29,7 @@ import de.danoeh.antennapod.core.storage.APCleanupAlgorithm;
|
||||||
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
|
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
|
||||||
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
|
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
|
||||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
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
|
* Provides access to preferences set by the user in the settings screen. A
|
||||||
|
@ -260,20 +261,12 @@ public class UserPreferences {
|
||||||
|
|
||||||
public static float getLeftVolume() {
|
public static float getLeftVolume() {
|
||||||
int volume = prefs.getInt(PREF_LEFT_VOLUME, 100);
|
int volume = prefs.getInt(PREF_LEFT_VOLUME, 100);
|
||||||
if(volume == 100) {
|
return Converter.getVolumeFromPercentage(volume);
|
||||||
return 1.0f;
|
|
||||||
} else {
|
|
||||||
return (float) (1 - (Math.log(100 - volume) / Math.log(100)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getRightVolume() {
|
public static float getRightVolume() {
|
||||||
int volume = prefs.getInt(PREF_RIGHT_VOLUME, 100);
|
int volume = prefs.getInt(PREF_RIGHT_VOLUME, 100);
|
||||||
if(volume == 100) {
|
return Converter.getVolumeFromPercentage(volume);
|
||||||
return 1.0f;
|
|
||||||
} else {
|
|
||||||
return (float) (1 - (Math.log(100 - volume) / Math.log(100)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldPauseForFocusLoss() {
|
public static boolean shouldPauseForFocusLoss() {
|
||||||
|
|
|
@ -119,4 +119,15 @@ public final class Converter {
|
||||||
return result;
|
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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue