Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Gamepad input. Refactor JNI native functions to all pull fr…
…om a single class instead of everywhere willy-nilly
  • Loading branch information
Sonicadvance1 committed Jun 18, 2013
1 parent a518a1c commit 7223778
Show file tree
Hide file tree
Showing 19 changed files with 916 additions and 365 deletions.
286 changes: 124 additions & 162 deletions Source/Android/.idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Source/Android/AndroidManifest.xml
Expand Up @@ -35,6 +35,11 @@
android:label="@string/app_name"
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
</activity>
<activity
android:name="org.dolphinemu.dolphinemu.InputConfigActivity"
android:label="@string/app_name"
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
</activity>
<activity
android:name=".PrefsActivity" >
</activity>
Expand Down
34 changes: 17 additions & 17 deletions Source/Android/assets/GCPadNew.ini
Expand Up @@ -2,28 +2,28 @@
Device = Android/0/Touchscreen
Buttons/A = Button 0
Buttons/B = Button 1
Buttons/X = C
Buttons/Y = S
Buttons/Z = D
Buttons/X = Button 3
Buttons/Y = Button 4
Buttons/Z = Button 5
Buttons/Start = Button 2
Main Stick/Up = Up
Main Stick/Down = Down
Main Stick/Left = Left
Main Stick/Right = Right
Main Stick/Up = Axis 10
Main Stick/Down = Axis 11
Main Stick/Left = Axis 12
Main Stick/Right = Axis 13
Main Stick/Modifier = Shift_L
Main Stick/Modifier/Range = 50.000000
C-Stick/Up = I
C-Stick/Down = K
C-Stick/Left = J
C-Stick/Right = L
C-Stick/Up = Axis 14
C-Stick/Down = Axis 15
C-Stick/Left = Axis 16
C-Stick/Right = Axis 17
C-Stick/Modifier = Control_L
C-Stick/Modifier/Range = 50.000000
Triggers/L = Q
Triggers/R = W
D-Pad/Up = T
D-Pad/Down = G
D-Pad/Left = F
D-Pad/Right = H
Triggers/L = Axis 18
Triggers/R = Axis 19
D-Pad/Up = Button 6
D-Pad/Down = Button 7
D-Pad/Left = Button 8
D-Pad/Right = Button 9
[GCPad2]
[GCPad3]
[GCPad4]
67 changes: 45 additions & 22 deletions Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java
Expand Up @@ -7,10 +7,13 @@
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;

public class DolphinEmulator<MainActivity> extends Activity
{
Expand All @@ -20,19 +23,6 @@
private float screenWidth;
private float screenHeight;

public static native void onTouchEvent(int Action, float X, float Y);

static
{
try
{
System.loadLibrary("dolphin-emu-nogui");
}
catch (Exception ex)
{
Log.w("me", ex.toString());
}
}
private void CopyAsset(String asset, String output) {
InputStream in = null;
OutputStream out = null;
Expand All @@ -49,6 +39,7 @@ private void CopyAsset(String asset, String output) {
Log.e("tag", "Failed to copy asset file: " + asset, e);
}
}

private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
Expand All @@ -62,21 +53,21 @@ public void onStop()
{
super.onStop();
if (Running)
NativeGLSurfaceView.StopEmulation();
NativeLibrary.StopEmulation();
}
@Override
public void onPause()
{
super.onPause();
if (Running)
NativeGLSurfaceView.PauseEmulation();
NativeLibrary.PauseEmulation();
}
@Override
public void onResume()
{
super.onResume();
if (Running)
NativeGLSurfaceView.UnPauseEmulation();
NativeLibrary.UnPauseEmulation();
}

/** Called when the activity is first created. */
Expand Down Expand Up @@ -158,14 +149,46 @@ public boolean onTouchEvent(MotionEvent event)
float ScreenX = ((X / screenWidth) * 2.0f) - 1.0f;
float ScreenY = ((Y / screenHeight) * -2.0f) + 1.0f;

onTouchEvent(Action, ScreenX, ScreenY);
NativeLibrary.onTouchEvent(Action, ScreenX, ScreenY);

return false;
}

public boolean overrideKeys()
{
return false;
}

// Gets button presses
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = 0;
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
action = 0;
break;
case KeyEvent.ACTION_UP:
action = 1;
break;
default:
break;
}
InputDevice input = event.getDevice();
NativeLibrary.onGamePadEvent(input.getDescriptor(), event.getKeyCode(), action);
return true;
}

@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)) {
return super.dispatchGenericMotionEvent(event);
}

InputDevice input = event.getDevice();
List<InputDevice.MotionRange> motions = input.getMotionRanges();
for (int a = 0; a < motions.size(); ++a)
{
InputDevice.MotionRange range;
range = motions.get(a);
NativeLibrary.onGamePadMoveEvent(input.getDescriptor(), range.getAxis(), event.getAxisValue(range.getAxis()));
}

