aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-02-12 21:44:31 -0800
committerScott Jackson <daneren2005@gmail.com>2013-02-12 21:44:31 -0800
commit9d5e7dd4f1a19fb712bd27d764909ae57d10ac6d (patch)
tree57340fff9f2b35b068f6e698ae538ba4e1995544 /subsonic-android/src/github/daneren2005
parentda65a7f83b546477c0b00252c270352e0592cdae (diff)
downloaddsub-9d5e7dd4f1a19fb712bd27d764909ae57d10ac6d.tar.gz
dsub-9d5e7dd4f1a19fb712bd27d764909ae57d10ac6d.tar.bz2
dsub-9d5e7dd4f1a19fb712bd27d764909ae57d10ac6d.zip
Closes #59 Add Master control to EQ
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java50
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java1
2 files changed, 38 insertions, 13 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
index 78e7cc51..1dbe0f7c 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
@@ -55,6 +55,7 @@ public class EqualizerActivity extends Activity {
private final Map<Short, SeekBar> bars = new HashMap<Short, SeekBar>();
private EqualizerController equalizerController;
private Equalizer equalizer;
+ private short masterLevel = 0;
@Override
public void onCreate(Bundle bundle) {
@@ -139,16 +140,27 @@ public class EqualizerActivity extends Activity {
}
private void updateBars() {
-
+ boolean isEnabled = equalizer.getEnabled();
+ short minEQLevel = equalizer.getBandLevelRange()[0];
for (Map.Entry<Short, SeekBar> entry : bars.entrySet()) {
short band = entry.getKey();
SeekBar bar = entry.getValue();
- bar.setEnabled(equalizer.getEnabled());
+ bar.setEnabled(isEnabled);
if(band >= (short)0) {
- short minEQLevel = equalizer.getBandLevelRange()[0];
+ equalizer.setBandLevel(band, (short)(equalizer.getBandLevel(band) - masterLevel));
bar.setProgress(equalizer.getBandLevel(band) - minEQLevel);
+ } else if(!isEnabled) {
+ bar.setProgress(-minEQLevel);
}
}
+
+ if(!isEnabled) {
+ masterLevel = 0;
+ SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel);
+ editor.commit();
+ }
}
private void initEqualizer() {
@@ -158,7 +170,9 @@ public class EqualizerActivity extends Activity {
final short maxEQLevel = equalizer.getBandLevelRange()[1];
// Setup Pregain
- initPregain(layout, equalizer.getBandLevel((short)0), minEQLevel, maxEQLevel);
+ SharedPreferences prefs = Util.getPreferences(this);
+ masterLevel = (short)prefs.getInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, 0);
+ initPregain(layout, minEQLevel, maxEQLevel);
for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
final short band = i;
@@ -173,6 +187,9 @@ public class EqualizerActivity extends Activity {
bars.put(band, bar);
bar.setMax(maxEQLevel - minEQLevel);
short level = equalizer.getBandLevel(band);
+ if(equalizer.getEnabled()) {
+ level = (short) (level - masterLevel);
+ }
bar.setProgress(level - minEQLevel);
bar.setEnabled(equalizer.getEnabled());
updateLevelText(levelTextView, level);
@@ -182,7 +199,7 @@ public class EqualizerActivity extends Activity {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
short level = (short) (progress + minEQLevel);
if (fromUser) {
- equalizer.setBandLevel(band, level);
+ equalizer.setBandLevel(band, (short)(level + masterLevel));
}
updateLevelText(levelTextView, level);
}
@@ -199,7 +216,7 @@ public class EqualizerActivity extends Activity {
}
}
- private void initPregain(LinearLayout layout, short level, final short minEQLevel, final short maxEQLevel) {
+ private void initPregain(LinearLayout layout, final short minEQLevel, final short maxEQLevel) {
View bandBar = LayoutInflater.from(this).inflate(R.layout.equalizer_bar, null);
TextView freqTextView = (TextView) bandBar.findViewById(R.id.equalizer_frequency);
final TextView levelTextView = (TextView) bandBar.findViewById(R.id.equalizer_level);
@@ -209,18 +226,25 @@ public class EqualizerActivity extends Activity {
bars.put((short)-1, bar);
bar.setMax(maxEQLevel - minEQLevel);
- bar.setProgress(level - minEQLevel);
+ bar.setProgress(masterLevel - minEQLevel);
bar.setEnabled(equalizer.getEnabled());
- updateLevelText(levelTextView, (short)0);
+ updateLevelText(levelTextView, masterLevel);
bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- short level = (short) (progress + minEQLevel);
- /*if (fromUser) {
- equalizer.setBandLevel(band, level);
- }*/
- updateLevelText(levelTextView, level);
+ masterLevel = (short) (progress + minEQLevel);
+ if (fromUser) {
+ SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel);
+ editor.commit();
+ for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
+ short level = (short) ((bars.get(i).getProgress() + minEQLevel) + masterLevel);
+ equalizer.setBandLevel(i, level);
+ }
+ }
+ updateLevelText(levelTextView, masterLevel);
}
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index d633e7f0..3ee7d7e8 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -89,6 +89,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_KEEP_SCREEN_ON = "keepScreenOn";
public static final String PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength";
public static final String PREFERENCES_EQUALIZER_ON = "equalizerOn";
+ public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings";
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";