VERY experimental Nintendo Switch 2 emulator
C++
android: Add support for split foldable view
Abandoned Cartfa02375617cb
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.ktindex 1382ae29f8..901a3978d8 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt@@ -26,6 +26,12 @@ import androidx.core.content.getSystemServiceimport androidx.core.view.WindowCompatimport androidx.core.view.WindowInsetsCompatimport androidx.core.view.WindowInsetsControllerCompat+import androidx.lifecycle.Lifecycle+import androidx.lifecycle.lifecycleScope+import androidx.lifecycle.repeatOnLifecycle+import androidx.window.layout.WindowInfoTracker+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launchimport org.yuzu.yuzu_emu.NativeLibraryimport org.yuzu.yuzu_emu.Rimport org.yuzu.yuzu_emu.fragments.EmulationFragment@@ -96,6 +102,14 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {inputHandler = InputHandler()inputHandler.initialize()+ lifecycleScope.launch(Dispatchers.Main) {+ lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {+ WindowInfoTracker.getOrCreate(this@EmulationActivity)+ .windowLayoutInfo(this@EmulationActivity)+ .collect { emulationFragment?.updateCurrentLayout(this@EmulationActivity, it) }+ }+ }+// Start a foreground service to prevent the app from getting killed in the backgroundval startIntent = Intent(this, ForegroundService::class.java)startForegroundService(startIntent)diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.ktindex e00f02f86d..1a9843fcc0 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt@@ -8,10 +8,13 @@ import android.app.AlertDialogimport android.content.Contextimport android.content.DialogInterfaceimport android.content.SharedPreferences+import android.content.pm.ActivityInfo+import android.content.res.Resourcesimport android.graphics.Colorimport android.os.Bundleimport android.os.Handlerimport android.os.Looper+import android.util.TypedValueimport android.view.*import android.widget.TextViewimport androidx.activity.OnBackPressedCallback@@ -20,8 +23,11 @@ import androidx.core.content.res.ResourcesCompatimport androidx.core.graphics.Insetsimport androidx.core.view.ViewCompatimport androidx.core.view.WindowInsetsCompat+import androidx.core.view.updatePaddingimport androidx.fragment.app.Fragmentimport androidx.preference.PreferenceManager+import androidx.window.layout.FoldingFeature+import androidx.window.layout.WindowLayoutInfoimport com.google.android.material.dialog.MaterialAlertDialogBuilderimport com.google.android.material.slider.Sliderimport org.yuzu.yuzu_emu.NativeLibrary@@ -211,6 +217,33 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {}}+ private val Number.toPx get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt()++ fun updateCurrentLayout(emulationActivity: EmulationActivity, newLayoutInfo: WindowLayoutInfo) {+ val isFolding = (newLayoutInfo.displayFeatures.find { it is FoldingFeature } as? FoldingFeature)?.let {+ if (it.isSeparating) {+ emulationActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED+ if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) {+ binding.surfaceEmulation.layoutParams.height = it.bounds.top+ binding.inGameMenu.layoutParams.height = it.bounds.bottom+ binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx+ binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)+ }+ }+ it.isSeparating+ } ?: false+ if (!isFolding) {+ binding.surfaceEmulation.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT+ binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT+ binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT+ binding.overlayContainer.updatePadding(0, 0, 0, 0)+ emulationActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE+ }+ binding.surfaceInputOverlay.requestLayout()+ binding.inGameMenu.requestLayout()+ binding.overlayContainer.requestLayout()+ }+override fun surfaceCreated(holder: SurfaceHolder) {// We purposely don't do anything here.// All work is done in surfaceChanged, which we are guaranteed to get even for surface creation.diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xmlindex 74ec512afc..940dbd4bf7 100644--- a/src/android/app/src/main/res/layout/fragment_emulation.xml+++ b/src/android/app/src/main/res/layout/fragment_emulation.xml@@ -20,6 +20,12 @@android:focusable="false"android:focusableInTouchMode="false" />+ <FrameLayout+ android:id="@+id/overlay_container"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:layout_gravity="bottom">+<!-- This is the onscreen input overlay --><org.yuzu.yuzu_emu.overlay.InputOverlayandroid:id="@+id/surface_input_overlay"@@ -48,6 +54,7 @@android:layout_gravity="center"android:text="@string/emulation_done"android:visibility="gone" />+ </FrameLayout></androidx.coordinatorlayout.widget.CoordinatorLayout>@@ -55,7 +62,7 @@android:id="@+id/in_game_menu"android:layout_width="wrap_content"android:layout_height="match_parent"- android:layout_gravity="start"+ android:layout_gravity="start|bottom"app:headerLayout="@layout/header_in_game"app:menu="@menu/menu_in_game" />