Merge pull request #7551 from zackhow/fixffs

Android: Fix crash on instant rotate
This commit is contained in:
Pierre Bourdon 2018-11-09 04:27:59 +01:00 committed by GitHub
commit 98d2e278b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 15 deletions

View File

@ -185,6 +185,10 @@ public final class EmulationActivity extends AppCompatActivity
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Find the EmulationFragment
mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
.findFragmentById(R.id.frame_emulation_fragment);
if (savedInstanceState == null) if (savedInstanceState == null)
{ {
// Get params we were passed // Get params we were passed
@ -196,7 +200,9 @@ public final class EmulationActivity extends AppCompatActivity
} }
else else
{ {
activityRecreated = true; // Could have recreated the activity(rotate) before creating the fragment. If the fragment
// doesn't exist, treat this as a new start.
activityRecreated = mEmulationFragment != null;
restoreState(savedInstanceState); restoreState(savedInstanceState);
} }
@ -212,13 +218,6 @@ public final class EmulationActivity extends AppCompatActivity
int themeId; int themeId;
if (mDeviceHasTouchScreen) if (mDeviceHasTouchScreen)
{ {
BooleanSetting lockLandscape =
(BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
.getSetting(SettingsFile.KEY_LOCK_LANDSCAPE);
// Force landscape if set
if (lockLandscape == null || lockLandscape.getValue())
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
themeId = R.style.DolphinEmulationBase; themeId = R.style.DolphinEmulationBase;
// Get a handle to the Window containing the UI. // Get a handle to the Window containing the UI.
@ -250,10 +249,20 @@ public final class EmulationActivity extends AppCompatActivity
setContentView(R.layout.activity_emulation); setContentView(R.layout.activity_emulation);
// Find or create the EmulationFragment
mEmulationFragment = (EmulationFragment) getSupportFragmentManager() BooleanSetting lockLandscapeSetting =
.findFragmentById(R.id.frame_emulation_fragment); (BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
if (mEmulationFragment == null) .getSetting(SettingsFile.KEY_LOCK_LANDSCAPE);
boolean lockLandscape = lockLandscapeSetting == null || lockLandscapeSetting.getValue();
// Force landscape if set
if (mDeviceHasTouchScreen && lockLandscape)
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
if (!(mDeviceHasTouchScreen && lockLandscape &&
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) &&
mEmulationFragment == null)
{ {
mEmulationFragment = EmulationFragment.newInstance(mPath); mEmulationFragment = EmulationFragment.newInstance(mPath);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()

View File

@ -3,6 +3,7 @@ package org.dolphinemu.dolphinemu.features.settings.ui;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
@ -24,6 +25,7 @@ import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.EGLHelper; import org.dolphinemu.dolphinemu.utils.EGLHelper;
import org.dolphinemu.dolphinemu.utils.Log; import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.TvUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -265,9 +267,12 @@ public final class SettingsFragmentPresenter
sl.add(new CheckBoxSetting(SettingsFile.KEY_ENABLE_SAVE_STATES, Settings.SECTION_INI_CORE, sl.add(new CheckBoxSetting(SettingsFile.KEY_ENABLE_SAVE_STATES, Settings.SECTION_INI_CORE,
R.string.enable_save_states, R.string.enable_save_states_description, false, R.string.enable_save_states, R.string.enable_save_states_description, false,
enableSaveState)); enableSaveState));
if (!TvUtil.isLeanback(DolphinApplication.getAppContext()))
{
sl.add(new CheckBoxSetting(SettingsFile.KEY_LOCK_LANDSCAPE, Settings.SECTION_INI_CORE, sl.add(new CheckBoxSetting(SettingsFile.KEY_LOCK_LANDSCAPE, Settings.SECTION_INI_CORE,
R.string.lock_emulation_landscape, R.string.lock_emulation_landscape_desc, true, R.string.lock_emulation_landscape, R.string.lock_emulation_landscape_desc, true,
lockToLandscape)); lockToLandscape));
}
sl.add(new CheckBoxSetting(SettingsFile.KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS, sl.add(new CheckBoxSetting(SettingsFile.KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS,
R.string.analytics, 0, false, analytics)); R.string.analytics, 0, false, analytics));
} }