SeekbarPref: support dummy text for zero-values

This commit is contained in:
Adrian Ulrich 2015-10-05 20:56:04 +02:00
parent bcd400ef00
commit 3746a58767
2 changed files with 12 additions and 1 deletions

View File

@ -7,5 +7,6 @@
<attr name="sbpSummaryValueAddition" format="float"/>
<attr name="sbpSummaryText" format="string"/>
<attr name="sbpSummaryFormat" format="string"/>
<attr name="sbpSummaryZeroText" format="string" />
</declare-styleable>
</resources>

View File

@ -63,6 +63,10 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
* The text to use in the summary
*/
private String mSummaryText;
/**
* Text to display if the value equals zero
*/
private String mZeroText;
/**
* Add given value to summary value
*/
@ -100,6 +104,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
mSummaryFormat = (mSummaryFormat == null ? "%s %.1f" : mSummaryFormat);
mSummaryText = a.getString(R.styleable.SeekBarPreference_sbpSummaryText);
mSummaryText = (mSummaryText == null ? "" : mSummaryText);
mZeroText = a.getString(R.styleable.SeekBarPreference_sbpSummaryZeroText); // unlike other strings, this may be null
a.recycle();
}
@ -136,7 +141,12 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
if (mSummaryValueMultiplication != 0f)
fValue = fValue * mSummaryValueMultiplication;
return String.format(mSummaryFormat, mSummaryText, fValue);
String result = String.format(mSummaryFormat, mSummaryText, fValue);
if (fValue == 0f && mZeroText != null)
result = mZeroText;
return result;
}
@Override