From 65ef6fd112a88815942ccba26148f87768427ec2 Mon Sep 17 00:00:00 2001 From: Forrest Guice Date: Fri, 11 Nov 2022 20:45:57 -0700 Subject: [PATCH] text size option adds "text size" app option; "small", "normal", or "large" text (#492, #622); increases the default text size ("normal") by 2sp. --- .../suntimeswidget/settings/AppSettings.java | 90 +++++++++++++++---- app/src/main/res/values/dimens.xml | 30 +++++-- app/src/main/res/values/strings.xml | 20 +++++ app/src/main/res/values/styles.xml | 60 +++++++++++++ .../main/res/xml/preference_userinterface.xml | 7 ++ 5 files changed, 185 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/forrestguice/suntimeswidget/settings/AppSettings.java b/app/src/main/java/com/forrestguice/suntimeswidget/settings/AppSettings.java index c382d42eb..5020b60c9 100644 --- a/app/src/main/java/com/forrestguice/suntimeswidget/settings/AppSettings.java +++ b/app/src/main/java/com/forrestguice/suntimeswidget/settings/AppSettings.java @@ -68,6 +68,9 @@ public class AppSettings public static final String PREF_KEY_APPEARANCE_THEME_DARK = "app_appearance_theme_dark"; public static final String PREF_DEF_APPEARANCE_THEME_DARK = "default"; + public static final String PREF_KEY_APPEARANCE_TEXTSIZE = "app_appearance_textsize"; + public static final TextSize PREF_DEF_APPEARANCE_TEXTSIZE = TextSize.NORMAL; + public static final String PREF_KEY_LOCALE_MODE = "app_locale_mode"; public static final LocaleMode PREF_DEF_LOCALE_MODE = LocaleMode.SYSTEM_LOCALE; @@ -144,6 +147,42 @@ public class AppSettings public static final String PREF_KEY_DIALOG = "dialog"; public static final String PREF_KEY_DIALOG_DONOTSHOWAGAIN = "donotshowagain"; + /** + * Text sizes + */ + public static enum TextSize + { + SMALL("Small"), NORMAL("Normal"), LARGE("Large"); + + private TextSize( String displayString ) { + this.displayString = displayString; + } + + public String getDisplayString() { + return displayString; + } + public void setDisplayString( String displayString ) { + this.displayString = displayString; + } + private String displayString; + + public static void initDisplayStrings( Context context ) + { + SMALL.setDisplayString(context.getString(R.string.textSize_small)); + NORMAL.setDisplayString(context.getString(R.string.textSize_normal)); + LARGE.setDisplayString(context.getString(R.string.textSize_large)); + } + + public static TextSize valueOf(String value, TextSize defaultValue) + { + try { + return TextSize.valueOf(value); + } catch (IllegalArgumentException e) { + return defaultValue; + } + } + } + /** * Language modes (system, user defined) */ @@ -472,7 +511,13 @@ public static String loadNoteTapActionPref( Context context ) public static String loadThemePref(Context context) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); - return pref.getString(PREF_KEY_APPEARANCE_THEME, PREF_DEF_APPEARANCE_THEME); + return pref.getString(PREF_KEY_APPEARANCE_THEME, PREF_DEF_APPEARANCE_THEME) + "_" + loadTextSizePref(context); + } + + public static String loadTextSizePref(Context context) + { + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); + return pref.getString(PREF_KEY_APPEARANCE_TEXTSIZE, PREF_DEF_APPEARANCE_TEXTSIZE.name()); } public static String loadThemeLightPref(Context context) @@ -520,30 +565,43 @@ public static int themePrefToStyleId( Context context, String themeName ) } public static int themePrefToStyleId( Context context, String themeName, SuntimesRiseSetData data ) { - int styleID = R.style.AppTheme_Dark; if (themeName != null) { - //noinspection IfCanBeSwitch - if (themeName.equals(THEME_LIGHT)) - { - styleID = R.style.AppTheme_Light; - - } else if (themeName.equals(THEME_DARK)) { - styleID = R.style.AppTheme_Dark; - - } else if (themeName.equals(THEME_SYSTEM)) { - styleID = R.style.AppTheme_System; - - } else if (themeName.equals(THEME_DAYNIGHT)) { + String[] parts = themeName.split("_"); + TextSize size = TextSize.valueOf((parts.length > 0 ? parts[1] : TextSize.NORMAL.name()), TextSize.NORMAL); + + if (themeName.startsWith(THEME_LIGHT)) { + switch (size) { + case SMALL: return R.style.AppTheme_Light_Small; + case LARGE: return R.style.AppTheme_Light_Large; + case NORMAL: default: return R.style.AppTheme_Light; + } + } else if (themeName.startsWith(THEME_DARK)) { + switch (size) { + case SMALL: return R.style.AppTheme_Dark_Small; + case LARGE: return R.style.AppTheme_Dark_Large; + case NORMAL: default: return R.style.AppTheme_Dark; + } + } else if (themeName.startsWith(THEME_SYSTEM)) { + switch (size) { + case SMALL: return R.style.AppTheme_System_Small; + case LARGE: return R.style.AppTheme_System_Large; + case NORMAL: default: return R.style.AppTheme_System; + } + } else if (themeName.startsWith(THEME_DAYNIGHT)) { if (data == null) { data = new SuntimesRiseSetData(context, AppWidgetManager.INVALID_APPWIDGET_ID); data.initCalculator(context); } - styleID = (data.isDay() ? R.style.AppTheme_Light : R.style.AppTheme_Dark); + switch (size) { + case SMALL: return (data.isDay() ? R.style.AppTheme_Light_Small : R.style.AppTheme_Dark_Small); + case LARGE: return (data.isDay() ? R.style.AppTheme_Light_Large : R.style.AppTheme_Dark_Large); + case NORMAL: default: return (data.isDay() ? R.style.AppTheme_Light : R.style.AppTheme_Dark); + } } } - return styleID; + return R.style.AppTheme; } public static String getThemeOverride(Context context, int appThemeResID) diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 96a6c6140..7c8a7cb1f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,15 +4,33 @@ 8dp 8dp - 6sp - 10sp - 12sp - 14sp - 16sp - 18sp + 6sp + 10sp + 12sp + 14sp + 16sp + 18sp + 36sp + 56sp + + 10sp + 12sp + 14sp + 16sp + 18sp + 20sp 36sp 56sp + 12sp + 14sp + 16sp + 18sp + 20sp + 22sp + 38sp + 58sp + 250 250dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9a9c9e5eb..c7e3871b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1082,6 +1082,25 @@ MODE_24HR + + + Text Size + %s + + Small + Normal + Large + + @string/textSize_small + @string/textSize_normal + @string/textSize_large + + + SMALL + NORMAL + LARGE + + @string/trackingMode_recent @@ -2073,6 +2092,7 @@ false + NORMAL SYSTEM_LOCALE en diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 25b8c45d2..fdea8afc9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -144,6 +144,26 @@ @drawable/ic_action_next_item_ref @drawable/ic_action_previous_item_ref + + + + + +