summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt14
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt33
-rw-r--r--src/android/app/src/main/res/layout/fragment_emulation.xml9
3 files changed, 55 insertions, 1 deletions
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.kt
index 1382ae29f..901a3978d 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.getSystemService
26import androidx.core.view.WindowCompat 26import androidx.core.view.WindowCompat
27import androidx.core.view.WindowInsetsCompat 27import androidx.core.view.WindowInsetsCompat
28import androidx.core.view.WindowInsetsControllerCompat 28import androidx.core.view.WindowInsetsControllerCompat
29import androidx.lifecycle.Lifecycle
30import androidx.lifecycle.lifecycleScope
31import androidx.lifecycle.repeatOnLifecycle
32import androidx.window.layout.WindowInfoTracker
33import kotlinx.coroutines.Dispatchers
34import kotlinx.coroutines.launch
29import org.yuzu.yuzu_emu.NativeLibrary 35import org.yuzu.yuzu_emu.NativeLibrary
30import org.yuzu.yuzu_emu.R 36import org.yuzu.yuzu_emu.R
31import org.yuzu.yuzu_emu.fragments.EmulationFragment 37import org.yuzu.yuzu_emu.fragments.EmulationFragment
@@ -96,6 +102,14 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
96 inputHandler = InputHandler() 102 inputHandler = InputHandler()
97 inputHandler.initialize() 103 inputHandler.initialize()
98 104
105 lifecycleScope.launch(Dispatchers.Main) {
106 lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
107 WindowInfoTracker.getOrCreate(this@EmulationActivity)
108 .windowLayoutInfo(this@EmulationActivity)
109 .collect { emulationFragment?.updateCurrentLayout(this@EmulationActivity, it) }
110 }
111 }
112
99 // Start a foreground service to prevent the app from getting killed in the background 113 // Start a foreground service to prevent the app from getting killed in the background
100 val startIntent = Intent(this, ForegroundService::class.java) 114 val startIntent = Intent(this, ForegroundService::class.java)
101 startForegroundService(startIntent) 115 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.kt
index e00f02f86..1a9843fcc 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.AlertDialog
8import android.content.Context 8import android.content.Context
9import android.content.DialogInterface 9import android.content.DialogInterface
10import android.content.SharedPreferences 10import android.content.SharedPreferences
11import android.content.pm.ActivityInfo
12import android.content.res.Resources
11import android.graphics.Color 13import android.graphics.Color
12import android.os.Bundle 14import android.os.Bundle
13import android.os.Handler 15import android.os.Handler
14import android.os.Looper 16import android.os.Looper
17import android.util.TypedValue
15import android.view.* 18import android.view.*
16import android.widget.TextView 19import android.widget.TextView
17import androidx.activity.OnBackPressedCallback 20import androidx.activity.OnBackPressedCallback
@@ -20,8 +23,11 @@ import androidx.core.content.res.ResourcesCompat
20import androidx.core.graphics.Insets 23import androidx.core.graphics.Insets
21import androidx.core.view.ViewCompat 24import androidx.core.view.ViewCompat
22import androidx.core.view.WindowInsetsCompat 25import androidx.core.view.WindowInsetsCompat
26import androidx.core.view.updatePadding
23import androidx.fragment.app.Fragment 27import androidx.fragment.app.Fragment
24import androidx.preference.PreferenceManager 28import androidx.preference.PreferenceManager
29import androidx.window.layout.FoldingFeature
30import androidx.window.layout.WindowLayoutInfo
25import com.google.android.material.dialog.MaterialAlertDialogBuilder 31import com.google.android.material.dialog.MaterialAlertDialogBuilder
26import com.google.android.material.slider.Slider 32import com.google.android.material.slider.Slider
27import org.yuzu.yuzu_emu.NativeLibrary 33import org.yuzu.yuzu_emu.NativeLibrary
@@ -211,6 +217,33 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
211 } 217 }
212 } 218 }
213 219
220 private val Number.toPx get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt()
221
222 fun updateCurrentLayout(emulationActivity: EmulationActivity, newLayoutInfo: WindowLayoutInfo) {
223 val isFolding = (newLayoutInfo.displayFeatures.find { it is FoldingFeature } as? FoldingFeature)?.let {
224 if (it.isSeparating) {
225 emulationActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
226 if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) {
227 binding.surfaceEmulation.layoutParams.height = it.bounds.top
228 binding.inGameMenu.layoutParams.height = it.bounds.bottom
229 binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx
230 binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)
231 }
232 }
233 it.isSeparating
234 } ?: false
235 if (!isFolding) {
236 binding.surfaceEmulation.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
237 binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
238 binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
239 binding.overlayContainer.updatePadding(0, 0, 0, 0)
240 emulationActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
241 }
242 binding.surfaceInputOverlay.requestLayout()
243 binding.inGameMenu.requestLayout()
244 binding.overlayContainer.requestLayout()
245 }
246
214 override fun surfaceCreated(holder: SurfaceHolder) { 247 override fun surfaceCreated(holder: SurfaceHolder) {
215 // We purposely don't do anything here. 248 // We purposely don't do anything here.
216 // All work is done in surfaceChanged, which we are guaranteed to get even for surface creation. 249 // 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.xml
index 74ec512af..940dbd4bf 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 @@
20 android:focusable="false" 20 android:focusable="false"
21 android:focusableInTouchMode="false" /> 21 android:focusableInTouchMode="false" />
22 22
23 <FrameLayout
24 android:id="@+id/overlay_container"
25 android:layout_width="match_parent"
26 android:layout_height="match_parent"
27 android:layout_gravity="bottom">
28
23 <!-- This is the onscreen input overlay --> 29 <!-- This is the onscreen input overlay -->
24 <org.yuzu.yuzu_emu.overlay.InputOverlay 30 <org.yuzu.yuzu_emu.overlay.InputOverlay
25 android:id="@+id/surface_input_overlay" 31 android:id="@+id/surface_input_overlay"
@@ -48,6 +54,7 @@
48 android:layout_gravity="center" 54 android:layout_gravity="center"
49 android:text="@string/emulation_done" 55 android:text="@string/emulation_done"
50 android:visibility="gone" /> 56 android:visibility="gone" />
57 </FrameLayout>
51 58
52 </androidx.coordinatorlayout.widget.CoordinatorLayout> 59 </androidx.coordinatorlayout.widget.CoordinatorLayout>
53 60
@@ -55,7 +62,7 @@
55 android:id="@+id/in_game_menu" 62 android:id="@+id/in_game_menu"
56 android:layout_width="wrap_content" 63 android:layout_width="wrap_content"
57 android:layout_height="match_parent" 64 android:layout_height="match_parent"
58 android:layout_gravity="start" 65 android:layout_gravity="start|bottom"
59 app:headerLayout="@layout/header_in_game" 66 app:headerLayout="@layout/header_in_game"
60 app:menu="@menu/menu_in_game" /> 67 app:menu="@menu/menu_in_game" />
61 68