Skip to content

Commit

Permalink
termux-app: Make font size setting be per display
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Jun 16, 2024
1 parent 835f45a commit d1756eb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions termux-app/src/main/java/com/termux/app/TermuxPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.util.TypedValue;
import android.view.Display;

public class TermuxPreferences {

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

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit d1756eb

Please sign in to comment.