mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-30 23:00:09 -05:00
Extract code to scale the slider value for the message content font setting
This commit is contained in:
parent
f1682fe517
commit
53eac39a90
@ -121,10 +121,8 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
|||||||
|
|
||||||
mMessageViewContentSlider = (SliderPreference) findPreference(
|
mMessageViewContentSlider = (SliderPreference) findPreference(
|
||||||
PREFERENCE_MESSAGE_VIEW_CONTENT_FONT_SLIDER);
|
PREFERENCE_MESSAGE_VIEW_CONTENT_FONT_SLIDER);
|
||||||
// Scale to [0, 1]
|
|
||||||
mMessageViewContentSlider.setValue((float)
|
mMessageViewContentSlider.setValue(scaleFromInt(fontSizes.getMessageViewContentAsPercent()));
|
||||||
(fontSizes.getMessageViewContentAsPercent() - FONT_PERCENT_MIN) /
|
|
||||||
(FONT_PERCENT_MAX - FONT_PERCENT_MIN));
|
|
||||||
mMessageViewContentSlider.setOnPreferenceChangeListener(
|
mMessageViewContentSlider.setOnPreferenceChangeListener(
|
||||||
new Preference.OnPreferenceChangeListener() {
|
new Preference.OnPreferenceChangeListener() {
|
||||||
// Show the preference value in the preference summary field.
|
// Show the preference value in the preference summary field.
|
||||||
@ -132,9 +130,7 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
|||||||
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
|
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
|
||||||
final SliderPreference slider = (SliderPreference) preference;
|
final SliderPreference slider = (SliderPreference) preference;
|
||||||
final Float value = (Float) newValue;
|
final Float value = (Float) newValue;
|
||||||
// Scale from [0, 1]
|
slider.setSummary(String.valueOf(scaleToInt(value) + "%"));
|
||||||
slider.setSummary(String.valueOf((int)(FONT_PERCENT_MIN +
|
|
||||||
value * (FONT_PERCENT_MAX - FONT_PERCENT_MIN))) + "%");
|
|
||||||
slider.setDialogTitle(slider.getTitle() + " " + slider.getSummary());
|
slider.setDialogTitle(slider.getTitle() + " " + slider.getSummary());
|
||||||
if (slider.getDialog() != null) {
|
if (slider.getDialog() != null) {
|
||||||
slider.getDialog().setTitle(slider.getDialogTitle());
|
slider.getDialog().setTitle(slider.getDialogTitle());
|
||||||
@ -175,10 +171,7 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
|||||||
fontSizes.setMessageViewAdditionalHeaders(Integer.parseInt(mMessageViewAdditionalHeaders.getValue()));
|
fontSizes.setMessageViewAdditionalHeaders(Integer.parseInt(mMessageViewAdditionalHeaders.getValue()));
|
||||||
fontSizes.setMessageViewSubject(Integer.parseInt(mMessageViewSubject.getValue()));
|
fontSizes.setMessageViewSubject(Integer.parseInt(mMessageViewSubject.getValue()));
|
||||||
fontSizes.setMessageViewDate(Integer.parseInt(mMessageViewDate.getValue()));
|
fontSizes.setMessageViewDate(Integer.parseInt(mMessageViewDate.getValue()));
|
||||||
// Scale from [0, 1]
|
fontSizes.setMessageViewContentAsPercent(scaleToInt(mMessageViewContentSlider.getValue()));
|
||||||
fontSizes.setMessageViewContentAsPercent((int)(FONT_PERCENT_MIN +
|
|
||||||
mMessageViewContentSlider.getValue() *
|
|
||||||
(FONT_PERCENT_MAX - FONT_PERCENT_MIN)));
|
|
||||||
|
|
||||||
fontSizes.setMessageComposeInput(Integer.parseInt(mMessageComposeInput.getValue()));
|
fontSizes.setMessageComposeInput(Integer.parseInt(mMessageComposeInput.getValue()));
|
||||||
|
|
||||||
@ -188,6 +181,14 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
|||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int scaleToInt(float sliderValue) {
|
||||||
|
return (int) (FONT_PERCENT_MIN + sliderValue * (FONT_PERCENT_MAX - FONT_PERCENT_MIN));
|
||||||
|
}
|
||||||
|
|
||||||
|
private float scaleFromInt(int value) {
|
||||||
|
return (float) (value - FONT_PERCENT_MIN) / (FONT_PERCENT_MAX - FONT_PERCENT_MIN);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
Loading…
Reference in New Issue
Block a user