feat(session): add portrait sessions and controls below the game (#1612)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-26 12:01:44 -04:00
1 parent d65912f0c5
commit eaaecf0661
16 files changed
+359 -91

No files matched your search

@@ -21,13 +21,9 @@ class OrientationTest {
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
@Test fun sessionChoicesPersistGloballyWithLandscapeAsTheDefault() {
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
for (value in listOf(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
)) {
for ((value, _) in SessionPrefs.orientationOptions) {
SessionPrefs.setOrientation(context, value)
assertEquals(value, SessionPrefs.orientation(context.createConfigurationContext(context.resources.configuration)))
}
@@ -35,11 +31,11 @@ class OrientationTest {
@Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit()
prefs.edit().putInt("orientation", 999).commit()
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
assertThrows(IllegalArgumentException::class.java) {
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
SessionPrefs.setOrientation(context, 999)
}
assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, SessionPrefs.orientation(context))
}
@@ -54,6 +50,34 @@ class OrientationTest {
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, AppUiPrefs.orientation(context))
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, AppUiPrefs.orientation(context))
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, SessionPrefs.orientation(context))
}
@Test fun explicitOrientationTakesPriorityOverLargeFollowScreenWindows() {
assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, SessionPrefs.windowOrientation(context, true, 700))
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.windowOrientation(context, true, 400))
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.windowOrientation(context, false, 700))
for ((value, _) in SessionPrefs.orientationOptions) {
SessionPrefs.setOrientation(context, value)
assertEquals(value, SessionPrefs.windowOrientation(context, true, 700))
}
}
@Test fun sessionPortraitUsesItsOwnLockOrTheCurrentRotation() {
val config = android.content.res.Configuration(context.resources.configuration)
config.orientation = android.content.res.Configuration.ORIENTATION_PORTRAIT
val portrait = context.createConfigurationContext(config)
config.orientation = android.content.res.Configuration.ORIENTATION_LANDSCAPE
val landscape = context.createConfigurationContext(config)
assertFalse(SessionPrefs.portrait(portrait))
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
assertTrue(SessionPrefs.portrait(landscape))
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_USER)
assertTrue(SessionPrefs.portrait(portrait))
assertFalse(SessionPrefs.portrait(landscape))
}
@Test fun invalidLauncherOrientationFallsBackAndInvalidChoicePreservesPreference() {
@@ -4,6 +4,23 @@ import org.junit.Assert.*
import org.junit.Test
class SessionDisplayTest {
@Test fun portraitPresetsSwapTheOutputAndRetainTheResolutionCap() {
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "720p", portrait = true))
assertEquals(900 to 1600, SessionDisplay.resolveChoice(1080 to 1920, "900p", portrait = true))
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1440 to 1080, "720p", portrait = true))
assertEquals(720 to 1600, SessionDisplay.resolveChoice(2400 to 1080, "720p", portrait = true))
assertEquals(1080 to 1920, SessionDisplay.resolveChoice(1921 to 1081, SessionDisplay.MATCH_SCREEN, portrait = true))
assertEquals(1080 to 2400, SessionDisplay.resolveChoice(2400 to 1080, SessionDisplay.FOLLOW_SCREEN, portrait = true))
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "invalid", portrait = true))
}
@Test fun customDimensionsStayExplicitInEitherOrientation() {
for (portrait in listOf(false, true)) {
assertEquals(1280 to 720, SessionDisplay.resolveChoice(1920 to 1080, "1280x720", portrait))
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "720x1280", portrait))
}
}
@Test fun fixedSizesAndMatchScreenResolveWithoutAnyAspectSetting() {
assertEquals(1280 to 720, SessionDisplay.resolveChoice(1440 to 1080, "1280x720"))
assertEquals(1600 to 900, SessionDisplay.resolveChoice(1280 to 720, "1600x900"))
@@ -35,6 +52,7 @@ class SessionDisplayTest {
}
@Test fun unfoldedControlsKeepTheGameSixteenByNineAcrossTheWidth() {
assertEquals(606, SessionDisplay.unfoldedGameHeight(1080, 1920))
assertEquals(1376, SessionDisplay.unfoldedGameHeight(2448, 1848))
assertEquals(1038, SessionDisplay.unfoldedGameHeight(1848, 2448))
assertEquals(864, SessionDisplay.unfoldedGameHeight(1920, 1080))
@@ -67,6 +85,18 @@ class SessionDisplayTest {
assertFalse(SessionDisplay.unfoldedControlsWanted(true, true, true, true, true, false, 0, 1848, 700))
}
@Test fun portraitControlsWorkOnHandheldsAndPhonesWithoutAHinge() {
fun wanted(width: Int = 1080, height: Int = 1920, controller: Boolean = false,
keep: Boolean = false, pad: Boolean = true, pip: Boolean = false) =
SessionDisplay.unfoldedControlsWanted(true, false, controller, keep, pad, pip, width, height, 393)
assertTrue(wanted())
assertFalse(wanted(width = 1920, height = 1080))
assertFalse(wanted(controller = true))
assertTrue(wanted(controller = true, keep = true))
assertFalse(wanted(pad = false))
assertFalse(wanted(pip = true))
}
@Test fun followScreenKeepsTheWindowShapeAndSkipsTinyWindows() {
assertEquals(2520 to 1080, SessionDisplay.resolveChoice(1080 to 2520, SessionDisplay.FOLLOW_SCREEN))
@@ -75,6 +105,13 @@ class SessionDisplayTest {
assertNull(SessionDisplay.followSize(640, 360))
}
@Test fun aPhoneCanFollowTheShortGameAreaAboveItsControls() {
assertNull(SessionDisplay.followSize(720, 404))
assertEquals(720 to 404, SessionDisplay.followSize(720, 404, controlsBelow = true))
assertNull(SessionDisplay.followSize(320, 180, controlsBelow = true))
assertNull(SessionDisplay.followSize(720, 0, controlsBelow = true))
}
@Test fun resolutionCapsPreserveTheSelectedShapeWithoutExceedingPanelHeight() {
assertEquals(1280 to 720, SessionDisplay.resolve(1920 to 1080, 720, SessionPrefs.SHAPE_AUTO))
assertEquals(960 to 720, SessionDisplay.resolve(1440 to 1080, 720, SessionPrefs.SHAPE_EXACT))
@@ -13,6 +13,16 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class SessionScalingPrefsTest {
@Test fun legacyAutomaticResolutionsRemainRotatablePresets() {
val context = RuntimeEnvironment.getApplication()
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
prefs.edit().putString("shape", SessionPrefs.SHAPE_AUTO).putInt("resolutionCap.steam", 900).commit()
assertEquals("900p", SessionPrefs.resolutionChoice(context, "steam", 1920 to 1080))
val desktop = SessionPrefs.resolutionChoice(context, "lxqt", 1920 to 1080)
assertEquals("720p", desktop)
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, desktop, portrait = true))
}
@Before fun clearSettings() {
RuntimeEnvironment.getApplication().getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}