Customseekbar: add method to set default values
also be sure default values is not greater than max value
Change-Id: I59c8bd20694bc593c584b66c4122d0be7321856a
diff --git a/src/com/bliss/support/preferences/CustomSeekBarPreference.java b/src/com/bliss/support/preferences/CustomSeekBarPreference.java
index cbdd59b..2f55784 100644
--- a/src/com/bliss/support/preferences/CustomSeekBarPreference.java
+++ b/src/com/bliss/support/preferences/CustomSeekBarPreference.java
@@ -54,6 +54,9 @@
mMax = attrs.getAttributeIntValue(ANDROIDNS, "max", 100);
mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0);
mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1);
+ if (mDefaultValue > mMax) {
+ mDefaultValue = mMax;
+ }
mUnits = getAttributeStringValue(attrs, SETTINGS_NS, "units", "");
mDefaultText = getAttributeStringValue(attrs, SETTINGS_NS, "defaultText", "Def");
@@ -141,7 +144,7 @@
mStatusText.setText(mDefaultText);
} else {
mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
- }
+ }
mSeekBar.setProgress(mCurrentValue - mMin);
mTitle = (TextView) view.findViewById(android.R.id.title);
@@ -226,6 +229,16 @@
}
}
+ public void setDefaultValue(int value) {
+ mDefaultValue = value;
+ if (mDefaultValue > mMax) {
+ mDefaultValue = mMax;
+ }
+ if (mCurrentValue == mDefaultValue) {
+ mStatusText.setText(mDefaultText);
+ }
+ }
+
@Override
public void setEnabled(boolean enabled) {
if (mSeekBar != null && mStatusText != null && mTitle != null) {