aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout/seekbar_preference.xml18
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/xml/settings.xml24
-rw-r--r--src/github/daneren2005/dsub/activity/SettingsActivity.java16
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java6
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java2
-rw-r--r--src/github/daneren2005/dsub/view/SeekBarPreference.java137
7 files changed, 201 insertions, 4 deletions
diff --git a/res/layout/seekbar_preference.xml b/res/layout/seekbar_preference.xml
new file mode 100644
index 00000000..4d3bc877
--- /dev/null
+++ b/res/layout/seekbar_preference.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/value"
+ android:padding="5dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="right" />
+ <SeekBar
+ android:id="@+id/seek_bar"
+ android:padding="15dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 64237ac0..b00f66bc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -431,6 +431,8 @@
<string name="settings.admin_enabled_summary">Whether or not to display the admin listing in the pull out drawer</string>
<string name="settings.replay_gain">Replay Gain</string>
<string name="settings.replay_gain_summary">Whether or not to scale playback volume by track and album replay gain tags</string>
+ <string name="settings.replay_gain_bump">Replay Gain Pre-amp</string>
+ <string name="settings.replay_gain_untagged">Songs without Replay Gain</string>
<string name="shuffle.title">Shuffle By</string>
<string name="shuffle.startYear">Start Year:</string>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index bc2fd9e3..553fe710 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -355,6 +355,30 @@
</PreferenceCategory>
<PreferenceCategory
+ android:title="@string/settings.replay_gain">
+
+ <CheckBoxPreference
+ android:title="@string/settings.replay_gain"
+ android:summary="@string/settings.replay_gain_summary"
+ android:key="replayGain"
+ android:defaultValue="false"/>
+
+ <github.daneren2005.dsub.view.SeekBarPreference
+ android:key="replayGainBump2"
+ android:negativeButtonText="@null"
+ android:dialogLayout="@layout/seekbar_preference"
+ android:title="@string/settings.replay_gain_bump"
+ android:defaultValue="75"/>
+
+ <github.daneren2005.dsub.view.SeekBarPreference
+ android:key="replayGainUntagged2"
+ android:negativeButtonText="@null"
+ android:dialogLayout="@layout/seekbar_preference"
+ android:title="@string/settings.replay_gain_untagged"
+ android:defaultValue="150"/>
+ </PreferenceCategory>
+
+ <PreferenceCategory
android:title="@string/settings.other_title">
<CheckBoxPreference
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java
index 710d7385..5ca30f62 100644
--- a/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -86,6 +86,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private CheckBoxPreference syncNotification;
private CheckBoxPreference syncStarred;
private CheckBoxPreference syncMostRecent;
+ private CheckBoxPreference replayGain;
+ private Preference replayGainBump;
+ private Preference replayGainUntagged;
private String internalSSID;
private int serverCount = 3;
@@ -127,6 +130,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
syncNotification = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION);
syncStarred = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_STARRED);
syncMostRecent = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT);
+ replayGain = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN);
+ replayGainBump = (Preference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP);
+ replayGainUntagged = (Preference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED);
settings = Util.getPreferences(this);
serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
@@ -267,7 +273,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
}
else if(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT.equals(key)) {
SyncUtil.removeMostRecentSyncFiles(this);
- } else if(Constants.PREFERENCES_KEY_REPLAY_GAIN.equals(key)) {
+ } else if(Constants.PREFERENCES_KEY_REPLAY_GAIN.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED.equals(key)) {
DownloadService downloadService = DownloadService.getInstance();
if(downloadService != null) {
downloadService.reapplyVolume();
@@ -331,6 +337,14 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
syncMostRecent.setEnabled(false);
}
}
+ if(replayGain.isChecked()) {
+ replayGainBump.setEnabled(true);
+ replayGainUntagged.setEnabled(true);
+ } else {
+ replayGainBump.setEnabled(false);
+ replayGainUntagged.setEnabled(false);
+ }
+
for (ServerSettings ss : serverSettings.values()) {
ss.update();
}
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 21de600d..d813ddc0 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -1965,7 +1965,7 @@ public class DownloadService extends Service {
return;
}
- SharedPreferences prefs = Util.getPeferences(this);
+ SharedPreferences prefs = Util.getPreferences(this);
try {
float[] rg = BastpUtil.getReplayGainValues(downloadFile.getFile().getCanonicalPath()); /* track, album */
float adjust = 0f;
@@ -1980,13 +1980,13 @@ public class DownloadService extends Service {
if (adjust == 0) {
/* No RG value found: decrease volume for untagged song if requested by user */
- int untagged = prefs.getInt(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED, 0);
+ int untagged = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED, "0"));
adjust = (untagged - 150) / 10f;
} else {
/* This song has some replay gain info, we are now going to apply the 'bump' value
** The preferences stores the raw value of the seekbar, that's 0-150
** But we want -15 <-> +15, so 75 shall be zero */
- int bump = prefs.getInt(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP, 0);
+ int bump = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP, "0"));
adjust += 2 * (bump - 75) / 10f;
}
}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index 88dfa086..30dc33b4 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -145,6 +145,8 @@ public final class Constants {
public static final String PREFERENCES_KEY_RECENT_COUNT = "mostRecentCount";
public static final String PREFERENCES_KEY_MENU_RATING = "showRating";
public static final String PREFERENCES_KEY_REPLAY_GAIN = "replayGain";
+ public static final String PREFERENCES_KEY_REPLAY_GAIN_BUMP = "replayGainBump2";
+ public static final String PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED = "replayGainUntagged2";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";
diff --git a/src/github/daneren2005/dsub/view/SeekBarPreference.java b/src/github/daneren2005/dsub/view/SeekBarPreference.java
new file mode 100644
index 00000000..d0127857
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/SeekBarPreference.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.util.Constants;
+
+/**
+ * SeekBar preference to set the shake force threshold.
+ */
+public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
+ /**
+ * The current value.
+ */
+ private String mValue;
+
+ /**
+ * Our context (needed for getResources())
+ */
+ private Context mContext;
+
+ /**
+ * TextView to display current threshold.
+ */
+ private TextView mValueText;
+
+ public SeekBarPreference(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ mContext = context;
+ }
+
+ @Override
+ public CharSequence getSummary()
+ {
+ return getSummary(mValue);
+ }
+
+ @Override
+ protected Object onGetDefaultValue(TypedArray a, int index)
+ {
+ return a.getString(index);
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restoreValue, Object defaultValue)
+ {
+ mValue = restoreValue ? getPersistedString((String) defaultValue) : (String)defaultValue;
+ }
+
+ /**
+ * Create the summary for the given value.
+ *
+ * @param value The force threshold.
+ * @return A string representation of the threshold.
+ */
+ private String getSummary(String value) {
+ int val = Integer.parseInt(value);
+ if(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED.equals(getKey())) {
+ return String.format("%+.1f dB", (val - 150) / 10f);
+ } else if(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP.equals(getKey())) {
+ return String.format("%+.1f dB", 2 * (val - 75) / 10f);
+ } else {
+ return String.format("%+.1f", val);
+ }
+ }
+
+ @Override
+ protected View onCreateDialogView()
+ {
+ View view = super.onCreateDialogView();
+
+ mValueText = (TextView)view.findViewById(R.id.value);
+ mValueText.setText(getSummary(mValue));
+
+ SeekBar seekBar = (SeekBar)view.findViewById(R.id.seek_bar);
+ seekBar.setMax(150);
+ seekBar.setProgress(Integer.parseInt(mValue));
+ seekBar.setOnSeekBarChangeListener(this);
+
+ return view;
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult)
+ {
+ persistString(mValue);
+ notifyChanged();
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
+ {
+ if (fromUser) {
+ mValue = String.valueOf(progress);
+ mValueText.setText(getSummary(mValue));
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar)
+ {
+ }
+}