SeekbarPref: support dummy text for zero-values
This commit is contained in:
parent
bcd400ef00
commit
3746a58767
@ -7,5 +7,6 @@
|
|||||||
<attr name="sbpSummaryValueAddition" format="float"/>
|
<attr name="sbpSummaryValueAddition" format="float"/>
|
||||||
<attr name="sbpSummaryText" format="string"/>
|
<attr name="sbpSummaryText" format="string"/>
|
||||||
<attr name="sbpSummaryFormat" format="string"/>
|
<attr name="sbpSummaryFormat" format="string"/>
|
||||||
|
<attr name="sbpSummaryZeroText" format="string" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -63,6 +63,10 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
|
|||||||
* The text to use in the summary
|
* The text to use in the summary
|
||||||
*/
|
*/
|
||||||
private String mSummaryText;
|
private String mSummaryText;
|
||||||
|
/**
|
||||||
|
* Text to display if the value equals zero
|
||||||
|
*/
|
||||||
|
private String mZeroText;
|
||||||
/**
|
/**
|
||||||
* Add given value to summary value
|
* Add given value to summary value
|
||||||
*/
|
*/
|
||||||
@ -100,6 +104,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
|
|||||||
mSummaryFormat = (mSummaryFormat == null ? "%s %.1f" : mSummaryFormat);
|
mSummaryFormat = (mSummaryFormat == null ? "%s %.1f" : mSummaryFormat);
|
||||||
mSummaryText = a.getString(R.styleable.SeekBarPreference_sbpSummaryText);
|
mSummaryText = a.getString(R.styleable.SeekBarPreference_sbpSummaryText);
|
||||||
mSummaryText = (mSummaryText == null ? "" : mSummaryText);
|
mSummaryText = (mSummaryText == null ? "" : mSummaryText);
|
||||||
|
mZeroText = a.getString(R.styleable.SeekBarPreference_sbpSummaryZeroText); // unlike other strings, this may be null
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +141,12 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
|
|||||||
if (mSummaryValueMultiplication != 0f)
|
if (mSummaryValueMultiplication != 0f)
|
||||||
fValue = fValue * mSummaryValueMultiplication;
|
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
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user