[Android] Decouple the emulation processes from the Main activity. Moved them into their own activity called EmulationActivity.
This commit is contained in:
parent
2de2e774fe
commit
aeec249626
|
@ -32,8 +32,8 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="org.dolphinemu.dolphinemu.gamelist.GameListActivity" >
|
||||
</activity>
|
||||
<activity android:name="org.dolphinemu.dolphinemu.gamelist.GameListActivity" />
|
||||
<activity android:name="org.dolphinemu.dolphinemu.EmulationActivity" />
|
||||
<activity
|
||||
android:name="org.dolphinemu.dolphinemu.settings.PrefsActivity"
|
||||
android:label="@string/settings" >
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
@ -11,4 +11,4 @@
|
|||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</merge>
|
|
@ -7,31 +7,23 @@
|
|||
package org.dolphinemu.dolphinemu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
import org.dolphinemu.dolphinemu.gamelist.GameListActivity;
|
||||
import org.dolphinemu.dolphinemu.settings.InputConfigFragment;
|
||||
import org.dolphinemu.dolphinemu.settings.UserPreferences;
|
||||
|
||||
/**
|
||||
* The main activity of this emulator.
|
||||
*
|
||||
* @param <MainActivity> Main activity.
|
||||
*/
|
||||
public final class DolphinEmulator<MainActivity> extends Activity
|
||||
{
|
||||
private static boolean Running = false;
|
||||
|
||||
private float screenWidth;
|
||||
private float screenHeight;
|
||||
|
||||
private void CopyAsset(String asset, String output)
|
||||
{
|
||||
InputStream in = null;
|
||||
|
@ -62,30 +54,6 @@ public final class DolphinEmulator<MainActivity> extends Activity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
if (Running)
|
||||
NativeLibrary.StopEmulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (Running)
|
||||
NativeLibrary.PauseEmulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (Running)
|
||||
NativeLibrary.UnPauseEmulation();
|
||||
}
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
|
@ -138,103 +106,4 @@ public final class DolphinEmulator<MainActivity> extends Activity
|
|||
UserPreferences.LoadDolphinConfigToPrefs(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
|
||||
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
screenWidth = displayMetrics.widthPixels;
|
||||
screenHeight = displayMetrics.heightPixels;
|
||||
|
||||
String FileName = data.getStringExtra("Select");
|
||||
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
NativeLibrary.SetDimensions((int)screenWidth, (int)screenHeight);
|
||||
NativeLibrary.SetFilename(FileName);
|
||||
setContentView(R.layout.emulation_view);
|
||||
Running = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
float X = event.getX();
|
||||
float Y = event.getY();
|
||||
int Action = event.getActionMasked();
|
||||
|
||||
// Converts button locations 0 - 1 to OGL screen coords -1.0 - 1.0
|
||||
float ScreenX = ((X / screenWidth) * 2.0f) - 1.0f;
|
||||
float ScreenY = ((Y / screenHeight) * -2.0f) + 1.0f;
|
||||
|
||||
NativeLibrary.onTouchEvent(Action, ScreenX, ScreenY);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gets button presses
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event)
|
||||
{
|
||||
int action = 0;
|
||||
|
||||
// Special catch for the back key
|
||||
// Currently disabled because stopping and starting emulation is broken.
|
||||
/*
|
||||
if (event.getSource() == InputDevice.SOURCE_KEYBOARD
|
||||
&& event.getKeyCode() == KeyEvent.KEYCODE_BACK
|
||||
&& event.getAction() == KeyEvent.ACTION_UP)
|
||||
{
|
||||
if (Running)
|
||||
NativeLibrary.StopEmulation();
|
||||
Running = false;
|
||||
Intent ListIntent = new Intent(this, GameListActivity.class);
|
||||
startActivityForResult(ListIntent, 1);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
if (Running)
|
||||
{
|
||||
switch (event.getAction())
|
||||
{
|
||||
case KeyEvent.ACTION_DOWN:
|
||||
action = 0;
|
||||
break;
|
||||
case KeyEvent.ACTION_UP:
|
||||
action = 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
InputDevice input = event.getDevice();
|
||||
NativeLibrary.onGamePadEvent(InputConfigFragment.getInputDesc(input), event.getKeyCode(), action);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
||||
{
|
||||
if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) || !Running)
|
||||
{
|
||||
return super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
InputDevice input = event.getDevice();
|
||||
List<InputDevice.MotionRange> motions = input.getMotionRanges();
|
||||
|
||||
for (InputDevice.MotionRange range : motions)
|
||||
{
|
||||
NativeLibrary.onGamePadMoveEvent(InputConfigFragment.getInputDesc(input), range.getAxis(), event.getAxisValue(range.getAxis()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package org.dolphinemu.dolphinemu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dolphinemu.dolphinemu.settings.InputConfigFragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
* This is the activity where all of the emulation handling happens.
|
||||
* This activity is responsible for displaying the SurfaceView that we render to.
|
||||
*/
|
||||
public final class EmulationActivity extends Activity
|
||||
{
|
||||
private boolean Running;
|
||||
private float screenWidth;
|
||||
private float screenHeight;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Retrieve screen dimensions.
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
|
||||
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
this.screenHeight = displayMetrics.heightPixels;
|
||||
this.screenWidth = displayMetrics.widthPixels;
|
||||
|
||||
// Request window features for the emulation view.
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
|
||||
|
||||
// Set the native rendering screen width/height.
|
||||
// Also get the intent passed from the GameList when the game
|
||||
// was selected. This is so the path of the game can be retrieved
|
||||
// and set on the native side of the code so the emulator can actually
|
||||
// load the game.
|
||||
Intent gameToEmulate = getIntent();
|
||||
NativeLibrary.SetDimensions((int)screenWidth, (int)screenHeight);
|
||||
NativeLibrary.SetFilename(gameToEmulate.getStringExtra("SelectedGame"));
|
||||
Running = true;
|
||||
|
||||
// Set the emulation window.
|
||||
setContentView(R.layout.emulation_view);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
if (Running)
|
||||
NativeLibrary.StopEmulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (Running)
|
||||
NativeLibrary.PauseEmulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (Running)
|
||||
NativeLibrary.UnPauseEmulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
float X = event.getX();
|
||||
float Y = event.getY();
|
||||
int Action = event.getActionMasked();
|
||||
|
||||
// Converts button locations 0 - 1 to OGL screen coords -1.0 - 1.0
|
||||
float ScreenX = ((X / screenWidth) * 2.0f) - 1.0f;
|
||||
float ScreenY = ((Y / screenHeight) * -2.0f) + 1.0f;
|
||||
|
||||
NativeLibrary.onTouchEvent(Action, ScreenX, ScreenY);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gets button presses
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event)
|
||||
{
|
||||
int action = 0;
|
||||
|
||||
// Special catch for the back key
|
||||
// Currently disabled because stopping and starting emulation is broken.
|
||||
/*
|
||||
if (event.getSource() == InputDevice.SOURCE_KEYBOARD
|
||||
&& event.getKeyCode() == KeyEvent.KEYCODE_BACK
|
||||
&& event.getAction() == KeyEvent.ACTION_UP)
|
||||
{
|
||||
if (Running)
|
||||
NativeLibrary.StopEmulation();
|
||||
Running = false;
|
||||
Intent ListIntent = new Intent(this, GameListActivity.class);
|
||||
startActivityForResult(ListIntent, 1);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
if (Running)
|
||||
{
|
||||
switch (event.getAction())
|
||||
{
|
||||
case KeyEvent.ACTION_DOWN:
|
||||
action = 0;
|
||||
break;
|
||||
case KeyEvent.ACTION_UP:
|
||||
action = 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
InputDevice input = event.getDevice();
|
||||
NativeLibrary.onGamePadEvent(InputConfigFragment.getInputDesc(input), event.getKeyCode(), action);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
||||
{
|
||||
if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) || !Running)
|
||||
{
|
||||
return super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
InputDevice input = event.getDevice();
|
||||
List<InputDevice.MotionRange> motions = input.getMotionRanges();
|
||||
|
||||
for (InputDevice.MotionRange range : motions)
|
||||
{
|
||||
NativeLibrary.onGamePadMoveEvent(InputConfigFragment.getInputDesc(input), range.getAxis(), event.getAxisValue(range.getAxis()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.dolphinemu.dolphinemu.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
|
||||
|
@ -132,9 +133,9 @@ public final class GameListFragment extends Fragment
|
|||
{
|
||||
Toast.makeText(mMe, getString(R.string.file_clicked) + o, Toast.LENGTH_SHORT).show();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("Select", o);
|
||||
mMe.setResult(Activity.RESULT_OK, intent);
|
||||
Intent intent = new Intent(mMe, EmulationActivity.class);
|
||||
intent.putExtra("SelectedGame", o);
|
||||
mMe.startActivity(intent);
|
||||
mMe.finish();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue