Android: Add option to force screen rotation
This commit is contained in:
parent
f88fca8817
commit
7f26ba3b59
|
@ -3,6 +3,7 @@ package com.github.stenzek.duckstation;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.net.Uri;
|
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() {
|
private void applySettings() {
|
||||||
if (!AndroidHostInterface.getInstance().isEmulationThreadRunning())
|
if (!AndroidHostInterface.getInstance().isEmulationThreadRunning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (AndroidHostInterface.getInstance().hasSurface())
|
if (AndroidHostInterface.getInstance().hasSurface()) {
|
||||||
AndroidHostInterface.getInstance().applySettings();
|
doApplySettings();
|
||||||
else
|
} else {
|
||||||
mApplySettingsOnSurfaceRestored = true;
|
mApplySettingsOnSurfaceRestored = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ends the activity if it was restored without properly being created.
|
/// Ends the activity if it was restored without properly being created.
|
||||||
|
@ -152,8 +159,8 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
updateOrientation();
|
updateOrientation();
|
||||||
|
|
||||||
if (mApplySettingsOnSurfaceRestored) {
|
if (mApplySettingsOnSurfaceRestored) {
|
||||||
AndroidHostInterface.getInstance().applySettings();
|
|
||||||
mApplySettingsOnSurfaceRestored = false;
|
mApplySettingsOnSurfaceRestored = false;
|
||||||
|
doApplySettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AndroidHostInterface.getInstance().isEmulationThreadPaused())
|
if (AndroidHostInterface.getInstance().isEmulationThreadPaused())
|
||||||
|
@ -167,6 +174,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
final String bootSaveStatePath = getIntent().getStringExtra("saveStatePath");
|
final String bootSaveStatePath = getIntent().getStringExtra("saveStatePath");
|
||||||
|
|
||||||
AndroidHostInterface.getInstance().startEmulationThread(this, holder.getSurface(), bootPath, resumeState, bootSaveStatePath);
|
AndroidHostInterface.getInstance().startEmulationThread(this, holder.getSurface(), bootPath, resumeState, bootSaveStatePath);
|
||||||
|
updateRequestedOrientation();
|
||||||
updateOrientation();
|
updateOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,8 +252,9 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestCode == REQUEST_CODE_SETTINGS) {
|
if (requestCode == REQUEST_CODE_SETTINGS) {
|
||||||
if (AndroidHostInterface.getInstance().isEmulationThreadRunning())
|
if (AndroidHostInterface.getInstance().isEmulationThreadRunning()) {
|
||||||
applySettings();
|
applySettings();
|
||||||
|
}
|
||||||
} else if (requestCode == REQUEST_IMPORT_PATCH_CODES) {
|
} else if (requestCode == REQUEST_IMPORT_PATCH_CODES) {
|
||||||
if (data != null)
|
if (data != null)
|
||||||
importPatchesFromFile(data.getData());
|
importPatchesFromFile(data.getData());
|
||||||
|
@ -265,6 +274,16 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
updateOrientation(newConfig.orientation);
|
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() {
|
private void updateOrientation() {
|
||||||
final int orientation = getResources().getConfiguration().orientation;
|
final int orientation = getResources().getConfiguration().orientation;
|
||||||
updateOrientation(orientation);
|
updateOrientation(orientation);
|
||||||
|
|
|
@ -393,4 +393,14 @@
|
||||||
<item>900</item>
|
<item>900</item>
|
||||||
<item>1000</item>
|
<item>1000</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
|
|
|
@ -45,6 +45,14 @@
|
||||||
app:defaultValue="false"
|
app:defaultValue="false"
|
||||||
app:summary="Pauses emulation when ingame and the menu is opened."
|
app:summary="Pauses emulation when ingame and the menu is opened."
|
||||||
app:iconSpaceReserved="false" />
|
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
|
<SwitchPreferenceCompat
|
||||||
app:key="Main/AutoLoadCheats"
|
app:key="Main/AutoLoadCheats"
|
||||||
app:title="Load Patch Codes"
|
app:title="Load Patch Codes"
|
||||||
|
|
Loading…
Reference in New Issue