return true;
}

}
28 changes: 7 additions & 21 deletions Source/Android/src/org/dolphinemu/dolphinemu/GameListItem.java
@@ -1,33 +1,19 @@
package org.dolphinemu.dolphinemu;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class GameListItem implements Comparable<GameListItem>{
private String name;
private String data;
private String path;
private Bitmap image;
public static native int[] GetBanner(String filename);
public static native String GetTitle(String filename);
static
{
try
{
System.loadLibrary("dolphin-emu-nogui");
}
catch (Exception ex)
{
Log.w("me", ex.toString());
}
}


public GameListItem(Context ctx, String n,String d,String p)
{
name = n;
Expand All @@ -36,7 +22,7 @@ public GameListItem(Context ctx, String n,String d,String p)
File file = new File(path);
if (!file.isDirectory())
{
int[] Banner = GetBanner(path);
int[] Banner = NativeLibrary.GetBanner(path);
if (Banner[0] == 0)
{
try {
Expand All @@ -50,7 +36,7 @@ public GameListItem(Context ctx, String n,String d,String p)
}
else
image = Bitmap.createBitmap(Banner, 96, 32, Bitmap.Config.ARGB_8888);
name = GetTitle(path);
name = NativeLibrary.GetTitle(path);
}
}

Expand Down
27 changes: 16 additions & 11 deletions Source/Android/src/org/dolphinemu/dolphinemu/GameListView.java
Expand Up @@ -24,22 +24,18 @@ public class GameListView extends ListActivity {

private SideMenuAdapter mAdapter;
private static GameListView me;
public static native String GetConfig(String Key, String Value, String Default);
public static native void SetConfig(String Key, String Value, String Default);

enum keyTypes {TYPE_STRING, TYPE_BOOL};

private void Fill()
{


this.setTitle("Game List");
List<GameListItem>fls = new ArrayList<GameListItem>();
String Directories = GetConfig("General", "GCMPathes", "0");
String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
int intDirectories = Integer.parseInt(Directories);
for (int a = 0; a < intDirectories; ++a)
{
String BrowseDir = GetConfig("General", "GCMPath" + Integer.toString(a), "");
String BrowseDir = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPath" + Integer.toString(a), "");
File currentDir = new File(BrowseDir);
File[]dirs = currentDir.listFiles();
try
Expand Down Expand Up @@ -101,11 +97,11 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
{
String FileName = data.getStringExtra("Select");
Toast.makeText(this, "Folder Selected: " + FileName, Toast.LENGTH_SHORT).show();
String Directories = GetConfig("General", "GCMPathes", "0");
String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
int intDirectories = Integer.parseInt(Directories);
Directories = Integer.toString(intDirectories + 1);
SetConfig("General", "GCMPathes", Directories);
SetConfig("General", "GCMPath" + Integer.toString(intDirectories), FileName);
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPathes", Directories);
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPath" + Integer.toString(intDirectories), FileName);

Fill();
}
Expand Down Expand Up @@ -142,16 +138,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
{
case TYPE_STRING:
String strPref = prefs.getString(Keys[a], "");
SetConfig(Key, Value, strPref);
NativeLibrary.SetConfig("Dolphin.ini", Key, Value, strPref);
break;
case TYPE_BOOL:
boolean boolPref = prefs.getBoolean(Keys[a], true);
SetConfig(Key, Value, boolPref ? "True" : "False");
NativeLibrary.SetConfig("Dolphin.ini", Key, Value, boolPref ? "True" : "False");
break;
}

}
break;
case 3: // Gamepad settings
/* Do Nothing */
break;
}
}

Expand All @@ -169,6 +168,7 @@ public void onCreate(Bundle savedInstanceState)
List<SideMenuItem>dir = new ArrayList<SideMenuItem>();
dir.add(new SideMenuItem("Browse Folder", 0));
dir.add(new SideMenuItem("Settings", 1));
dir.add(new SideMenuItem("Gamepad Config", 2));

ListView mList = new ListView(this);
mAdapter = new SideMenuAdapter(this,R.layout.sidemenu,dir);
Expand All @@ -193,6 +193,11 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
Intent SettingIntent = new Intent(me, PrefsActivity.class);
startActivityForResult(SettingIntent, 2);
break;
case 2:
Toast.makeText(me, "Loading up settings", Toast.LENGTH_SHORT).show();
Intent ConfigIntent = new Intent(me, InputConfigActivity.class);
startActivityForResult(ConfigIntent, 3);
break;
default:
break;
}
Expand Down

0 comments on commit 7223778

Please sign in to comment.