Android: Add option to force screen rotation
This commit is contained in:
parent
fb4ebabee5
commit
d23b9b508d
|
@ -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);
|
||||
|
|
|
@ -393,4 +393,14 @@
|
|||
<item>900</item>
|
||||
<item>1000</item>
|
||||
</string-array>
|
||||
<string-array name="settings_emulation_screen_orientation_entries">
|
||||
<item>Use Device Setting</item>
|
||||
<item>Portrait</item>
|
||||
<item>Landscape</item>
|
||||
</string-array>
|
||||
<string-array name="settings_emulation_screen_orientation_values">
|
||||
<item>unspecified</item>
|
||||
<item>portrait</item>
|
||||
<item>landscape</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -45,6 +45,14 @@
|
|||
app:defaultValue="false"
|
||||
app:summary="Pauses emulation when ingame and the menu is opened."
|
||||
app:iconSpaceReserved="false" />
|
||||
<ListPreference
|
||||
app:key="Main/EmulationScreenOrientation"
|
||||
app:title="Emulation Screen Orientation"
|
||||
app:entries="@array/settings_emulation_screen_orientation_entries"
|
||||
app:entryValues="@array/settings_emulation_screen_orientation_values"
|
||||
app:defaultValue="unspecified"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
app:key="Main/AutoLoadCheats"
|
||||
app:title="Load Patch Codes"
|
||||
|
|
Loading…
Reference in New Issue