Skip to content

Commit

Permalink
text size option
Browse files Browse the repository at this point in the history
adds "text size" app option; "small", "normal", or "large" text (#492, #622); increases the default text size ("normal") by 2sp.
  • Loading branch information
forrestguice committed Nov 12, 2022
1 parent b27d335 commit 65ef6fd
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 24 additions & 6 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@
<dimen name="activity_margin">8dp</dimen>
<dimen name="dialog_margin">8dp</dimen>

<dimen name="text_size_tiny">6sp</dimen>
<dimen name="text_size_xsmall">10sp</dimen>
<dimen name="text_size_small">12sp</dimen>
<dimen name="text_size_medium">14sp</dimen>
<dimen name="text_size_large">16sp</dimen>
<dimen name="text_size_xlarge">18sp</dimen>
<dimen name="smalltext_size_tiny">6sp</dimen> <!-- "small" sizes -->
<dimen name="smalltext_size_xsmall">10sp</dimen>
<dimen name="smalltext_size_small">12sp</dimen>
<dimen name="smalltext_size_medium">14sp</dimen>
<dimen name="smalltext_size_large">16sp</dimen>
<dimen name="smalltext_size_xlarge">18sp</dimen>
<dimen name="smalltext_size_huge">36sp</dimen>
<dimen name="smalltext_size_enormous">56sp</dimen>

<dimen name="text_size_tiny">10sp</dimen> <!-- "normal" sizes -->
<dimen name="text_size_xsmall">12sp</dimen>
<dimen name="text_size_small">14sp</dimen>
<dimen name="text_size_medium">16sp</dimen>
<dimen name="text_size_large">18sp</dimen>
<dimen name="text_size_xlarge">20sp</dimen>
<dimen name="text_size_huge">36sp</dimen>
<dimen name="text_size_enormous">56sp</dimen>

<dimen name="largetext_size_tiny">12sp</dimen> <!-- "large" sizes -->
<dimen name="largetext_size_xsmall">14sp</dimen>
<dimen name="largetext_size_small">16sp</dimen>
<dimen name="largetext_size_medium">18sp</dimen>
<dimen name="largetext_size_large">20sp</dimen>
<dimen name="largetext_size_xlarge">22sp</dimen>
<dimen name="largetext_size_huge">38sp</dimen>
<dimen name="largetext_size_enormous">58sp</dimen>

<integer name="widget_size_minWidthDp4x1">250</integer>
<dimen name="widget_size_minWidth4x1">250dp</dimen>

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,25 @@
<item>MODE_24HR</item>
</string-array>

<!-- App Setting: text size -->

<string name="configLabel_ui_textsize">Text Size</string> <!-- TODO -->
<string name="configLabel_ui_textsize_summary">%s</string> <!-- TODO -->

<string name="textSize_small">Small</string> <!-- TODO -->
<string name="textSize_normal">Normal</string> <!-- TODO -->
<string name="textSize_large">Large</string> <!-- TODO -->
<string-array name="textSize_display"> <!-- one-to-one with textSize_values -->
<item>@string/textSize_small</item>
<item>@string/textSize_normal</item>
<item>@string/textSize_large</item>
</string-array>
<string-array name="textSize_values" translatable="false"> <!-- one-to-one with textSize_display -->
<item>SMALL</item>
<item>NORMAL</item>
<item>LARGE</item>
</string-array>

<!-- App Setting: solstice tracking mode -->
<string-array name="solsticeTrackingMode_display"> <!-- one-to-one with solsticeTrackingMode_values -->
<item>@string/trackingMode_recent</item>
Expand Down Expand Up @@ -2073,6 +2092,7 @@

<string name="def_app_plugins_enabled" translatable="false">false</string>

<string name="def_app_appearance_textsize" translatable="false">NORMAL</string>
<string name="def_app_locale_mode" translatable="false">SYSTEM_LOCALE</string>
<string name="def_app_locale" translatable="false">en</string>

Expand Down
60 changes: 60 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@
<item name="icActionNext">@drawable/ic_action_next_item_ref</item>
<item name="icActionPrevious">@drawable/ic_action_previous_item_ref</item>
</style>
<style name="AppTheme.System.Small" parent="AppTheme.System">
<item name="text_size_tiny">@dimen/smalltext_size_tiny</item>
<item name="text_size_xsmall">@dimen/smalltext_size_xsmall</item>
<item name="text_size_small">@dimen/smalltext_size_small</item>
<item name="text_size_medium">@dimen/smalltext_size_medium</item>
<item name="text_size_large">@dimen/smalltext_size_large</item>
<item name="text_size_xlarge">@dimen/smalltext_size_xlarge</item>
<item name="text_size_huge">@dimen/smalltext_size_huge</item>
<item name="text_size_enormous">@dimen/smalltext_size_enormous</item>
</style>
<style name="AppTheme.System.Large" parent="AppTheme.System">
<item name="text_size_tiny">@dimen/largetext_size_tiny</item>
<item name="text_size_xsmall">@dimen/largetext_size_xsmall</item>
<item name="text_size_small">@dimen/largetext_size_small</item>
<item name="text_size_medium">@dimen/largetext_size_medium</item>
<item name="text_size_large">@dimen/largetext_size_large</item>
<item name="text_size_xlarge">@dimen/largetext_size_xlarge</item>
<item name="text_size_huge">@dimen/largetext_size_huge</item>
<item name="text_size_enormous">@dimen/largetext_size_enormous</item>
</style>

<!-- Theme: Light (left-to-right) -->
<style name="AppThemeBase.Light" parent="Theme.AppCompat.Light.NoActionBar">
Expand Down Expand Up @@ -286,6 +306,26 @@
<item name="icActionNext">@drawable/ic_action_next_item_light</item>
<item name="icActionPrevious">@drawable/ic_action_previous_item_light</item>
</style>
<style name="AppTheme.Light.Small" parent="AppTheme.Light">
<item name="text_size_tiny">@dimen/smalltext_size_tiny</item>
<item name="text_size_xsmall">@dimen/smalltext_size_xsmall</item>
<item name="text_size_small">@dimen/smalltext_size_small</item>
<item name="text_size_medium">@dimen/smalltext_size_medium</item>
<item name="text_size_large">@dimen/smalltext_size_large</item>
<item name="text_size_xlarge">@dimen/smalltext_size_xlarge</item>
<item name="text_size_huge">@dimen/smalltext_size_huge</item>
<item name="text_size_enormous">@dimen/smalltext_size_enormous</item>
</style>
<style name="AppTheme.Light.Large" parent="AppTheme.Light">
<item name="text_size_tiny">@dimen/largetext_size_tiny</item>
<item name="text_size_xsmall">@dimen/largetext_size_xsmall</item>
<item name="text_size_small">@dimen/largetext_size_small</item>
<item name="text_size_medium">@dimen/largetext_size_medium</item>
<item name="text_size_large">@dimen/largetext_size_large</item>
<item name="text_size_xlarge">@dimen/largetext_size_xlarge</item>
<item name="text_size_huge">@dimen/largetext_size_huge</item>
<item name="text_size_enormous">@dimen/largetext_size_enormous</item>
</style>

<!-- Theme: Dark (left-to-right) -->
<style name="AppThemeBase.Dark" parent="Theme.AppCompat.NoActionBar">
Expand Down Expand Up @@ -428,6 +468,26 @@
<item name="icActionNext">@drawable/ic_action_next_item</item>
<item name="icActionPrevious">@drawable/ic_action_previous_item</item>
</style>
<style name="AppTheme.Dark.Small" parent="AppTheme.Dark">
<item name="text_size_tiny">@dimen/smalltext_size_tiny</item>
<item name="text_size_xsmall">@dimen/smalltext_size_xsmall</item>
<item name="text_size_small">@dimen/smalltext_size_small</item>
<item name="text_size_medium">@dimen/smalltext_size_medium</item>
<item name="text_size_large">@dimen/smalltext_size_large</item>
<item name="text_size_xlarge">@dimen/smalltext_size_xlarge</item>
<item name="text_size_huge">@dimen/smalltext_size_huge</item>
<item name="text_size_enormous">@dimen/smalltext_size_enormous</item>
</style>
<style name="AppTheme.Dark.Large" parent="AppTheme.Dark">
<item name="text_size_tiny">@dimen/largetext_size_tiny</item>
<item name="text_size_xsmall">@dimen/largetext_size_xsmall</item>
<item name="text_size_small">@dimen/largetext_size_small</item>
<item name="text_size_medium">@dimen/largetext_size_medium</item>
<item name="text_size_large">@dimen/largetext_size_large</item>
<item name="text_size_xlarge">@dimen/largetext_size_xlarge</item>
<item name="text_size_huge">@dimen/largetext_size_huge</item>
<item name="text_size_enormous">@dimen/largetext_size_enormous</item>
</style>

<style name="ThemeOverlay.Suntimes.BottomSheetDialog" parent="ThemeOverlay.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preference_userinterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
android:widgetLayout="@layout/layout_pref_themewidget"
android:summary="%s" />

<com.forrestguice.suntimeswidget.settings.ListPreference
android:key="app_appearance_textsize"
android:title="@string/configLabel_ui_textsize"
android:summary="@string/configLabel_ui_textsize_summary"
android:entries="@array/textSize_display" android:entryValues="@array/textSize_values"
android:defaultValue="@string/def_app_appearance_textsize" />

</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 65ef6fd

Please sign in to comment.