CustomSeekBar: Add defaultValueText attribute
Change-Id: If4d0c8dac4aca9466aafab6cf782d1cf08f80f93
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index fb90900..e506b08 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -17,6 +17,7 @@
<!-- Base attributes available to CustomSeekBarPreference. -->
<declare-styleable name="CustomSeekBarPreference">
+ <attr name="defaultValueText" format="string" />
<attr name="interval" format="integer" />
<attr name="showSign" format="boolean" />
<attr name="units" format="string|reference" />
diff --git a/src/com/bliss/support/preferences/CustomSeekBarPreference.java b/src/com/bliss/support/preferences/CustomSeekBarPreference.java
index bf7a5e6..00ab7fd 100644
--- a/src/com/bliss/support/preferences/CustomSeekBarPreference.java
+++ b/src/com/bliss/support/preferences/CustomSeekBarPreference.java
@@ -48,6 +48,8 @@
protected int mMaxValue = 100;
protected boolean mDefaultValueExists = false;
protected int mDefaultValue;
+ protected boolean mDefaultValueTextExists = false;
+ protected String mDefaultValueText;
protected int mValue;
@@ -94,6 +96,12 @@
mValue = mMinValue;
}
+ String defaultValueText = attrs.getAttributeValue(SETTINGS_NS, "defaultValueText");
+ mDefaultValueTextExists = defaultValueText != null && !defaultValueText.isEmpty();
+ if (mDefaultValueTextExists) {
+ mDefaultValueText = defaultValueText;
+ }
+
mSeekBar = new SeekBar(context, attrs);
setLayoutResource(R.layout.preference_custom_seekbar);
}
@@ -163,6 +171,9 @@
}
protected String getTextValue(int v) {
+ if (mDefaultValueTextExists && mDefaultValueExists && v == mDefaultValue) {
+ return mDefaultValueText;
+ }
return (mShowSign && v > 0 ? "+" : "") + String.valueOf(v) + mUnits;
}