Remove a check when motion is motion, recognized or not

This commit is contained in:
TwistedUmbrella 2014-02-24 06:50:27 -05:00
parent b1bcef83ea
commit 5f9c75a414
11 changed files with 147 additions and 279 deletions

View File

@ -44,7 +44,7 @@
</intent-filter>
</activity>
<activity
android:name="com.reicast.emulator.emu.GL2JNIActivity"
android:name=".GL2JNIActivity"
android:configChanges="orientation|screenSize|screenLayout|uiMode|keyboard|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
@ -91,7 +91,7 @@
</intent-filter>
</activity>
<activity
android:name="com.reicast.emulator.config.EditVJoyActivity"
android:name=".config.EditVJoyActivity"
android:configChanges="orientation|screenSize|screenLayout|uiMode|keyboard|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

View File

@ -389,71 +389,6 @@
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="Joystick" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/dpad_joystick" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<de.ankri.views.Switch
android:id="@+id/dpad_js_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >

View File

@ -57,7 +57,6 @@
<string name="controller_already_in_use">This controller is already in use!</string>
<string name="modified_layout">Enable Custom Key Layout</string>
<string name="controller_compat">Enable Compatibility Mode</string>
<string name="dpad_joystick">Joystick Uses DPAD Layout</string>
<string name="mic_in_port_2">Microphone plugged into port 2</string>
<string name="customize_physical_controls">Customize Physical Controls</string>

View File

