diff --git a/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt b/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt
index 74c14f964a..7a6c60cbf5 100644
--- a/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt
@@ -14,6 +14,7 @@ class HomeActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
routeHome()
}
diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt
index 898ecd1e4d..692b6eb35b 100644
--- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt
@@ -164,6 +164,7 @@ class MainActivity : ComponentActivity() {
private var showPhantomGate by mutableStateOf(false)
private var directAudio by mutableStateOf(false)
private var stretch16x9 by mutableStateOf(false)
+ private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
private var launcherFullscreen by mutableStateOf(true)
private var animationsEnabled by mutableStateOf(true)
private var storeEnabled by mutableStateOf(false)
@@ -534,6 +535,8 @@ class MainActivity : ComponentActivity() {
// Last start's game list, so the Steam wall is up on the first frame; refresh() replaces it.
steamGames = if (shortcutPicker) emptyList() else com.droiddeck.launcher.frontend.LibraryCache.load(this)
backActionsInverted = SessionPrefs.backActionsInverted(this)
+ orientation = SessionPrefs.orientation(this)
+ requestedOrientation = orientation
launcherFullscreen = SessionPrefs.launcherFullscreen(this)
animationsEnabled = SessionPrefs.animationsEnabled(this)
storeEnabled = SessionPrefs.storeEnabled(this)
@@ -591,6 +594,7 @@ class MainActivity : ComponentActivity() {
updates = updates.state(),
phantomProcessStatus = phantomProcessStatus,
showPhantomGate = showPhantomGate,
+ orientation = orientation,
launcherFullscreen = launcherFullscreen,
animationsEnabled = animationsEnabled,
storeEnabled = storeEnabled,
@@ -737,6 +741,11 @@ class MainActivity : ComponentActivity() {
com.droiddeck.launcher.core.AppUiPrefs.setScale(this, percent)
appScale = com.droiddeck.launcher.core.AppUiPrefs.scale(this)
},
+ onOrientation = { value ->
+ SessionPrefs.setOrientation(this, value)
+ orientation = value
+ requestedOrientation = value
+ },
onLauncherFullscreen = { on ->
SessionPrefs.setLauncherFullscreen(this, on)
launcherFullscreen = on
@@ -972,6 +981,8 @@ class MainActivity : ComponentActivity() {
override fun onResume() {
super.onResume()
+ orientation = SessionPrefs.orientation(this)
+ requestedOrientation = orientation
refreshWifiDiscovery()
// Back from a store's sign-in page: the Stores chips show the account at once. A store
// install finishing while this screen is up rebuilds the Games list through the listener.
diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt
index 0e44a1fbf2..19f9f7eacf 100644
--- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt
@@ -320,6 +320,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ requestedOrientation = SessionPrefs.orientation(this)
if (com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isRemoving() ||
com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isMaintaining()) {
runtimeRemovalBlocked = true
@@ -2178,6 +2179,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun onResume() {
super.onResume()
+ requestedOrientation = SessionPrefs.orientation(this)
if (runtimeRemovalBlocked) return
com.droiddeck.launcher.ui.Motion.refresh(this)
refreshHomeApp()
diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentStartActivity.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentStartActivity.kt
index 99a6f784c6..edf38dde68 100644
--- a/app/src/main/java/com/droiddeck/launcher/agent/AgentStartActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentStartActivity.kt
@@ -14,6 +14,7 @@ import org.json.JSONObject
class AgentStartActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
val request = decodeRequest(intent.getStringExtra(EXTRA_REQUEST))
if (request == null) {
finish()
diff --git a/app/src/main/java/com/droiddeck/launcher/files/FileManagerActivity.kt b/app/src/main/java/com/droiddeck/launcher/files/FileManagerActivity.kt
index cc0586d6fe..2395d1c80d 100644
--- a/app/src/main/java/com/droiddeck/launcher/files/FileManagerActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/files/FileManagerActivity.kt
@@ -22,6 +22,7 @@ class FileManagerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1)
}
diff --git a/app/src/main/java/com/droiddeck/launcher/files/FilePickerActivity.kt b/app/src/main/java/com/droiddeck/launcher/files/FilePickerActivity.kt
index 36ec427cf0..8f8782719f 100644
--- a/app/src/main/java/com/droiddeck/launcher/files/FilePickerActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/files/FilePickerActivity.kt
@@ -35,6 +35,7 @@ class FilePickerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
// targetSdk 28: the old storage permission is exactly what lets us list the card.
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1)
diff --git a/app/src/main/java/com/droiddeck/launcher/input/ControllerEditorActivity.kt b/app/src/main/java/com/droiddeck/launcher/input/ControllerEditorActivity.kt
index 2e2f52a3ac..4bd76a4e73 100644
--- a/app/src/main/java/com/droiddeck/launcher/input/ControllerEditorActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/input/ControllerEditorActivity.kt
@@ -47,6 +47,7 @@ class ControllerEditorActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
immersive()
val root = FrameLayout(this)
root.setBackgroundColor(0xFF0B0F14.toInt())
diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt
index c1657830b3..689b59829e 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt
@@ -1,6 +1,7 @@
package com.droiddeck.launcher.session
import android.content.Context
+import android.content.pm.ActivityInfo
import androidx.annotation.StringRes
import com.droiddeck.launcher.R
import com.droiddeck.launcher.core.TextureFiltering
@@ -35,6 +36,22 @@ object SessionPrefs {
private fun prefs(context: Context) = context.getSharedPreferences("session", Context.MODE_PRIVATE)
+ val orientationOptions = listOf(
+ ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE to R.string.setup_orientation_auto,
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE to R.string.setup_orientation_landscape,
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE to R.string.setup_orientation_reverse,
+ )
+
+ fun orientation(context: Context): Int =
+ prefs(context).getInt("orientation", ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
+ .takeIf { value -> orientationOptions.any { it.first == value } }
+ ?: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
+
+ fun setOrientation(context: Context, orientation: Int) {
+ require(orientationOptions.any { it.first == orientation })
+ prefs(context).edit().putInt("orientation", orientation).apply()
+ }
+
/** Whether the launcher hides Android's status and navigation bars. */
fun launcherFullscreen(context: Context): Boolean = prefs(context).getBoolean("launcherFullscreen", true)
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt
index fd80e44c4d..1c2e50dec6 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt
@@ -129,6 +129,7 @@ class FrontEndState(
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE,
val showPhantomGate: Boolean = false,
+ val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
val launcherFullscreen: Boolean = true,
val animationsEnabled: Boolean = true,
/** The Flathub Store, a beta the user turns on in Setup. */
@@ -204,6 +205,7 @@ class FrontEndActions(
val onTheme: (String) -> Unit = {},
val onLanguage: (String) -> Unit = {},
val onAppScale: (Int) -> Unit = {},
+ val onOrientation: (Int) -> Unit = {},
val onLauncherFullscreen: (Boolean) -> Unit = {},
val onAnimationsEnabled: (Boolean) -> Unit = {},
val onStoreEnabled: (Boolean) -> Unit = {},
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt
index 1b9f086f8a..0fd48e36a0 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt
@@ -351,6 +351,11 @@ internal fun SetupPanel(
if (s.homeScreenEnabled) stringResource(R.string.setup_home_on) else stringResource(R.string.setup_home_off),
s.homeScreenEnabled,
) { a.onHomeScreen(it) }
+ ChoiceRow(
+ host, "orientation", stringResource(R.string.setup_orientation), null,
+ SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) },
+ s.orientation, onPick = a.onOrientation,
+ )
ToggleRow(
host, "launcher-fullscreen", stringResource(R.string.setup_fullscreen),
if (s.launcherFullscreen) stringResource(R.string.setup_fullscreen_on) else stringResource(R.string.setup_fullscreen_off),
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index be139954c6..3e098e2a04 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -635,6 +635,10 @@
Use as Home screen
DroidDeck can be the Home app
DroidDeck is never offered as a Home app
+ Orientation
+ Automatic landscape
+ Landscape
+ Reverse landscape
Fullscreen
Hides the Android status and navigation bars
Shows the Android status and navigation bars
diff --git a/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt b/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt
new file mode 100644
index 0000000000..5d67d041a2
--- /dev/null
+++ b/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt
@@ -0,0 +1,44 @@
+package com.droiddeck.launcher.session
+
+import android.content.Context
+import android.content.pm.ActivityInfo
+import org.junit.Assert.*
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.RuntimeEnvironment
+import org.robolectric.annotation.Config
+
+@RunWith(RobolectricTestRunner::class)
+@Config(sdk = [28], manifest = Config.NONE)
+class OrientationTest {
+ private val context get() = RuntimeEnvironment.getApplication()
+
+ @Before fun clearOrientation() {
+ context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
+ }
+
+ @Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
+ 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,
+ )) {
+ SessionPrefs.setOrientation(context, value)
+ assertEquals(value, SessionPrefs.orientation(context.createConfigurationContext(context.resources.configuration)))
+ }
+ }
+
+ @Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
+ val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
+ prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).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)
+ }
+ assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, SessionPrefs.orientation(context))
+ }
+}