aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-09-27 17:42:42 -0700
committerScott Jackson <daneren2005@gmail.com>2014-09-27 17:42:42 -0700
commitd77b2b14ebf6532b7b0e42e9d2219ea1dacbdb18 (patch)
tree7c2b222babd7ea30f7fa07bcab7473b55ccae1fe
parent11810a9a0b0a041916faa8bfd07b0b7bd4533583 (diff)
downloaddsub-d77b2b14ebf6532b7b0e42e9d2219ea1dacbdb18.tar.gz
dsub-d77b2b14ebf6532b7b0e42e9d2219ea1dacbdb18.tar.bz2
dsub-d77b2b14ebf6532b7b0e42e9d2219ea1dacbdb18.zip
#241 Generalize SeekBarPreference to accept custom attributes
-rw-r--r--res/values/attrs.xml7
-rw-r--r--res/xml/settings.xml15
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java2
-rw-r--r--src/github/daneren2005/dsub/view/SeekBarPreference.java29
4 files changed, 38 insertions, 15 deletions
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 13456e18..e0a3d00d 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -26,4 +26,11 @@
<attr name="rating_bad" format="reference"/>
<attr name="rating_good" format="reference"/>
<attr name="drawerItemsIcons" format="reference"/>
+
+ <declare-styleable name="SeekBarPreference">
+ <attr name="min" format="integer"/>
+ <attr name="max" format="integer"/>
+ <attr name="stepSize" format="float"/>
+ <attr name="display" format="string"/>
+ </declare-styleable>
</resources>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index 553fe710..de9c641b 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:myns="http://schemas.android.com/apk/res/github.daneren2005.dsub"
android:title="@string/settings.title">
<PreferenceScreen
@@ -365,17 +366,23 @@
<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"/>
+ android:defaultValue="75"
+ myns:max="150"
+ myns:min="-150"
+ myns:stepSize="10"
+ myns:display="%+.1f dB"/>
<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"/>
+ android:defaultValue="150"
+ myns:max="0"
+ myns:min="-150"
+ myns:stepSize="10"
+ myns:display="%+.1f dB"/>
</PreferenceCategory>
<PreferenceCategory
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 44d63ba3..588df901 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -1989,7 +1989,7 @@ public class DownloadService extends Service {
** 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 = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP, "0"));
- adjust += 2 * (bump - 75) / 10f;
+ adjust += (bump - 150) / 10f;
}
}
diff --git a/src/github/daneren2005/dsub/view/SeekBarPreference.java b/src/github/daneren2005/dsub/view/SeekBarPreference.java
index d0127857..84aed452 100644
--- a/src/github/daneren2005/dsub/view/SeekBarPreference.java
+++ b/src/github/daneren2005/dsub/view/SeekBarPreference.java
@@ -41,6 +41,10 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
* The current value.
*/
private String mValue;
+ private int mMin;
+ private int mMax;
+ private float mStepSize;
+ private String mDisplay;
/**
* Our context (needed for getResources())
@@ -56,6 +60,15 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
{
super(context, attrs);
mContext = context;
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBarPreference);
+ mMin = a.getInteger(R.styleable.SeekBarPreference_min, 0);
+ mMax = a.getInteger(R.styleable.SeekBarPreference_max, 100);
+ mStepSize = a.getFloat(R.styleable.SeekBarPreference_stepSize, 1f);
+ mDisplay = a.getString(R.styleable.SeekBarPreference_display);
+ if(mDisplay == null) {
+ mDisplay = "%+.1f";
+ }
}
@Override
@@ -84,13 +97,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
*/
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);
- }
+ return String.format(mDisplay, (val + mMin) / mStepSize);
}
@Override
@@ -102,7 +109,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
mValueText.setText(getSummary(mValue));
SeekBar seekBar = (SeekBar)view.findViewById(R.id.seek_bar);
- seekBar.setMax(150);
+ seekBar.setMax(mMax - mMin);
seekBar.setProgress(Integer.parseInt(mValue));
seekBar.setOnSeekBarChangeListener(this);
@@ -112,8 +119,10 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
@Override
protected void onDialogClosed(boolean positiveResult)
{
- persistString(mValue);
- notifyChanged();
+ if(positiveResult) {
+ persistString(mValue);
+ notifyChanged();
+ }
}
@Override