New custom seekbar: more improvements
fix value txt being cutted when too long
allow to set a custom string to show instead of the
numeric value when value is defaultValue
Change-Id: I5d359518d8b394be9609e2cd8469751b7b234f1f
diff --git a/res/layout/preference_custom_seekbar.xml b/res/layout/preference_custom_seekbar.xml
index 73ef6d5..576fa3f 100644
--- a/res/layout/preference_custom_seekbar.xml
+++ b/res/layout/preference_custom_seekbar.xml
@@ -30,15 +30,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="44dp"
- android:gravity="start|center_vertical"
+ android:gravity="center"
android:orientation="horizontal"
android:paddingEnd="12dp"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<TextView
android:id="@+id/seekBarPrefValue"
- android:layout_width="24dp"
- android:layout_height="24dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
android:textAlignment="center"
android:singleLine="true"
android:ellipsize="end"
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 206e159..fddd8cd 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -20,6 +20,7 @@
<attr name="interval" format="integer" />
<attr name="min" format="integer" />
<attr name="units" format="string|reference" />
+ <attr name="defaultText" format="string|reference" />
</declare-styleable>
</resources>
diff --git a/src/com/bliss/support/preferences/CustomSeekBarPreference.java b/src/com/bliss/support/preferences/CustomSeekBarPreference.java
index b3d71e9..1bed0a6 100644
--- a/src/com/bliss/support/preferences/CustomSeekBarPreference.java
+++ b/src/com/bliss/support/preferences/CustomSeekBarPreference.java
@@ -40,6 +40,7 @@
private int mDefaultValue = -1;
private int mMax = 100;
private String mUnits = "";
+ private String mDefaultText = "";
private SeekBar mSeekBar;
private TextView mTitle;
private TextView mStatusText;
@@ -54,6 +55,7 @@
mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0);
mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1);
mUnits = getAttributeStringValue(attrs, SETTINGS_NS, "units", "");
+ mDefaultText = getAttributeStringValue(attrs, SETTINGS_NS, "defaultText", "Def");
Integer id = a.getResourceId(R.styleable.CustomSeekBarPreference_units, 0);
if (id > 0) {
@@ -131,8 +133,11 @@
Log.e(TAG, "Error binding view: " + ex.toString());
}
mStatusText = (TextView) view.findViewById(R.id.seekBarPrefValue);
- mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
- mStatusText.setMinimumWidth(30);
+ if (mCurrentValue == mDefaultValue) {
+ mStatusText.setText(mDefaultText);
+ } else {
+ mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
+ }
mSeekBar.setProgress(mCurrentValue - mMin);
mTitle = (TextView) view.findViewById(android.R.id.title);
@@ -176,7 +181,11 @@
// change accepted, store it
mCurrentValue = newValue;
if (mStatusText != null) {
- mStatusText.setText(String.valueOf(newValue) + mUnits);
+ if (newValue == mDefaultValue) {
+ mStatusText.setText(mDefaultText);
+ } else {
+ mStatusText.setText(String.valueOf(newValue) + mUnits);
+ }
}
persistInt(newValue);
}