feat(accessibility): add display setting to make app's text size bigger

This commit is contained in:
LucasGGamerM
2025-03-10 12:10:33 -03:00
parent b52f1c156d
commit a03297313a
4 changed files with 39 additions and 2 deletions

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -47,7 +47,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment<Void>{
private CheckableListItem<Void> pronounsInUserListingsItem, pronounsInTimelinesItem, pronounsInThreadsItem;
// MOSHIDON
private CheckableListItem<Void> enableDoubleTapToSwipeItem, relocatePublishButtonItem, showPostDividersItem, enableDoubleTapToSearchItem, showMediaPreviewItem;
private CheckableListItem<Void> enableDoubleTapToSwipeItem, relocatePublishButtonItem, showPostDividersItem, enableDoubleTapToSearchItem, showMediaPreviewItem, enhanceTextSizeItem;
private AccountLocalPreferences lp;
@@ -62,6 +62,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment<Void>{
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<Void>{
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<Void>{
maybeApplyNewThemeRightNow(null, null, prev);
}
private void onEnhanceTextSizeClick(){
toggleCheckableItem(enhanceTextSizeItem);
restartActivityToApplyNewTheme();
}
private void onAppearanceClick(ListItem<?> item_){
int selected=switch(GlobalUserPreferences.theme){
case LIGHT -> 0;

View File

@@ -120,6 +120,8 @@
<string name="mo_settings_unifiedpush_warning_disabled">UnifiedPush is not enabled. You will not receive any notifications.</string>
<string name="mo_settings_unifiedpush_enable">Enable</string>
<string name="mo_settings_remove_tracking_params">Private Links</string>
<string name="mo_settings_enhance_text_size">Enhance text size</string>
<string name="mo_settings_enhance_text_size_summary">Makes the app\'s text bigger</string>
<!-- Temporary Strings. They exist in strings_sk.xml, but are not available on Megalodon's weblate-->
<string name="mo_muted_accounts">Muted accounts</string>