diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-02-07 19:44:56 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-02-07 19:44:56 -0800 |
commit | f11bcc17cdd7495b577812b4bcb68710c22e6a6c (patch) | |
tree | f6dd79338d44b5905532030b67381fdaefbe997e | |
parent | 6612b1049231374d69d4cdd3fe9b52571048cda1 (diff) | |
download | dsub-f11bcc17cdd7495b577812b4bcb68710c22e6a6c.tar.gz dsub-f11bcc17cdd7495b577812b4bcb68710c22e6a6c.tar.bz2 dsub-f11bcc17cdd7495b577812b4bcb68710c22e6a6c.zip |
Only start Equalizer if actually being used
5 files changed, 25 insertions, 6 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 05591818..1c44fca1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -119,6 +119,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi private int swipeDistance; private int swipeVelocity; private VisualizerView visualizerView; + private boolean equalizerOn; private boolean nowPlaying = true; private ScheduledFuture<?> hideControlsFuture; @@ -275,6 +276,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi equalizerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + equalizerOn = true; startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class)); setControlsVisible(true); } @@ -353,7 +355,10 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi if (!equalizerAvailable) { equalizerButton.setVisibility(View.GONE); - } + } else { + SharedPreferences prefs = Util.getPreferences(DownloadActivity.this); + equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false); + } if (!visualizerAvailable) { visualizerButton.setVisibility(View.GONE); } else { @@ -446,10 +451,13 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi } private void updateButtons() { - boolean eqEnabled = getDownloadService() != null && getDownloadService().getEqualizerController() != null && - getDownloadService().getEqualizerController().isEnabled(); - equalizerButton.setTextColor(eqEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); - + if(equalizerOn && getDownloadService() != null && getDownloadService().getEqualizerController() != null && + getDownloadService().getEqualizerController().isEnabled()) { + equalizerButton.setTextColor(COLOR_BUTTON_ENABLED); + } else { + equalizerButton.setTextColor(COLOR_BUTTON_DISABLED); + } + if (visualizerView != null) { visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java index 9906673a..2aa61945 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import android.app.Activity; +import android.content.SharedPreferences; import android.media.audiofx.Equalizer; import android.os.Bundle; import android.view.ContextMenu; @@ -36,6 +37,8 @@ import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.Util; /** * Equalizer controls. @@ -114,6 +117,10 @@ public class EqualizerActivity extends Activity { } private void setEqualizerEnabled(boolean enabled) { + SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this); + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(Constants.PREFERENCES_EQUALIZER_ON, enabled); + editor.commit(); equalizer.setEnabled(enabled); updateBars(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java b/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java index 4206b156..f16ff968 100644 --- a/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java +++ b/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java @@ -56,7 +56,6 @@ public class EqualizerController { } public EqualizerController(Context context, MediaPlayer mediaPlayer) { - Log.d(TAG, "Setting up equalizer"); this.context = context; try { equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId()); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 340ff179..9e6662cf 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -174,6 +174,10 @@ public class DownloadServiceImpl extends Service implements DownloadService { instance = this; lifecycleSupport.onCreate(); + + if(prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) { + getEqualizerController(); + } } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index c116c484..d633e7f0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -88,6 +88,7 @@ public final class Constants { public static final String PREFERENCES_KEY_SHUFFLE_GENRE = "genre"; 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"; // Name of the preferences file. public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences"; |