Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Android] Decouple the emulation processes from the Main activity. Mo…
…ved them into their own activity called EmulationActivity.
- Loading branch information
Showing
5 changed files
with
173 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
Source/Android/src/org/dolphinemu/dolphinemu/EmulationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters