From d1756eb9b085f843700e672a05a59251dfa8f6c8 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sat, 15 Jun 2024 22:18:30 +0200 Subject: [PATCH] termux-app: Make font size setting be per display By @babaric-dev in https://github.com/termux/termux-app/pull/3208 --- .../java/com/termux/app/TermuxPreferences.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/termux-app/src/main/java/com/termux/app/TermuxPreferences.java b/termux-app/src/main/java/com/termux/app/TermuxPreferences.java index eca4832b..d1ecdee4 100644 --- a/termux-app/src/main/java/com/termux/app/TermuxPreferences.java +++ b/termux-app/src/main/java/com/termux/app/TermuxPreferences.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.util.TypedValue; +import android.view.Display; public class TermuxPreferences { @@ -18,9 +19,11 @@ public class TermuxPreferences { private final SharedPreferences prefs; + private final Context context; TermuxPreferences(TermuxActivity activity) { prefs = activity.getPreferences(Context.MODE_PRIVATE); + context = activity; setupFontSizeDefaults(activity); } @@ -64,8 +67,17 @@ public boolean toggleShowTerminalToolbar() { return newValue; } + /** + * Use different font sizes on different displays. + */ + private String fontSizePrefName() { + var display = context.getDisplay(); + var displayId = (display == null) ? Display.DEFAULT_DISPLAY : display.getDisplayId(); + return PREF_FONT_SIZE + ((displayId == Display.DEFAULT_DISPLAY) ? "" : Integer.toString(displayId)); + } + public int getFontSize() { - return prefs.getInt(PREF_FONT_SIZE, defaultFontSize); + return prefs.getInt(fontSizePrefName(), defaultFontSize); } public int changeFontSize(boolean increase) { @@ -74,7 +86,7 @@ public int changeFontSize(boolean increase) { fontSize += (increase ? 1 : -1) * 2; fontSize = Math.max(minFontSize, Math.min(fontSize, maxFontSize)); - prefs.edit().putInt(PREF_FONT_SIZE, fontSize).apply(); + prefs.edit().putInt(fontSizePrefName(), fontSize).apply(); return fontSize; }