@ -1,4 +1,4 @@
package com.reicast.emulator.emu;
package com.reicast.emulator;
import java.util.Arrays;
import java.util.HashMap;
@ -14,6 +14,7 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.SparseArray;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyEvent;
@ -25,8 +26,9 @@ import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.reicast.emulator.R;
import com.reicast.emulator.config.ConfigureFragment;
import com.reicast.emulator.emu.GL2JNIView;
import com.reicast.emulator.emu.JNIdc;
import com.reicast.emulator.emu.OnScreenMenu;
import com.reicast.emulator.emu.OnScreenMenu.FpsPopup;
import com.reicast.emulator.emu.OnScreenMenu.MainPopup;
import com.reicast.emulator.emu.OnScreenMenu.VmuPopup;
@ -38,44 +40,35 @@ import com.reicast.emulator.periph.SipEmulator;
public class GL2JNIActivity extends Activity {
public GL2JNIView mView;
OnScreenMenu menu;
MainPopup popUp;
public MainPopup popUp;
VmuPopup vmuPop;
FpsPopup fpsPop;
MOGAInput moga = new MOGAInput();
private SharedPreferences prefs;
public String[] portId = { "_A", "_B", "_C", "_D" };
public boolean[] compat = { false, false, false, false };
public boolean[] custom = { false, false, false, false };
public boolean[] jsDpad = { false, false, false, false };
public int[] name = { -1, -1, -1, -1 };
private Gamepad gamepad;
public boolean isXperiaPlay;
public boolean isOuyaOrTV;
public static byte[] syms;
float[] globalLS_X = new float[4], globalLS_Y = new float[4],
private String[] portId = { "_A", "_B", "_C", "_D" };
private boolean[] compat = { false, false, false, false };
private boolean[] custom = { false, false, false, false };
private int[] name = { -1, -1, -1, -1 };
private float[] globalLS_X = new float[4], globalLS_Y = new float[4],
previousLS_X = new float[4], previousLS_Y = new float[4];
private int map[][] = new int[4][];
public static HashMap<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
public static HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
int map[][];
static byte[] syms;
private SparseArray<String> deviceId_deviceDescriptor = new SparseArray<String>();
private HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
@Override
protected void onCreate(Bundle icicle) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
moga.onCreate(this);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
menu = new OnScreenMenu(GL2JNIActivity.this, prefs);
gamepad = new Gamepad(GL2JNIActivity.this);
isXperiaPlay = gamepad.IsXperiaPlay();
isOuyaOrTV = gamepad.IsOuyaOrTV();
Gamepad.isXperiaPlay = Gamepad.IsXperiaPlay();
Gamepad.isOuyaOrTV = Gamepad.IsOuyaOrTV(GL2JNIActivity.this);
// isNvidiaShield = Gamepad.IsNvidiaShield();
/*
* try { //int rID =
@ -93,8 +86,7 @@ public class GL2JNIActivity extends Activity {
// Call parent onCreate()
super.onCreate(icicle);
OuyaController.init(this);
map = new int[4][];
moga.onCreate(this, deviceId_deviceDescriptor, deviceDescriptor_PlayerNum);
// Populate device descriptor-to-player-map from preferences
deviceDescriptor_PlayerNum.put(
@ -160,41 +152,28 @@ public class GL2JNIActivity extends Activity {
String id = portId[playerNum];
custom[playerNum] = prefs.getBoolean("modified_key_layout" + id, false);
compat[playerNum] = prefs.getBoolean("controller_compat" + id, false);
jsDpad[playerNum] = prefs.getBoolean("dpad_js_layout" + id, false);
if (!compat[playerNum]) {
if (custom[playerNum]) {
map[playerNum] = gamepad.setModifiedKeys(id, playerNum);
if (jsDpad[playerNum]) {
initJoyStickLayout(playerNum);
}
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
} else if (InputDevice.getDevice(joy).getName()
.equals("Sony PLAYSTATION(R)3 Controller")) {
map[playerNum] = gamepad.getConsoleController();
map[playerNum] = Gamepad.getConsoleController();
} else if (InputDevice.getDevice(joy).getName()
.equals("Microsoft X-Box 360 pad")) {
map[playerNum] = gamepad.getConsoleController();
jsDpad[playerNum] = true;
initJoyStickLayout(playerNum);
map[playerNum] = Gamepad.getConsoleController();
} else if (InputDevice.getDevice(joy).getName()
.contains("NVIDIA Corporation NVIDIA Controller")) {
map[playerNum] = gamepad.getConsoleController();
jsDpad[playerNum] = true;
initJoyStickLayout(playerNum);
map[playerNum] = Gamepad.getConsoleController();
} else if (InputDevice.getDevice(joy).getName()
.contains("keypad-zeus")) {
map[playerNum] = gamepad.getXPlayController();
initJoyStickLayout(playerNum);
} else if (!moga.isActive[playerNum]) { // Ouya controller
map[playerNum] = gamepad.getOUYAController();
map[playerNum] = Gamepad.getXPlayController();
} else if (!moga.isActiveMoga[playerNum]) { // Ouya controller
map[playerNum] = Gamepad.getOUYAController();
}
} else {
getCompatibilityMap(playerNum, id);
}
initJoyStickLayout(playerNum);
}
}
if (joys.length == 0) {
@ -216,9 +195,9 @@ public class GL2JNIActivity extends Activity {
=======
String menu_spec;
if (isXperiaPlay) {
if (Gamepad.isXperiaPlay) {
menu_spec = getApplicationContext().getString(R.string.menu_button);
} else if (isOuyaOrTV) {
} else if (Gamepad.isOuyaOrTV) {
menu_spec = getApplicationContext().getString(R.string.right_button);
} else {
menu_spec = getApplicationContext().getString(R.string.back_button);
@ -272,6 +251,7 @@ public class GL2JNIActivity extends Activity {
for (int n = 0; n < 4; n++) {
if (compat[n]) {
getCompatibilityMap(n, portId[n]);
initJoyStickLayout(n);
}
}
}
@ -279,10 +259,7 @@ public class GL2JNIActivity extends Activity {
private void getCompatibilityMap(int playerNum, String id) {
name[playerNum] = prefs.getInt("controller" + id, -1);
if (name[playerNum] != -1) {
map[playerNum] = gamepad.setModifiedKeys(id, playerNum);
}
if (jsDpad[playerNum]) {
initJoyStickLayout(playerNum);
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
}
}
@ -304,7 +281,11 @@ public class GL2JNIActivity extends Activity {
if (playerNum == null || playerNum == -1)
return false;
if (!moga.isActive[playerNum] || compat[playerNum]) {
if (moga.isActiveMoga[playerNum]) {
return false;
}
if (compat[playerNum]) {
// TODO: Moga should handle this locally
// Joystick
@ -318,23 +299,21 @@ public class GL2JNIActivity extends Activity {
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
float R2 = event.getAxisValue(OuyaController.AXIS_R2);
if (jsDpad[playerNum]) {
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = LS_X;
globalLS_Y[playerNum] = LS_Y;
}
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = LS_X;
globalLS_Y[playerNum] = LS_Y;
if (prefs.getBoolean("right_buttons", true)) {
if (RS_Y > 0.5) {
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][gamepad.key_CONT_B];
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][Gamepad.key_CONT_B];
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][Gamepad.key_CONT_A];
} else if (RS_Y < 0.5) {
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][gamepad.key_CONT_B];
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][Gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][Gamepad.key_CONT_B];
} else {
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][gamepad.key_CONT_B];
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][Gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][Gamepad.key_CONT_B];
}
} else {
if (RS_Y > 0) {
@ -353,8 +332,8 @@ public class GL2JNIActivity extends Activity {
}
mView.pushInput();
if ((jsDpad[playerNum])
&& ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum]) || (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f)))
if ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum])
|| (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f))
// Only handle Left Stick on an Xbox 360 controller if there was
// some actual motion on the stick,
// so otherwise the event can be handled as a DPAD event
@ -412,25 +391,23 @@ public class GL2JNIActivity extends Activity {
boolean handle_key(Integer playerNum, int kc, boolean down) {
if (playerNum == null || playerNum == -1)
return false;
if (!moga.isActive[playerNum]) {
boolean rav = false;
for (int i = 0; i < map[playerNum].length; i += 2) {
if (map[playerNum][i + 0] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
else
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
rav = true;
break;
}
}
mView.pushInput();
return rav;
} else {
return true;
if (moga.isActiveMoga[playerNum]) {
return false;
}
boolean rav = false;
for (int i = 0; i < map[playerNum].length; i += 2) {
if (map[playerNum][i + 0] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
else
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
rav = true;
break;
}
}
mView.pushInput();
return rav;
}
public void displayPopUp(PopupWindow popUp) {
@ -562,7 +539,7 @@ public class GL2JNIActivity extends Activity {
=======
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (isXperiaPlay) {
if (Gamepad.isXperiaPlay) {
return true;
} else {
>>>>>>> Support "Select" as menu, Mapping, "Menu" hardware key

View File

@ -31,7 +31,6 @@ import com.reicast.emulator.config.ConfigureFragment;
import com.reicast.emulator.config.InputFragment;
import com.reicast.emulator.config.OptionsFragment;
import com.reicast.emulator.debug.GenerateLogs;
import com.reicast.emulator.emu.GL2JNIActivity;
import com.reicast.emulator.emu.JNIdc;
public class MainActivity extends SlidingFragmentActivity implements

View File

@ -1,5 +1,7 @@
package com.reicast.emulator.config;
import java.util.HashMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -12,6 +14,7 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.util.SparseArray;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -31,6 +34,7 @@ import com.bda.controller.MotionEvent;
import com.bda.controller.StateEvent;
import com.reicast.emulator.MainActivity;
import com.reicast.emulator.R;
import com.reicast.emulator.periph.Gamepad;
import com.reicast.emulator.periph.MOGAInput;
import de.ankri.views.Switch;
@ -43,7 +47,6 @@ public class InputFragment extends Fragment {
private SharedPreferences sharedPreferences;
private Switch switchTouchVibrationEnabled;
private Switch micPluggedIntoFirstController;
public MOGAInput moga = new MOGAInput();
// Container Activity must implement this interface
@ -62,7 +65,7 @@ public class InputFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
parentActivity = getActivity();
moga.onCreate(parentActivity);
moga.onCreate(parentActivity, new SparseArray<String>(), new HashMap<String, Integer>());
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(parentActivity);
@ -362,7 +365,7 @@ public class InputFragment extends Fragment {
String descriptor = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (moga.isActive[listenForButton]) {
if (moga.isActiveMoga[listenForButton]) {
MogaListener config = new MogaListener(listenForButton);
moga.mController.setListener(config, new Handler());
descriptor = config.getController();
@ -459,9 +462,9 @@ public class InputFragment extends Fragment {
if (event.getState() == StateEvent.STATE_CONNECTION && event.getAction() == MOGAInput.ACTION_CONNECTED) {
int mControllerVersion = moga.mController.getState(Controller.STATE_CURRENT_PRODUCT_VERSION);
if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) {
moga.isActive[playerNum] = true;
moga.isActiveMoga[playerNum] = true;
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
moga.isActive[playerNum] = true;
moga.isActiveMoga[playerNum] = true;
}
}
}

View File

@ -267,44 +267,7 @@ public class InputModFragment extends Fragment {
}
});
final TextView joystick_text = (TextView) getView().findViewById(
R.id.joystick_key);
getKeyCode("joystick", joystick_text);
Button joystick = (Button) getView().findViewById(R.id.joystick_edit);
joystick.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mKey.intiateSearch("joystick", joystick_text);
}
});
Button joystick_remove = (Button) getView().findViewById(
R.id.remove_joystick);
joystick_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("joystick", joystick_text);
}
});
joystick.setEnabled(false);
mPrefs.edit().remove("joystick").commit();
// Still needs better support for identifying the entire stick
OnCheckedChangeListener dpad_joystick = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("dpad_js_layout" + player, isChecked)
.commit();
}
};
Switch dpad_js_layout = (Switch) getView().findViewById(
R.id.dpad_js_layout);
boolean joypad = mPrefs.getBoolean("dpad_js_layout" + player, false);
if (joypad) {
dpad_js_layout.setChecked(true);
} else {
dpad_js_layout.setChecked(false);
}
dpad_js_layout.setOnCheckedChangeListener(dpad_joystick);
final TextView dpad_up_text = (TextView) getView().findViewById(
final TextView dpad_up_text = (TextView) getView().findViewById(
R.id.dpad_up_key);
getKeyCode("dpad_up", dpad_up_text);
Button dpad_up = (Button) getView().findViewById(R.id.dpad_up_edit);

View File

@ -28,6 +28,7 @@ import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.view.View;
import com.reicast.emulator.GL2JNIActivity;
import com.reicast.emulator.config.ConfigureFragment;
import com.reicast.emulator.emu.OnScreenMenu.FpsPopup;
import com.reicast.emulator.periph.VJoy;

View File

@ -18,6 +18,7 @@ import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.reicast.emulator.GL2JNIActivity;
import com.reicast.emulator.MainActivity;
import com.reicast.emulator.R;
import com.reicast.emulator.config.ConfigureFragment;

View File

@ -5,30 +5,25 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
public class Gamepad {
public static boolean isXperiaPlay;
public static boolean isOuyaOrTV;
// public boolean isNvidiaShield;
public final int key_CONT_B = 0x0002;
public final int key_CONT_A = 0x0004;
public final int key_CONT_START = 0x0008;
public final int key_CONT_DPAD_UP = 0x0010;
public final int key_CONT_DPAD_DOWN = 0x0020;
public final int key_CONT_DPAD_LEFT = 0x0040;
public final int key_CONT_DPAD_RIGHT = 0x0080;
public final int key_CONT_Y = 0x0200;
public final int key_CONT_X = 0x0400;
public static final int key_CONT_B = 0x0002;
public static final int key_CONT_A = 0x0004;
public static final int key_CONT_START = 0x0008;
public static final int key_CONT_DPAD_UP = 0x0010;
public static final int key_CONT_DPAD_DOWN = 0x0020;
public static final int key_CONT_DPAD_LEFT = 0x0040;
public static final int key_CONT_DPAD_RIGHT = 0x0080;
public static final int key_CONT_Y = 0x0200;
public static final int key_CONT_X = 0x0400;
private SharedPreferences mPrefs;
private Context mContext;
public Gamepad(Context mContext) {
this.mContext = mContext;
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
}
public int[] getConsoleController() {
public static int[] getConsoleController() {
return new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
@ -46,7 +41,7 @@ public class Gamepad {
};
}
public int[] getXPlayController() {
public static int[] getXPlayController() {
return new int[] {
KeyEvent.KEYCODE_DPAD_CENTER, key_CONT_A,
KeyEvent.KEYCODE_BACK, key_CONT_B,
@ -64,7 +59,7 @@ public class Gamepad {
};
}
public int[] getOUYAController() {
public static int[] getOUYAController() {
return new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
@ -92,7 +87,7 @@ public class Gamepad {
};
}
public int[] getMogaController() {
public static int[] getMogaController() {
return new int[] {
KeyEvent.KEYCODE_BUTTON_B, key_CONT_B,
KeyEvent.KEYCODE_BUTTON_A, key_CONT_A,
@ -106,27 +101,27 @@ public class Gamepad {
getStartButtonCode(), key_CONT_START,
getSelectButtonCode(), getSelectButtonCode()
// Redundant, but verifies it is mapped properly
};
}
public int[] setModifiedKeys(String id, int playerNum) {
public static int[] setModifiedKeys(String id, int playerNum, SharedPreferences mPrefs) {
return new int[] {
mPrefs.getInt("a_button" + id, OuyaController.BUTTON_O), key_CONT_A,
mPrefs.getInt("b_button" + id, OuyaController.BUTTON_A), key_CONT_B,
mPrefs.getInt("x_button" + id, OuyaController.BUTTON_U), key_CONT_X,
mPrefs.getInt("y_button" + id, OuyaController.BUTTON_Y), key_CONT_Y,
mPrefs.getInt("a_button" + id, OuyaController.BUTTON_O), key_CONT_A,
mPrefs.getInt("b_button" + id, OuyaController.BUTTON_A), key_CONT_B,
mPrefs.getInt("x_button" + id, OuyaController.BUTTON_U), key_CONT_X,
mPrefs.getInt("y_button" + id, OuyaController.BUTTON_Y), key_CONT_Y,
mPrefs.getInt("dpad_up" + id, OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
mPrefs.getInt("dpad_down" + id, OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
mPrefs.getInt("dpad_left" + id, OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
mPrefs.getInt("dpad_right" + id, OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
mPrefs.getInt("dpad_up" + id, OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
mPrefs.getInt("dpad_down" + id, OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
mPrefs.getInt("dpad_left" + id, OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
mPrefs.getInt("dpad_right" + id, OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
mPrefs.getInt("start_button" + id, getStartButtonCode()), key_CONT_START,
mPrefs.getInt("select_button" + id, getSelectButtonCode()), getSelectButtonCode()
};
}
public boolean IsXperiaPlay() {
public static boolean IsXperiaPlay() {
return android.os.Build.MODEL.equals("R800a")
|| android.os.Build.MODEL.equals("R800i")
|| android.os.Build.MODEL.equals("R800x")
@ -135,8 +130,8 @@ public class Gamepad {
|| android.os.Build.MODEL.equals("zeus");
}
public boolean IsOuyaOrTV() {
PackageManager pMan = mContext.getPackageManager();
public static boolean IsOuyaOrTV(Context context) {
PackageManager pMan = context.getPackageManager();
if (pMan.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
return true;
}

View File

@ -3,10 +3,13 @@ package com.reicast.emulator.periph;
/******************************************************************************/
import java.util.HashMap;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.SparseArray;
import android.widget.Toast;
import com.bda.controller.Controller;
@ -15,7 +18,6 @@ import com.bda.controller.KeyEvent;
import com.bda.controller.MotionEvent;
import com.bda.controller.StateEvent;
import com.reicast.emulator.R;
import com.reicast.emulator.emu.GL2JNIActivity;
import com.reicast.emulator.emu.GL2JNIView;
import com.reicast.emulator.emu.JNIdc;
@ -35,24 +37,22 @@ public class MOGAInput
static final int ACTION_VERSION_MOGA = Controller.ACTION_VERSION_MOGA;
static final int ACTION_VERSION_MOGAPRO = Controller.ACTION_VERSION_MOGAPRO;
public boolean isActiveMoga[] = { false, false, false, false };
public boolean isMogaPro[] = { false, false, false, false };
private String[] portId = { "_A", "_B", "_C", "_D" };
private boolean[] custom = { false, false, false, false };
private float[] globalLS_X = new float[4], globalLS_Y = new float[4],
previousLS_X = new float[4], previousLS_Y = new float[4];
private int map[][] = new int[4][];
private SparseArray<String> deviceId_deviceDescriptor;
private HashMap<String, Integer> deviceDescriptor_PlayerNum;
public Controller mController = null;
private Handler handler;
private String notify;
private Gamepad gamepad;
static String[] portId = { "_A", "_B", "_C", "_D" };
static boolean[] custom = { false, false, false, false },
jsCompat = { false, false, false, false };
float[] globalLS_X = new float[4], globalLS_Y = new float[4],
previousLS_X = new float[4], previousLS_Y = new float[4];
public boolean isActive[] = { false, false, false, false };
public boolean isMogaPro[] = { false, false, false, false };
int map[][];
Activity act;
public MOGAInput()
{
@ -88,16 +88,18 @@ public class MOGAInput
*/
}
public void onCreate(Activity act)
{
public void onCreate(Activity act,
SparseArray<String> deviceId_deviceDescriptor,
HashMap<String, Integer> deviceDescriptor_PlayerNum) {
this.act = act;
this.deviceId_deviceDescriptor = deviceId_deviceDescriptor;
this.deviceDescriptor_PlayerNum = deviceDescriptor_PlayerNum;
handler = new Handler();
prefs = PreferenceManager
.getDefaultSharedPreferences(act.getApplicationContext());
gamepad = new Gamepad(act);
mController = Controller.getInstance(act);
mController.init();
mController.setListener(new ExampleControllerListener(), new Handler());
@ -145,14 +147,14 @@ public class MOGAInput
{
public void onKeyEvent(KeyEvent event)
{
Integer playerNum = GL2JNIActivity.deviceDescriptor_PlayerNum.get(GL2JNIActivity.deviceId_deviceDescriptor.get(event.getControllerId()));
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getControllerId()));
if (playerNum == null)
return;
String id = portId[playerNum];
if (custom[playerNum]) {
if (event.getKeyCode() == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
if (event.getKeyCode() == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
simulatedTouchEvent(playerNum, 1.0f, 0.0f);
simulatedTouchEvent(playerNum, 0.0f, 0.0f);
}
@ -179,12 +181,10 @@ public class MOGAInput
public void simulatedTouchEvent(int playerNum, float L2, float R2) {
if(playerNum == 0)
JNIdc.hide_osd();
if (jsCompat[playerNum]) {
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = 0;
globalLS_Y[playerNum] = 0;
}
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = 0;
globalLS_Y[playerNum] = 0;
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.jx[playerNum] = (int) (0 * 126);
@ -193,7 +193,7 @@ public class MOGAInput
public void onMotionEvent(MotionEvent event)
{
Integer playerNum = GL2JNIActivity.deviceDescriptor_PlayerNum.get(GL2JNIActivity.deviceId_deviceDescriptor.get(event.getControllerId()));
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getControllerId()));
if (playerNum == null)
return;
@ -205,15 +205,11 @@ public class MOGAInput
float S_Y = event.getAxisValue(MotionEvent.AXIS_Y);
float L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
float R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
if (jsCompat[playerNum]) {
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = S_X;
globalLS_Y[playerNum] = S_Y;
}
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = S_X;
globalLS_Y[playerNum] = S_Y;
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
@ -232,7 +228,7 @@ public class MOGAInput
public void onStateEvent(StateEvent event)
{
Integer playerNum = GL2JNIActivity.deviceDescriptor_PlayerNum.get(GL2JNIActivity.deviceId_deviceDescriptor.get(event.getControllerId()));
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getControllerId()));
if (playerNum == null)
return;
@ -242,26 +238,25 @@ public class MOGAInput
String id = portId[playerNum];
custom[playerNum] = prefs.getBoolean("modified_key_layout" + id, false);
jsCompat[playerNum] = prefs.getBoolean("dpad_js_layout" + id, false);
if (event.getState() == StateEvent.STATE_CONNECTION && event.getAction() == ACTION_CONNECTED) {
int mControllerVersion = mController.getState(Controller.STATE_CURRENT_PRODUCT_VERSION);
if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) {
isActive[playerNum] = true;
isActiveMoga[playerNum] = true;
isMogaPro[playerNum] = true;
if (custom[playerNum]) {
map[playerNum] = gamepad.setModifiedKeys(id, playerNum);
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
} else {
map[playerNum] = gamepad.getMogaController();
map[playerNum] = Gamepad.getMogaController();
}
notify = act.getApplicationContext().getString(R.string.moga_pro_connect);
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
isActive[playerNum] = true;
isActiveMoga[playerNum] = true;
isMogaPro[playerNum] = false;
if (custom[playerNum]) {
map[playerNum] = gamepad.setModifiedKeys(id, playerNum);
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
} else {
map[playerNum] = gamepad.getMogaController();
map[playerNum] = Gamepad.getMogaController();
}
notify = act.getApplicationContext().getString(R.string.moga_connect);
}