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_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minWidth="44dp"
|
android:minWidth="44dp"
|
||||||
android:gravity="start|center_vertical"
|
android:gravity="center"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="12dp"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:paddingBottom="4dp">
|
android:paddingBottom="4dp">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/seekBarPrefValue"
|
android:id="@+id/seekBarPrefValue"
|
||||||
android:layout_width="24dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="24dp"
|
android:layout_height="wrap_content"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<attr name="interval" format="integer" />
|
<attr name="interval" format="integer" />
|
||||||
<attr name="min" format="integer" />
|
<attr name="min" format="integer" />
|
||||||
<attr name="units" format="string|reference" />
|
<attr name="units" format="string|reference" />
|
||||||
|
<attr name="defaultText" format="string|reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<!-- Value to pass to callback when restore button is pressed -->
|
<!-- 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 mDefaultValue = -1;
|
||||||
private int mMax = 100;
|
private int mMax = 100;
|
||||||
private String mUnits = "";
|
private String mUnits = "";
|
||||||
|
private String mDefaultText = "";
|
||||||
private SeekBar mSeekBar;
|
private SeekBar mSeekBar;
|
||||||
private TextView mTitle;
|
private TextView mTitle;
|
||||||
private TextView mStatusText;
|
private TextView mStatusText;
|
||||||
@@ -54,6 +55,7 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
|||||||
mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0);
|
mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0);
|
||||||
mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1);
|
mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1);
|
||||||
mUnits = getAttributeStringValue(attrs, SETTINGS_NS, "units", "");
|
mUnits = getAttributeStringValue(attrs, SETTINGS_NS, "units", "");
|
||||||
|
mDefaultText = getAttributeStringValue(attrs, SETTINGS_NS, "defaultText", "Def");
|
||||||
|
|
||||||
Integer id = a.getResourceId(R.styleable.CustomSeekBarPreference_units, 0);
|
Integer id = a.getResourceId(R.styleable.CustomSeekBarPreference_units, 0);
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
@@ -131,8 +133,11 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
|||||||
Log.e(TAG, "Error binding view: " + ex.toString());
|
Log.e(TAG, "Error binding view: " + ex.toString());
|
||||||
}
|
}
|
||||||
mStatusText = (TextView) view.findViewById(R.id.seekBarPrefValue);
|
mStatusText = (TextView) view.findViewById(R.id.seekBarPrefValue);
|
||||||
mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
|
if (mCurrentValue == mDefaultValue) {
|
||||||
mStatusText.setMinimumWidth(30);
|
mStatusText.setText(mDefaultText);
|
||||||
|
} else {
|
||||||
|
mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
|
||||||
|
}
|
||||||
mSeekBar.setProgress(mCurrentValue - mMin);
|
mSeekBar.setProgress(mCurrentValue - mMin);
|
||||||
mTitle = (TextView) view.findViewById(android.R.id.title);
|
mTitle = (TextView) view.findViewById(android.R.id.title);
|
||||||
|
|
||||||
@@ -176,7 +181,11 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
|||||||
// change accepted, store it
|
// change accepted, store it
|
||||||
mCurrentValue = newValue;
|
mCurrentValue = newValue;
|
||||||
if (mStatusText != null) {
|
if (mStatusText != null) {
|
||||||
mStatusText.setText(String.valueOf(newValue) + mUnits);
|
if (newValue == mDefaultValue) {
|
||||||
|
mStatusText.setText(mDefaultText);
|
||||||
|
} else {
|
||||||
|
mStatusText.setText(String.valueOf(newValue) + mUnits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
persistInt(newValue);
|
persistInt(newValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user