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
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -19,6 +19,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>
|
||||
|
||||
<!-- Value to pass to callback when restore button is pressed -->
|
||||
|
||||
@@ -40,6 +40,7 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
||||
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 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
||||
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 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
||||
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 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
||||
// 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user