Use seekbar for font setting

pull/511/head^2
Alex Baker 8 years ago
parent 726342b292
commit 41c2c9c0e8

@ -26,7 +26,9 @@ public class AppearancePreferences extends InjectingPreferenceActivity implement
private static final int REQUEST_CUSTOMIZE = 1004;
private static final int REQUEST_DEFAULT_LIST = 1005;
private static final int REQUEST_ROW_PADDING = 1006;
private static final int REQUEST_FONT_SIZE = 1007;
private static final String FRAG_TAG_ROW_PADDING_SEEKBAR = "frag_tag_row_padding_seekbar";
private static final String FRAG_TAG_FONT_SIZE_SEEKBAR = "frag_tag_font_size_seekbar";
private static final String EXTRA_BUNDLE = "extra_bundle";
public static final String EXTRA_RESTART = "extra_restart";
@ -51,6 +53,7 @@ public class AppearancePreferences extends InjectingPreferenceActivity implement
addPreferencesFromResource(R.xml.preferences_appearance);
setExtraOnChange(R.string.p_fontSize, EXTRA_RESTART);
setExtraOnChange(R.string.p_rowPadding, EXTRA_RESTART);
setExtraOnChange(R.string.p_fullTaskTitle, EXTRA_RESTART);
setExtraOnChange(R.string.p_show_today_filter, EXTRA_FILTERS_CHANGED);
setExtraOnChange(R.string.p_show_recently_modified_filter, EXTRA_FILTERS_CHANGED);
@ -59,6 +62,14 @@ public class AppearancePreferences extends InjectingPreferenceActivity implement
startActivityForResult(new Intent(AppearancePreferences.this, BeastModePreferences.class), REQUEST_CUSTOMIZE);
return true;
});
findPreference(R.string.p_fontSize).setOnPreferenceClickListener(preference -> {
newSeekBarDialog(R.layout.dialog_font_size_seekbar, 10, 48, preferences.getFontSize(), REQUEST_FONT_SIZE)
.show(getFragmentManager(), FRAG_TAG_FONT_SIZE_SEEKBAR);
return false;
});
updateFontSize();
findPreference(R.string.p_rowPadding).setOnPreferenceClickListener(preference -> {
newSeekBarDialog(R.layout.dialog_font_size_seekbar, 0, 16, preferences.getRowPadding(), REQUEST_ROW_PADDING)
.show(getFragmentManager(), FRAG_TAG_ROW_PADDING_SEEKBAR);
@ -124,11 +135,24 @@ public class AppearancePreferences extends InjectingPreferenceActivity implement
@Override
public void valueSelected(int value, int requestCode) {
int resId = 0;
if (requestCode == REQUEST_ROW_PADDING) {
preferences.setInt(R.string.p_rowPadding, value);
result.putBoolean(EXTRA_RESTART, true);
updateRowPadding();
resId = R.string.p_rowPadding;
} else if (requestCode == REQUEST_FONT_SIZE) {
preferences.setInt(R.string.p_fontSize, value);
updateFontSize();
resId = R.string.p_fontSize;
}
if (resId > 0) {
result.putBoolean(EXTRA_RESTART, true);
tracker.reportEvent(Tracking.Events.SET_PREFERENCE, resId, Integer.toString(value));
}
}
private void updateFontSize() {
findPreference(R.string.p_fontSize).setSummary(locale.formatNumber(preferences.getFontSize()));
}
private void updateRowPadding() {

@ -153,6 +153,10 @@ public class Preferences {
return getInt(R.string.p_rowPadding, 16);
}
public int getFontSize() {
return getInt(R.string.p_fontSize, 16);
}
public int getIntegerFromString(int keyResource, int defaultValue) {
Resources r = context.getResources();
String value = prefs.getString(r.getString(keyResource), null);

@ -52,7 +52,7 @@ public class ViewHolderFactory {
background = getResourceId(context, R.attr.selectableItemBackground);
selectedColor = getData(context, R.attr.colorControlHighlight);
showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false);
fontSize = preferences.getIntegerFromString(R.string.p_fontSize, 16);
fontSize = preferences.getFontSize();
metrics = context.getResources().getDisplayMetrics();
rowPadding = convertDpToPixels(metrics, preferences.getInt(R.string.p_rowPadding, 16));
}

@ -88,29 +88,11 @@
<!-- ======================================================= APPEARANCE == -->
<string name="p_fontSize">font_size</string>
<string name="p_fontSize">font_size_v2</string>
<string name="p_rowPadding">row_padding</string>
<string name="p_voiceRemindersEnabled">voiceRemindersEnabled</string>
<string-array name="EPr_font_size">
<!-- font_size: options for preference menu -->
<item>10</item>
<item>12</item>
<item>14</item>
<item>16</item>
<item>18</item>
<item>20</item>
<item>22</item>
<item>24</item>
<item>26</item>
<item>28</item>
<item>30</item>
<item>32</item>
<item>36</item>
<item>48</item>
</string-array>
<string name="p_fullTaskTitle">fullTaskTitle</string>
<!-- ========================================================= DEFAULTS == -->

@ -8,10 +8,8 @@
android:key="@string/p_default_list"
android:title="@string/default_list" />
<com.todoroo.astrid.ui.MultilineListPreference
<Preference
android:defaultValue="16"
android:entries="@array/EPr_font_size"
android:entryValues="@array/EPr_font_size"
android:key="@string/p_fontSize"
android:title="@string/font_size" />

Loading…
Cancel
Save