[Android] Add support for rotation and minimizing the application

This commit is contained in:
Ryan Houdek 2016-01-10 12:31:49 -06:00
parent 6448e5e5ee
commit 5a549ef663
7 changed files with 78 additions and 29 deletions

View file

@ -333,10 +333,12 @@ public final class NativeLibrary
/**
* Begins emulation.
*
* @param surf The surface to render to.
*/
public static native void Run(Surface surf);
public static native void Run();
// Surface Handling
public static native void SurfaceChanged(Surface surf);
public static native void SurfaceDestroyed();
/** Unpauses emulation from a paused state. */
public static native void UnPauseEmulation();

View file

@ -177,13 +177,16 @@ public final class EmulationActivity extends AppCompatActivity
}
});
// Instantiate an EmulationFragment.
EmulationFragment emulationFragment = EmulationFragment.newInstance(path);
if (savedInstanceState == null)
{
// Instantiate an EmulationFragment.
EmulationFragment emulationFragment = EmulationFragment.newInstance(path);
// Add fragment to the activity - this triggers all its lifecycle callbacks.
getFragmentManager().beginTransaction()
.add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG)
.commit();
// Add fragment to the activity - this triggers all its lifecycle callbacks.
getFragmentManager().beginTransaction()
.add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG)
.commit();
}
if (mDeviceHasTouchScreen)
{

View file

@ -115,7 +115,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
public void onStop()
{
super.onStop();
pauseEmulation();
}
@Override
@ -160,12 +159,14 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
{
Log.d("DolphinEmu", "Surface changed. Resolution: " + width + "x" + height);
mSurface = holder.getSurface();
NativeLibrary.SurfaceChanged(mSurface);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
Log.d("DolphinEmu", "Surface destroyed.");
NativeLibrary.SurfaceDestroyed();
if (mEmulationRunning)
{
@ -216,20 +217,14 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mEmulationRunning = true;
mEmulationStarted = true;
// Loop until onSurfaceCreated succeeds
while (mSurface == null)
{
if (!mEmulationRunning)
{
// So that if the user quits before this gets a surface, we don't loop infinitely.
return;
}
}
Log.i("DolphinEmu", "Starting emulation: " + mSurface);
// Start emulation using the provided Surface.
NativeLibrary.Run(mSurface);
NativeLibrary.Run();
}
};
}