From a03297313aa6fe2a41b49782e412455e5686e091 Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Mon, 10 Mar 2025 12:10:33 -0300 Subject: [PATCH] feat(accessibility): add display setting to make app's text size bigger --- .../android/GlobalUserPreferences.java | 4 ++- .../joinmastodon/android/MainActivity.java | 26 +++++++++++++++++++ .../settings/SettingsDisplayFragment.java | 9 ++++++- mastodon/src/main/res/values/strings_mo.xml | 2 ++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 228b02286..87ef1a0dc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -81,6 +81,7 @@ public class GlobalUserPreferences{ public static boolean showPostsWithoutAlt; public static boolean showMediaPreview; public static boolean removeTrackingParams; + public static boolean enhanceTextSize; public static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); @@ -162,10 +163,10 @@ public class GlobalUserPreferences{ showPostsWithoutAlt=prefs.getBoolean("showPostsWithoutAlt", true); showMediaPreview=prefs.getBoolean("showMediaPreview", true); removeTrackingParams=prefs.getBoolean("removeTrackingParams", true); + enhanceTextSize=prefs.getBoolean("enhanceTextSize", false); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; - if (prefs.contains("prefixRepliesWithRe")) { prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false) ? PrefixRepliesMode.TO_OTHERS : PrefixRepliesMode.NEVER; @@ -237,6 +238,7 @@ public class GlobalUserPreferences{ .putBoolean("showPostsWithoutAlt", showPostsWithoutAlt) .putBoolean("showMediaPreview", showMediaPreview) .putBoolean("removeTrackingParams", removeTrackingParams) + .putBoolean("enhanceTextSize", enhanceTextSize) .apply(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index 977c8408b..18ba56905 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -7,8 +7,10 @@ import android.Manifest; import android.app.Activity; import android.app.Fragment; import android.app.assist.AssistContent; +import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.graphics.Bitmap; import android.net.Uri; import android.net.Uri; @@ -16,7 +18,9 @@ import android.os.BadParcelableException; import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; +import android.util.DisplayMetrics; import android.util.Log; +import android.util.TypedValue; import android.view.View; import android.widget.FrameLayout; import android.widget.Toast; @@ -338,4 +342,26 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis } } } + + @Override + protected void attachBaseContext(Context base) { + if (!GlobalUserPreferences.enhanceTextSize) { + super.attachBaseContext(base); + return; + } + + final Configuration override = new Configuration(base.getResources().getConfiguration()); + // How much we change the app's density; + final int densityDelta = 100; + + // TODO: FIXME: whenever we apply our custom scaling, the switches in the settings appear stretched. I don't know why, but it is what it is. + override.screenWidthDp = Math.round(override.densityDpi*((float) override.screenWidthDp/(override.densityDpi+densityDelta))); + override.screenHeightDp = Math.round(override.densityDpi*((float) override.screenHeightDp/(override.densityDpi+densityDelta))); + override.smallestScreenWidthDp = Math.round(override.densityDpi*((float) override.smallestScreenWidthDp/(override.densityDpi+densityDelta))); + + override.densityDpi = override.densityDpi+densityDelta; + final Context newBase = base.createConfigurationContext(override); + + super.attachBaseContext(newBase); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java index 9e675ee8c..46c638844 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java @@ -47,7 +47,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ private CheckableListItem pronounsInUserListingsItem, pronounsInTimelinesItem, pronounsInThreadsItem; // MOSHIDON - private CheckableListItem enableDoubleTapToSwipeItem, relocatePublishButtonItem, showPostDividersItem, enableDoubleTapToSearchItem, showMediaPreviewItem; + private CheckableListItem enableDoubleTapToSwipeItem, relocatePublishButtonItem, showPostDividersItem, enableDoubleTapToSearchItem, showMediaPreviewItem, enhanceTextSizeItem; private AccountLocalPreferences lp; @@ -62,6 +62,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ colorItem=new ListItem<>(getString(R.string.sk_settings_color_palette), getColorPaletteValue(), R.drawable.ic_fluent_color_24_regular, this::onColorClick), trueBlackModeItem=new CheckableListItem<>(R.string.sk_settings_true_black, R.string.mo_setting_true_black_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.trueBlackTheme, R.drawable.ic_fluent_dark_theme_24_regular, i->onTrueBlackModeClick(), true), publishTextItem=new ListItem<>(getString(R.string.sk_settings_publish_button_text), getPublishButtonText(), R.drawable.ic_fluent_send_24_regular, this::onPublishTextClick), + enhanceTextSizeItem=new CheckableListItem<>(R.string.mo_settings_enhance_text_size, R.string.mo_settings_enhance_text_size_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.enhanceTextSize, R.drawable.ic_fluent_text_more_24_regular, i->onEnhanceTextSizeClick()), autoRevealCWsItem=new ListItem<>(R.string.sk_settings_auto_reveal_equal_spoilers, getAutoRevealSpoilersText(), R.drawable.ic_fluent_eye_24_regular, this::onAutoRevealSpoilersClick), relocatePublishButtonItem=new CheckableListItem<>(R.string.mo_relocate_publish_button, R.string.mo_setting_relocate_publish_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.relocatePublishButton, R.drawable.ic_fluent_arrow_autofit_down_24_regular, i->toggleCheckableItem(relocatePublishButtonItem)), revealCWsItem=new CheckableListItem<>(R.string.sk_settings_always_reveal_content_warnings, 0, CheckableListItem.Style.SWITCH, lp.revealCWs, R.drawable.ic_fluent_chat_warning_24_regular, i->toggleCheckableItem(revealCWsItem)), @@ -141,6 +142,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ GlobalUserPreferences.displayPronounsInThreads=pronounsInThreadsItem.checked; GlobalUserPreferences.displayPronounsInUserListings=pronounsInUserListingsItem.checked; GlobalUserPreferences.showMediaPreview=showMediaPreviewItem.checked; + GlobalUserPreferences.enhanceTextSize=enhanceTextSizeItem.checked; GlobalUserPreferences.save(); if(restartPlease) restartActivityToApplyNewTheme(); else E.post(new StatusDisplaySettingsChangedEvent(accountID)); @@ -182,6 +184,11 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ maybeApplyNewThemeRightNow(null, null, prev); } + private void onEnhanceTextSizeClick(){ + toggleCheckableItem(enhanceTextSizeItem); + restartActivityToApplyNewTheme(); + } + private void onAppearanceClick(ListItem item_){ int selected=switch(GlobalUserPreferences.theme){ case LIGHT -> 0; diff --git a/mastodon/src/main/res/values/strings_mo.xml b/mastodon/src/main/res/values/strings_mo.xml index 4881f8d06..c490abb98 100644 --- a/mastodon/src/main/res/values/strings_mo.xml +++ b/mastodon/src/main/res/values/strings_mo.xml @@ -120,6 +120,8 @@ UnifiedPush is not enabled. You will not receive any notifications. Enable Private Links + Enhance text size + Makes the app\'s text bigger Muted accounts