diff options
Diffstat (limited to 'src')
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 | |||
| 26 | import androidx.core.view.WindowCompat | 26 | import androidx.core.view.WindowCompat |
| 27 | import androidx.core.view.WindowInsetsCompat | 27 | import androidx.core.view.WindowInsetsCompat |
| 28 | import androidx.core.view.WindowInsetsControllerCompat | 28 | import androidx.core.view.WindowInsetsControllerCompat |
| 29 | import androidx.lifecycle.Lifecycle | ||
| 30 | import androidx.lifecycle.lifecycleScope | ||
| 31 | import androidx.lifecycle.repeatOnLifecycle | ||
| 32 | import androidx.window.layout.WindowInfoTracker | ||
| 33 | import kotlinx.coroutines.Dispatchers | ||
| 34 | import kotlinx.coroutines.launch | ||
| 29 | import org.yuzu.yuzu_emu.NativeLibrary | 35 | import org.yuzu.yuzu_emu.NativeLibrary |
| 30 | import org.yuzu.yuzu_emu.R | 36 | import org.yuzu.yuzu_emu.R |
| 31 | import org.yuzu.yuzu_emu.fragments.EmulationFragment | 37 | import 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 | |||
| 8 | import android.content.Context | 8 | import android.content.Context |
| 9 | import android.content.DialogInterface | 9 | import android.content.DialogInterface |
| 10 | import android.content.SharedPreferences | 10 | import android.content.SharedPreferences |
| 11 | import android.content.pm.ActivityInfo | ||
| 12 | import android.content.res.Resources | ||
| 11 | import android.graphics.Color | 13 | import android.graphics.Color |
| 12 | import android.os.Bundle | 14 | import android.os.Bundle |
| 13 | import android.os.Handler | 15 | import android.os.Handler |
| 14 | import android.os.Looper | 16 | import android.os.Looper |
| 17 | import android.util.TypedValue | ||
| 15 | import android.view.* | 18 | import android.view.* |
| 16 | import android.widget.TextView | 19 | import android.widget.TextView |
| 17 | import androidx.activity.OnBackPressedCallback | 20 | import androidx.activity.OnBackPressedCallback |
| @@ -20,8 +23,11 @@ import androidx.core.content.res.ResourcesCompat | |||
| 20 | import androidx.core.graphics.Insets | 23 | import androidx.core.graphics.Insets |
| 21 | import androidx.core.view.ViewCompat | 24 | import androidx.core.view.ViewCompat |
| 22 | import androidx.core.view.WindowInsetsCompat | 25 | import androidx.core.view.WindowInsetsCompat |
| 26 | import androidx.core.view.updatePadding | ||
| 23 | import androidx.fragment.app.Fragment | 27 | import androidx.fragment.app.Fragment |
| 24 | import androidx.preference.PreferenceManager | 28 | import androidx.preference.PreferenceManager |
| 29 | import androidx.window.layout.FoldingFeature | ||
| 30 | import androidx.window.layout.WindowLayoutInfo | ||
| 25 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 31 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 26 | import com.google.android.material.slider.Slider | 32 | import com.google.android.material.slider.Slider |
| 27 | import org.yuzu.yuzu_emu.NativeLibrary | 33 | import 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 | ||