Files
goon-game/app/src/main/java/com/projectsacrifice/game/AccessibilitySettings.java
T

86 lines
2.7 KiB
Java

package com.projectsacrifice.game;
public final class AccessibilitySettings {
private enum TextSize {
STANDARD("Standard", 1f),
LARGE("Large", 1.25f);
final String label;
final float scale;
TextSize(String label, float scale) {
this.label = label;
this.scale = scale;
}
}
private final TextSize textSize;
private final boolean highContrastEnabled;
private final boolean reducedMotionEnabled;
private AccessibilitySettings(TextSize textSize, boolean highContrastEnabled,
boolean reducedMotionEnabled) {
this.textSize = textSize;
this.highContrastEnabled = highContrastEnabled;
this.reducedMotionEnabled = reducedMotionEnabled;
}
public static AccessibilitySettings defaults() {
return new AccessibilitySettings(TextSize.STANDARD, false, false);
}
static AccessibilitySettings restore(int textSizeIndex, boolean highContrastEnabled) {
return restore(textSizeIndex, highContrastEnabled, false);
}
static AccessibilitySettings restore(int textSizeIndex, boolean highContrastEnabled,
boolean reducedMotionEnabled) {
TextSize[] values = TextSize.values();
TextSize restored = textSizeIndex >= 0 && textSizeIndex < values.length
? values[textSizeIndex] : TextSize.STANDARD;
return new AccessibilitySettings(restored, highContrastEnabled, reducedMotionEnabled);
}
public String textSizeLabel() {
return textSize.label;
}
public float textScale() {
return textSize.scale;
}
public float canvasTextSize(float baseSize) {
return baseSize * textSize.scale;
}
public AccessibilitySettings nextTextSize() {
TextSize[] values = TextSize.values();
return new AccessibilitySettings(values[(textSize.ordinal() + 1) % values.length],
highContrastEnabled, reducedMotionEnabled);
}
public boolean highContrastEnabled() {
return highContrastEnabled;
}
public String highContrastLabel() {
return highContrastEnabled ? "On" : "Off";
}
public AccessibilitySettings toggleHighContrast() {
return new AccessibilitySettings(textSize, !highContrastEnabled, reducedMotionEnabled);
}
public boolean reducedMotionEnabled() { return reducedMotionEnabled; }
public String reducedMotionLabel() { return reducedMotionEnabled ? "On" : "Off"; }
public AccessibilitySettings toggleReducedMotion() {
return new AccessibilitySettings(textSize, highContrastEnabled, !reducedMotionEnabled);
}
int textSizeIndex() {
return textSize.ordinal();
}
}