diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java index 76f281046..d7a4dd1ca 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java @@ -3,6 +3,7 @@ package com.github.stenzek.duckstation; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.hardware.input.InputManager; import android.net.Uri; @@ -120,14 +121,20 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde }); } + private void doApplySettings() { + AndroidHostInterface.getInstance().applySettings(); + updateRequestedOrientation(); + } + private void applySettings() { if (!AndroidHostInterface.getInstance().isEmulationThreadRunning()) return; - if (AndroidHostInterface.getInstance().hasSurface()) - AndroidHostInterface.getInstance().applySettings(); - else + if (AndroidHostInterface.getInstance().hasSurface()) { + doApplySettings(); + } else { mApplySettingsOnSurfaceRestored = true; + } } /// Ends the activity if it was restored without properly being created. @@ -152,8 +159,8 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde updateOrientation(); if (mApplySettingsOnSurfaceRestored) { - AndroidHostInterface.getInstance().applySettings(); mApplySettingsOnSurfaceRestored = false; + doApplySettings(); } if (AndroidHostInterface.getInstance().isEmulationThreadPaused()) @@ -167,6 +174,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde final String bootSaveStatePath = getIntent().getStringExtra("saveStatePath"); AndroidHostInterface.getInstance().startEmulationThread(this, holder.getSurface(), bootPath, resumeState, bootSaveStatePath); + updateRequestedOrientation(); updateOrientation(); } @@ -244,8 +252,9 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde } if (requestCode == REQUEST_CODE_SETTINGS) { - if (AndroidHostInterface.getInstance().isEmulationThreadRunning()) + if (AndroidHostInterface.getInstance().isEmulationThreadRunning()) { applySettings(); + } } else if (requestCode == REQUEST_IMPORT_PATCH_CODES) { if (data != null) importPatchesFromFile(data.getData()); @@ -265,6 +274,16 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde updateOrientation(newConfig.orientation); } + private void updateRequestedOrientation() { + final String orientation = getStringSetting("Main/EmulationScreenOrientation", "unspecified"); + if (orientation.equals("portrait")) + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT); + else if (orientation.equals("landscape")) + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE); + else + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } + private void updateOrientation() { final int orientation = getResources().getConfiguration().orientation; updateOrientation(orientation); diff --git a/android/app/src/main/res/values/arrays.xml b/android/app/src/main/res/values/arrays.xml index 6551dc298..101b9a7d9 100644 --- a/android/app/src/main/res/values/arrays.xml +++ b/android/app/src/main/res/values/arrays.xml @@ -393,4 +393,14 @@ 900 1000 + + Use Device Setting + Portrait + Landscape + + + unspecified + portrait + landscape + diff --git a/android/app/src/main/res/xml/general_preferences.xml b/android/app/src/main/res/xml/general_preferences.xml index 25b6eb9a3..2fb1ec76a 100644 --- a/android/app/src/main/res/xml/general_preferences.xml +++ b/android/app/src/main/res/xml/general_preferences.xml @@ -45,6 +45,14 @@ app:defaultValue="false" app:summary="Pauses emulation when ingame and the menu is opened." app:iconSpaceReserved="false" /> +