Another instance of controller simplification, Not-static class

This commit is contained in:
TwistedUmbrella 2014-02-24 09:11:55 -05:00
parent 6d82495ed5
commit 0a95f966d5
11 changed files with 1508 additions and 997 deletions

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:gravity="right"
android:singleLine="true"
android:textColor="#ffffff" />

View File

@ -14,7 +14,6 @@ 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;
@ -26,6 +25,7 @@ import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.reicast.emulator.config.Config;
import com.reicast.emulator.emu.GL2JNIView;
import com.reicast.emulator.emu.JNIdc;
import com.reicast.emulator.emu.OnScreenMenu;
@ -45,30 +45,24 @@ public class GL2JNIActivity extends Activity {
FpsPopup fpsPop;
MOGAInput moga = new MOGAInput();
private SharedPreferences prefs;
private Config config;
private Gamepad pad = new Gamepad();
public static byte[] syms;
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][];
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);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
config = new Config(GL2JNIActivity.this);
config.getConfigurationPrefs();
menu = new OnScreenMenu(GL2JNIActivity.this, prefs);
Gamepad.isXperiaPlay = Gamepad.IsXperiaPlay();
Gamepad.isOuyaOrTV = Gamepad.IsOuyaOrTV(GL2JNIActivity.this);
// isNvidiaShield = Gamepad.IsNvidiaShield();
pad.isXperiaPlay = pad.IsXperiaPlay();
pad.isOuyaOrTV = pad.IsOuyaOrTV(GL2JNIActivity.this);
// pad.isNvidiaShield = pad.IsNvidiaShield();
/*
* try { //int rID =
@ -86,24 +80,24 @@ public class GL2JNIActivity extends Activity {
// Call parent onCreate()
super.onCreate(icicle);
OuyaController.init(this);
moga.onCreate(this, deviceId_deviceDescriptor, deviceDescriptor_PlayerNum);
moga.onCreate(this, pad);
// Populate device descriptor-to-player-map from preferences
deviceDescriptor_PlayerNum.put(
pad.deviceDescriptor_PlayerNum.put(
prefs.getString("device_descriptor_player_1", null), 0);
deviceDescriptor_PlayerNum.put(
pad.deviceDescriptor_PlayerNum.put(
prefs.getString("device_descriptor_player_2", null), 1);
deviceDescriptor_PlayerNum.put(
pad.deviceDescriptor_PlayerNum.put(
prefs.getString("device_descriptor_player_3", null), 2);
deviceDescriptor_PlayerNum.put(
pad.deviceDescriptor_PlayerNum.put(
prefs.getString("device_descriptor_player_4", null), 3);
deviceDescriptor_PlayerNum.remove(null);
pad.deviceDescriptor_PlayerNum.remove(null);
boolean controllerTwoConnected = false;
boolean controllerThreeConnected = false;
boolean controllerFourConnected = false;
for (HashMap.Entry<String, Integer> e : deviceDescriptor_PlayerNum
for (HashMap.Entry<String, Integer> e : pad.deviceDescriptor_PlayerNum
.entrySet()) {
String descriptor = e.getKey();
Integer playerNum = e.getValue();
@ -141,34 +135,34 @@ public class GL2JNIActivity extends Activity {
"InputDevice Name: "
+ InputDevice.getDevice(joy).getName());
Log.d("reidc", "InputDevice Descriptor: " + descriptor);
deviceId_deviceDescriptor.put(joy, descriptor);
pad.deviceId_deviceDescriptor.put(joy, descriptor);
}
for (int joy :joys) {
Integer playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(joy));
Integer playerNum = pad.deviceDescriptor_PlayerNum
.get(pad.deviceId_deviceDescriptor.get(joy));
if (playerNum != null) {
String id = portId[playerNum];
custom[playerNum] = prefs.getBoolean("modified_key_layout" + id, false);
compat[playerNum] = prefs.getBoolean("controller_compat" + id, false);
if (!compat[playerNum]) {
if (custom[playerNum]) {
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
String id = pad.portId[playerNum];
pad.custom[playerNum] = prefs.getBoolean("modified_key_layout" + id, false);
pad.compat[playerNum] = prefs.getBoolean("controller_compat" + id, false);
if (!pad.compat[playerNum]) {
if (pad.custom[playerNum]) {
pad.map[playerNum] = pad.setModifiedKeys(id, playerNum, prefs);
} else if (InputDevice.getDevice(joy).getName()
.equals("Sony PLAYSTATION(R)3 Controller")) {
map[playerNum] = Gamepad.getConsoleController();
pad.map[playerNum] = pad.getConsoleController();
} else if (InputDevice.getDevice(joy).getName()
.equals("Microsoft X-Box 360 pad")) {
map[playerNum] = Gamepad.getConsoleController();
pad.map[playerNum] = pad.getConsoleController();
} else if (InputDevice.getDevice(joy).getName()
.contains("NVIDIA Corporation NVIDIA Controller")) {
map[playerNum] = Gamepad.getConsoleController();
pad.map[playerNum] = pad.getConsoleController();
} else if (InputDevice.getDevice(joy).getName()
.contains("keypad-zeus")) {
map[playerNum] = Gamepad.getXPlayController();
} else if (!moga.isActiveMoga[playerNum]) { // Ouya controller
map[playerNum] = Gamepad.getOUYAController();
pad.map[playerNum] = pad.getXPlayController();
} else if (!pad.isActiveMoga[playerNum]) { // Ouya controller
pad.map[playerNum] = pad.getOUYAController();
}
} else {
getCompatibilityMap(playerNum, id);
@ -189,15 +183,15 @@ public class GL2JNIActivity extends Activity {
fileName = Uri.decode(intent.getData().toString());
// Create the actual GLES view
mView = new GL2JNIView(getApplication(), fileName, false, prefs.getInt("depth_render", 24), 0, false);
mView = new GL2JNIView(getApplication(), config, fileName, false, prefs.getInt("depth_render", 24), 0, false);
setContentView(mView);
<<<<<<< HEAD
=======
String menu_spec;
if (Gamepad.isXperiaPlay) {
if (pad.isXperiaPlay) {
menu_spec = getApplicationContext().getString(R.string.menu_button);
} else if (Gamepad.isOuyaOrTV) {
} else if (pad.isOuyaOrTV) {
menu_spec = getApplicationContext().getString(R.string.right_button);
} else {
menu_spec = getApplicationContext().getString(R.string.back_button);
@ -243,23 +237,23 @@ public class GL2JNIActivity extends Activity {
}
private void initJoyStickLayout(int playerNum) {
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
pad.globalLS_X[playerNum] = pad.previousLS_X[playerNum] = 0.0f;
pad.globalLS_Y[playerNum] = pad.previousLS_Y[playerNum] = 0.0f;
}
private void runCompatibilityMode() {
for (int n = 0; n < 4; n++) {
if (compat[n]) {
getCompatibilityMap(n, portId[n]);
if (pad.compat[n]) {
getCompatibilityMap(n, pad.portId[n]);
initJoyStickLayout(n);
}
}
}
private void getCompatibilityMap(int playerNum, String id) {
name[playerNum] = prefs.getInt("controller" + id, -1);
if (name[playerNum] != -1) {
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
pad.name[playerNum] = prefs.getInt("controller" + id, -1);
if (pad.name[playerNum] != -1) {
pad.map[playerNum] = pad.setModifiedKeys(id, playerNum, prefs);
}
}
@ -270,10 +264,10 @@ public class GL2JNIActivity extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Integer playerNum = Arrays.asList(name).indexOf(event.getDeviceId());
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getDeviceId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
playerNum = pad.deviceDescriptor_PlayerNum
.get(pad.deviceId_deviceDescriptor.get(event.getDeviceId()));
} else {
playerNum = -1;
}
@ -281,11 +275,11 @@ public class GL2JNIActivity extends Activity {
if (playerNum == null || playerNum == -1)
return false;
if (moga.isActiveMoga[playerNum]) {
if (pad.isActiveMoga[playerNum]) {
return false;
}
if (compat[playerNum]) {
if (!pad.compat[playerNum]) {
// TODO: Moga should handle this locally
// Joystick
@ -299,21 +293,21 @@ public class GL2JNIActivity extends Activity {
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
float R2 = event.getAxisValue(OuyaController.AXIS_R2);
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = LS_X;
globalLS_Y[playerNum] = LS_Y;
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
pad.globalLS_X[playerNum] = LS_X;
pad.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] |= pad.map[playerNum][Gamepad.key_CONT_B];
GL2JNIView.kcode_raw[playerNum] &= ~pad.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] |= pad.map[playerNum][Gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] &= ~pad.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] |= pad.map[playerNum][Gamepad.key_CONT_A];
GL2JNIView.kcode_raw[playerNum] |= pad.map[playerNum][Gamepad.key_CONT_B];
}
} else {
if (RS_Y > 0) {
@ -332,8 +326,8 @@ public class GL2JNIActivity extends Activity {
}
mView.pushInput();
if ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum])
|| (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f))
if ((pad.globalLS_X[playerNum] == pad.previousLS_X[playerNum] && pad.globalLS_Y[playerNum] == pad.previousLS_Y[playerNum])
|| (pad.previousLS_X[playerNum] == 0.0f && pad.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
@ -391,23 +385,24 @@ public class GL2JNIActivity extends Activity {
boolean handle_key(Integer playerNum, int kc, boolean down) {
if (playerNum == null || playerNum == -1)
return false;
if (moga.isActiveMoga[playerNum]) {
if (pad.isActiveMoga[playerNum]) {
return false;
}
boolean rav = false;
for (int i = 0; i < map[playerNum].length; i += 2) {
if (map[playerNum][i + 0] == kc) {
for (int i = 0; i < pad.map[playerNum].length; i += 2) {
if (pad.map[playerNum][i + 0] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
GL2JNIView.kcode_raw[playerNum] &= ~pad.map[playerNum][i + 1];
else
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
GL2JNIView.kcode_raw[playerNum] |= pad.map[playerNum][i + 1];
rav = true;
break;
}
}
mView.pushInput();
return rav;
}
public void displayPopUp(PopupWindow popUp) {
@ -470,17 +465,17 @@ public class GL2JNIActivity extends Activity {
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
Integer playerNum = Arrays.asList(name).indexOf(event.getDeviceId());
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getDeviceId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
playerNum = pad.deviceDescriptor_PlayerNum
.get(pad.deviceId_deviceDescriptor.get(event.getDeviceId()));
} else {
playerNum = -1;
}
if (playerNum != null && playerNum != -1) {
if (compat[playerNum] || custom[playerNum]) {
String id = portId[playerNum];
if (pad.compat[playerNum] || pad.custom[playerNum]) {
String id = pad.portId[playerNum];
if (keyCode == prefs.getInt("l_button" + id,
KeyEvent.KEYCODE_BUTTON_L1)
|| keyCode == prefs.getInt("r_button" + id,
@ -495,17 +490,17 @@ public class GL2JNIActivity extends Activity {
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
Integer playerNum = Arrays.asList(name).indexOf(event.getDeviceId());
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getDeviceId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
playerNum = pad.deviceDescriptor_PlayerNum
.get(pad.deviceId_deviceDescriptor.get(event.getDeviceId()));
} else {
playerNum = -1;
}
if (playerNum != null && playerNum != -1) {
if (compat[playerNum] || custom[playerNum]) {
String id = portId[playerNum];
if (pad.compat[playerNum] || pad.custom[playerNum]) {
String id = pad.portId[playerNum];
if (keyCode == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
return simulatedTouchEvent(playerNum, 1.0f, 0.0f);
}
@ -539,7 +534,7 @@ public class GL2JNIActivity extends Activity {
=======
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (Gamepad.isXperiaPlay) {
if (pad.isXperiaPlay) {
return true;
} else {
>>>>>>> Support "Select" as menu, Mapping, "Menu" hardware key

View File

@ -0,0 +1,75 @@
package com.reicast.emulator.config;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.android.util.DreamTime;
import com.reicast.emulator.emu.JNIdc;
public class Config {
public static boolean dynarecopt = true;
public static boolean idleskip = true;
public static boolean unstableopt = false;
public static int cable = 3;
public static int dcregion = 3;
public static int broadcast = 4;
public static boolean limitfps = true;
public static boolean nobatch = false;
public static boolean mipmaps = true;
public static boolean widescreen = false;
public static boolean subdivide = false;
public static int frameskip = 0;
public static boolean pvrrender = false;
public static String cheatdisk = "null";
private SharedPreferences mPrefs;
public Config(Context mContext) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
}
/**
* Load the user configuration from preferences
*
* @param sharedpreferences
* The preference instance to load values from
*/
public void getConfigurationPrefs() {
Config.dynarecopt = mPrefs.getBoolean("dynarec_opt", dynarecopt);
Config.unstableopt = mPrefs.getBoolean("unstable_opt", unstableopt);
Config.cable = mPrefs.getInt("dc_cable", cable);
Config.dcregion = mPrefs.getInt("dc_region", dcregion);
Config.broadcast = mPrefs.getInt("dc_broadcast", broadcast);
Config.limitfps = mPrefs.getBoolean("limit_fps", limitfps);
Config.mipmaps = mPrefs.getBoolean("use_mipmaps", mipmaps);
Config.widescreen = mPrefs.getBoolean("stretch_view", widescreen);
Config.frameskip = mPrefs.getInt("frame_skip", frameskip);
Config.pvrrender = mPrefs.getBoolean("pvr_render", pvrrender);
Config.cheatdisk = mPrefs.getString("cheat_disk", cheatdisk);
}
/**
* Write configuration settings to the emulator
*
*/
public void loadConfigurationPrefs() {
JNIdc.dynarec(Config.dynarecopt ? 1 : 0);
JNIdc.idleskip(Config.idleskip ? 1 : 0);
JNIdc.unstable(Config.unstableopt ? 1 : 0);
JNIdc.cable(Config.cable);
JNIdc.region(Config.dcregion);
JNIdc.broadcast(Config.broadcast);
JNIdc.limitfps(Config.limitfps ? 1 : 0);
JNIdc.nobatch(Config.nobatch ? 1 : 0);
JNIdc.mipmaps(Config.mipmaps ? 1 : 0);
JNIdc.widescreen(Config.widescreen ? 1 : 0);
JNIdc.subdivide(Config.subdivide ? 1 : 0);
JNIdc.frameskip(Config.frameskip);
JNIdc.pvrrender(Config.pvrrender ? 1 : 0);
JNIdc.cheatdisk(Config.cheatdisk);
JNIdc.dreamtime(DreamTime.getDreamtime());
}
}

View File

@ -2,6 +2,8 @@ package com.reicast.emulator.config;
import java.io.File;
import org.apache.commons.lang3.ArrayUtils;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.AsyncTask;
@ -12,7 +14,6 @@ import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -27,36 +28,17 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import com.android.util.DreamTime;
import com.reicast.emulator.R;
import com.reicast.emulator.debug.GenerateLogs;
import com.reicast.emulator.emu.GL2JNIView;
import com.reicast.emulator.emu.JNIdc;
import de.ankri.views.Switch;
public class ConfigureFragment extends Fragment {
Activity parentActivity;
TextView mainFrames;
OnClickListener mCallback;
/*
* default settings for emu-cfg
*/
public static boolean dynarecopt = true;
public static boolean idleskip = true;
public static boolean unstableopt = false;
public static int cable = 3;
public static int dcregion = 3;
public static int broadcast = 4;
public static boolean limitfps = true;
public static boolean nobatch = false;
public static boolean mipmaps = true;
public static boolean widescreen = false;
public static boolean subdivide = false;
public static int frameskip = 0;
public static boolean pvrrender = false;
public static String cheatdisk = "null";
private Config config;
private SharedPreferences mPrefs;
private File sdcard = Environment.getExternalStorageDirectory();
@ -82,32 +64,199 @@ public class ConfigureFragment extends Fragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// setContentView(R.layout.activity_main);
parentActivity = getActivity();
mPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
home_directory = mPrefs.getString("home_directory", home_directory);
loadCfgSettingsFromPrefs(mPrefs);
/*
* section for all non-emu-cfg settings
*/
final Switch fps_opt = (Switch) getView().findViewById(
R.id.fps_option);
OnCheckedChangeListener fps_options = new OnCheckedChangeListener() {
config = new Config(parentActivity);
config.getConfigurationPrefs();
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("show_fps", isChecked).commit();
// Generate the menu options and fill in existing settings
OnCheckedChangeListener dynarec_options = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("dynarec_opt", isChecked).commit();
Config.dynarecopt = isChecked;
}
};
Switch dynarec_opt = (Switch) getView().findViewById(
R.id.dynarec_option);
dynarec_opt.setChecked(Config.dynarecopt);
dynarec_opt.setOnCheckedChangeListener(dynarec_options);
OnCheckedChangeListener unstable_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("unstable_opt", isChecked).commit();
Config.unstableopt = isChecked;
}
};
Switch unstable_opt = (Switch) getView().findViewById(
R.id.unstable_option);
if (Config.unstableopt) {
unstable_opt.setChecked(true);
} else {
unstable_opt.setChecked(false);
}
unstable_opt.setOnCheckedChangeListener(unstable_option);
String[] regions = ArrayUtils.remove(parentActivity.getResources()
.getStringArray(R.array.region), 4);
Spinner region_spnr = (Spinner) getView().findViewById(
R.id.region_spinner);
ArrayAdapter<String> regionAdapter = new ArrayAdapter<String>(
parentActivity, R.layout.spinner_selected, regions);
regionAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
region_spnr.setAdapter(regionAdapter);
region_spnr.setSelection(Config.dcregion, true);
region_spnr.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
mPrefs.edit().putInt("dc_region", pos).commit();
Config.dcregion = pos;
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
OnCheckedChangeListener limitfps_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("limit_fps", isChecked).commit();
Config.limitfps = isChecked;
}
};
Switch limit_fps = (Switch) getView()
.findViewById(R.id.limitfps_option);
limit_fps.setChecked(Config.limitfps);
limit_fps.setOnCheckedChangeListener(limitfps_option);
OnCheckedChangeListener mipmaps_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("use_mipmaps", isChecked).commit();
Config.mipmaps = isChecked;
}
};
Switch mipmap_opt = (Switch) getView()
.findViewById(R.id.mipmaps_option);
mipmap_opt.setChecked(Config.mipmaps);
mipmap_opt.setOnCheckedChangeListener(mipmaps_option);
OnCheckedChangeListener full_screen = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("stretch_view", isChecked).commit();
Config.widescreen = isChecked;
}
};
Switch stretch_view = (Switch) getView().findViewById(
R.id.stretch_option);
stretch_view.setChecked(Config.widescreen);
stretch_view.setOnCheckedChangeListener(full_screen);
final TextView mainFrames = (TextView) getView().findViewById(R.id.current_frames);
mainFrames.setText(String.valueOf(Config.frameskip));
SeekBar frameSeek = (SeekBar) getView()
.findViewById(R.id.frame_seekbar);
frameSeek.setProgress(Config.frameskip);
frameSeek.setIndeterminate(false);
frameSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mainFrames.setText(String.valueOf(progress));
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
mPrefs.edit().putInt("frame_skip", progress).commit();
Config.frameskip = progress;
}
});
OnCheckedChangeListener pvr_rendering = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("pvr_render", isChecked).commit();
Config.pvrrender = isChecked;
}
};
Switch pvr_render = (Switch) getView().findViewById(R.id.render_option);
pvr_render.setChecked(Config.pvrrender);
pvr_render.setOnCheckedChangeListener(pvr_rendering);
final EditText cheatEdit = (EditText) getView().findViewById(
R.id.cheat_disk);
String disk = Config.cheatdisk;
if (disk != null && disk.contains("/")) {
cheatEdit.setText(disk.substring(disk.lastIndexOf("/"),
disk.length()));
} else {
cheatEdit.setText(disk);
}
cheatEdit.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if (cheatEdit.getText() != null) {
String disk = cheatEdit.getText().toString();
if (disk != null && disk.contains("/")) {
cheatEdit.setText(disk.substring(disk.lastIndexOf("/"),
disk.length()));
} else {
cheatEdit.setText(disk);
}
mPrefs.edit().putString("cheat_disk", disk).commit();
Config.cheatdisk = disk;
}
};
boolean counter = mPrefs.getBoolean("show_fps",
false);
fps_opt.setChecked(counter);
fps_opt.setOnCheckedChangeListener(fps_options);
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
final Switch fps_opt = (Switch) getView().findViewById(R.id.fps_option);
OnCheckedChangeListener fps_options = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("show_fps", isChecked).commit();
}
};
boolean counter = mPrefs.getBoolean("show_fps", false);
fps_opt.setChecked(counter);
fps_opt.setOnCheckedChangeListener(fps_options);
final Switch force_gpu_opt = (Switch) getView().findViewById(
R.id.force_gpu_option);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
OnCheckedChangeListener force_gpu_options = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
@ -115,8 +264,7 @@ public class ConfigureFragment extends Fragment {
mPrefs.edit().putBoolean("force_gpu", isChecked).commit();
}
};
boolean enhanced = mPrefs.getBoolean("force_gpu",
true);
boolean enhanced = mPrefs.getBoolean("force_gpu", true);
force_gpu_opt.setChecked(enhanced);
force_gpu_opt.setOnCheckedChangeListener(force_gpu_options);
} else {
@ -142,11 +290,11 @@ public class ConfigureFragment extends Fragment {
};
int software = mPrefs.getInt("render_type",
GL2JNIView.LAYER_TYPE_HARDWARE);
force_software_opt.setChecked(software == GL2JNIView.LAYER_TYPE_SOFTWARE);
force_software_opt
.setChecked(software == GL2JNIView.LAYER_TYPE_SOFTWARE);
force_software_opt.setOnCheckedChangeListener(force_software);
Switch sound_opt = (Switch) getView().findViewById(
R.id.sound_option);
Switch sound_opt = (Switch) getView().findViewById(R.id.sound_option);
OnCheckedChangeListener emu_sound = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
@ -154,173 +302,9 @@ public class ConfigureFragment extends Fragment {
mPrefs.edit().putBoolean("sound_enabled", isChecked).commit();
}
};
boolean sound = mPrefs.getBoolean("sound_enabled",
true);
boolean sound = mPrefs.getBoolean("sound_enabled", true);
sound_opt.setChecked(sound);
sound_opt.setOnCheckedChangeListener(emu_sound);
/*
* section for all emu-cfg settings
*/
OnCheckedChangeListener dynarec_options = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("dynarec_opt", isChecked).commit();
ConfigureFragment.dynarecopt = isChecked;
}
};
Switch dynarec_opt = (Switch) getView().findViewById(
R.id.dynarec_option);
dynarec_opt.setChecked(ConfigureFragment.dynarecopt);
dynarec_opt.setOnCheckedChangeListener(dynarec_options);
OnCheckedChangeListener unstable_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("unstable_opt", isChecked).commit();
ConfigureFragment.unstableopt = isChecked;
}
};
Switch unstable_opt = (Switch) getView().findViewById(
R.id.unstable_option);
if (ConfigureFragment.unstableopt) {
unstable_opt.setChecked(true);
} else {
unstable_opt.setChecked(false);
}
unstable_opt.setOnCheckedChangeListener(unstable_option);
String[] regions = parentActivity.getResources().getStringArray(
R.array.region);
Spinner region_spnr = (Spinner) getView().findViewById(
R.id.region_spinner);
ArrayAdapter<String> localeAdapter = new ArrayAdapter<String>(
parentActivity, android.R.layout.simple_spinner_item, regions);
localeAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
region_spnr.setAdapter(localeAdapter);
region_spnr.setSelection(ConfigureFragment.dcregion, true);
region_spnr.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
mPrefs.edit().putInt("dc_region", pos).commit();
ConfigureFragment.dcregion = pos;
}
public void onNothingSelected(AdapterView<?> arg0) {
mPrefs.edit().putInt("dc_region", ConfigureFragment.dcregion)
.commit();
}
});
OnCheckedChangeListener limitfps_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("limit_fps", isChecked).commit();
ConfigureFragment.limitfps = isChecked;
}
};
Switch limit_fps = (Switch) getView()
.findViewById(R.id.limitfps_option);
limit_fps.setChecked(ConfigureFragment.limitfps);
limit_fps.setOnCheckedChangeListener(limitfps_option);
OnCheckedChangeListener mipmaps_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("use_mipmaps", isChecked).commit();
ConfigureFragment.mipmaps = isChecked;
}
};
Switch mipmap_opt = (Switch) getView()
.findViewById(R.id.mipmaps_option);
mipmap_opt.setChecked(ConfigureFragment.mipmaps);
mipmap_opt.setOnCheckedChangeListener(mipmaps_option);
OnCheckedChangeListener full_screen = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("stretch_view", isChecked).commit();
ConfigureFragment.widescreen = isChecked;
}
};
Switch stretch_view = (Switch) getView().findViewById(
R.id.stretch_option);
stretch_view.setChecked(ConfigureFragment.widescreen);
stretch_view.setOnCheckedChangeListener(full_screen);
mainFrames = (TextView) getView().findViewById(R.id.current_frames);
mainFrames.setText(String.valueOf(ConfigureFragment.frameskip));
SeekBar frameSeek = (SeekBar) getView()
.findViewById(R.id.frame_seekbar);
frameSeek.setProgress(ConfigureFragment.frameskip);
frameSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progressChanged = 0;
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
progressChanged = progress;
mainFrames.setText(String.valueOf(progress));
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
mPrefs.edit().putInt("frame_skip", progressChanged).commit();
ConfigureFragment.frameskip = progressChanged;
}
});
OnCheckedChangeListener pvr_rendering = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("pvr_render", isChecked).commit();
ConfigureFragment.pvrrender = isChecked;
}
};
Switch pvr_render = (Switch) getView().findViewById(R.id.render_option);
pvr_render.setChecked(ConfigureFragment.pvrrender);
pvr_render.setOnCheckedChangeListener(pvr_rendering);
final EditText cheatEdit = (EditText) getView().findViewById(
R.id.cheat_disk);
cheatEdit.setText(ConfigureFragment.cheatdisk);
cheatEdit.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if (cheatEdit.getText() != null) {
ConfigureFragment.cheatdisk = cheatEdit.getText()
.toString();
mPrefs.edit()
.putString("cheat_disk",
ConfigureFragment.cheatdisk).commit();
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
String[] depths = parentActivity.getResources().getStringArray(
R.array.depth);
@ -328,7 +312,7 @@ public class ConfigureFragment extends Fragment {
Spinner depth_spnr = (Spinner) getView().findViewById(
R.id.depth_spinner);
ArrayAdapter<String> depthAdapter = new ArrayAdapter<String>(
parentActivity, android.R.layout.simple_spinner_item, depths);
parentActivity, R.layout.spinner_selected, depths);
depthAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
depth_spnr.setAdapter(depthAdapter);
@ -361,55 +345,6 @@ public class ConfigureFragment extends Fragment {
} else {
mGenerateLogs.execute(home_directory);
}
}
private static void loadCfgSettingsFromPrefs(SharedPreferences prefs){
ConfigureFragment.dynarecopt = prefs.getBoolean("dynarec_opt",
ConfigureFragment.dynarecopt);
//idleskip not configurable
ConfigureFragment.unstableopt = prefs.getBoolean("unstable_opt",
ConfigureFragment.unstableopt);
//cable not configurable
//rtc configured automatically
ConfigureFragment.dcregion = prefs.getInt("dc_region", ConfigureFragment.dcregion);
//broadcast not configurable
ConfigureFragment.limitfps = prefs.getBoolean("limit_fps",
ConfigureFragment.limitfps);
//nobatch not configurable
ConfigureFragment.mipmaps = prefs.getBoolean("use_mipmaps",
ConfigureFragment.mipmaps);
ConfigureFragment.widescreen = prefs.getBoolean("stretch_view",
ConfigureFragment.widescreen);
//subdivide not configurable
ConfigureFragment.frameskip = prefs.getInt("frame_skip",
ConfigureFragment.frameskip);
ConfigureFragment.pvrrender = prefs.getBoolean("pvr_render",
ConfigureFragment.pvrrender);
ConfigureFragment.cheatdisk = prefs.getString("cheat_disk",
ConfigureFragment.cheatdisk);
}
public static void pushCfgToEmu(SharedPreferences prefs){
//make sure all settings are loaded
loadCfgSettingsFromPrefs(prefs);
JNIdc.dynarec(ConfigureFragment.dynarecopt ? 1 : 0);
JNIdc.idleskip(ConfigureFragment.idleskip ? 1 : 0);
JNIdc.unstable(ConfigureFragment.unstableopt ? 1 : 0);
JNIdc.cable(ConfigureFragment.cable);
JNIdc.dreamtime(DreamTime.getDreamtime());
JNIdc.region(ConfigureFragment.dcregion);
JNIdc.broadcast(ConfigureFragment.broadcast);
JNIdc.limitfps(ConfigureFragment.limitfps ? 1 : 0);
JNIdc.nobatch(ConfigureFragment.nobatch ? 1 : 0);
JNIdc.mipmaps(ConfigureFragment.mipmaps ? 1 : 0);
JNIdc.widescreen(ConfigureFragment.widescreen ? 1 : 0);
JNIdc.subdivide(ConfigureFragment.subdivide ? 1 : 0);
JNIdc.frameskip(ConfigureFragment.frameskip);
JNIdc.pvrrender(ConfigureFragment.pvrrender ? 1 : 0);
JNIdc.cheatdisk(ConfigureFragment.cheatdisk);
}
}

View File

@ -32,6 +32,8 @@ public class EditVJoyActivity extends Activity {
GL2JNIView mView;
PopupWindow popUp;
LayoutParams params;
private Config config;
private float[][] vjoy_d_cached;
@ -56,9 +58,12 @@ public class EditVJoyActivity extends Activity {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
config = new Config(EditVJoyActivity.this);
config.getConfigurationPrefs();
// Create the actual GLES view
mView = new GL2JNIView(getApplication(), null, false, prefs.getInt("depth_render", 24), 0, true);
mView = new GL2JNIView(getApplication(), config, null, false,
prefs.getInt("depth_render", 24), 0, true);
mView.setFpsDisplay(null);
setContentView(mView);

View File

@ -1,7 +1,5 @@
package com.reicast.emulator.config;
import java.util.HashMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -14,7 +12,6 @@ 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;
@ -47,6 +44,8 @@ public class InputFragment extends Fragment {
private SharedPreferences sharedPreferences;
private Switch switchTouchVibrationEnabled;
private Switch micPluggedIntoFirstController;
private Gamepad pad = new Gamepad();
public MOGAInput moga = new MOGAInput();
// Container Activity must implement this interface
@ -65,9 +64,10 @@ public class InputFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
parentActivity = getActivity();
moga.onCreate(parentActivity, new SparseArray<String>(), new HashMap<String, Integer>());
moga.onCreate(parentActivity, pad);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(parentActivity);
sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(parentActivity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ImageView icon_a = (ImageView) getView().findViewById(
@ -84,28 +84,30 @@ public class InputFragment extends Fragment {
icon_d.setAlpha(0.8f);
}
Button buttonLaunchEditor = (Button) getView()
.findViewById(R.id.buttonLaunchEditor);
Button buttonLaunchEditor = (Button) getView().findViewById(
R.id.buttonLaunchEditor);
buttonLaunchEditor.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent inte = new Intent(parentActivity.getBaseContext(), EditVJoyActivity.class);
public void onClick(View v) {
Intent inte = new Intent(parentActivity, EditVJoyActivity.class);
startActivity(inte);
}
}
});
if (!MainActivity.isBiosExisting() || !MainActivity.isFlashExisting())
buttonLaunchEditor.setEnabled(false);
OnCheckedChangeListener touch_vibration = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
sharedPreferences.edit().putBoolean("touch_vibration_enabled", isChecked).commit();
sharedPreferences.edit()
.putBoolean("touch_vibration_enabled", isChecked)
.commit();
}
};
switchTouchVibrationEnabled = (Switch) getView().findViewById(
R.id.switchTouchVibrationEnabled);
boolean vibrate = sharedPreferences.getBoolean("touch_vibration_enabled", true);
boolean vibrate = sharedPreferences.getBoolean(
"touch_vibration_enabled", true);
if (vibrate) {
switchTouchVibrationEnabled.setChecked(true);
} else {
@ -206,7 +208,7 @@ public class InputFragment extends Fragment {
});
updateControllers();
} else {
TableLayout input_devices = (TableLayout) parentActivity.findViewById(R.id.input_devices);
@ -218,15 +220,20 @@ public class InputFragment extends Fragment {
}
private void updateVibration() {
boolean touchVibrationEnabled = sharedPreferences.getBoolean("touch_vibration_enabled", true);
boolean touchVibrationEnabled = sharedPreferences.getBoolean(
"touch_vibration_enabled", true);
switchTouchVibrationEnabled.setChecked(touchVibrationEnabled);
}
private void updateControllers() {
String deviceDescriptorPlayer1 = sharedPreferences.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = sharedPreferences.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = sharedPreferences.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = sharedPreferences.getString("device_descriptor_player_4", null);
String deviceDescriptorPlayer1 = sharedPreferences.getString(
"device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = sharedPreferences.getString(
"device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = sharedPreferences.getString(
"device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = sharedPreferences.getString(
"device_descriptor_player_4", null);
String labelPlayer1 = null, labelPlayer2 = null, labelPlayer3 = null, labelPlayer4 = null;
@ -253,68 +260,80 @@ public class InputFragment extends Fragment {
TextView textViewDeviceDescriptorPlayer1 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer1);
Button buttonRemoveControllerPlayer1 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer1);
Button buttonRemoveControllerPlayer1 = (Button) getView().findViewById(
R.id.buttonRemoveControllerPlayer1);
if (labelPlayer1 != null) {
textViewDeviceDescriptorPlayer1.setText(labelPlayer1);
buttonRemoveControllerPlayer1.setEnabled(true);
} else {
if (deviceDescriptorPlayer1 != null) {
textViewDeviceDescriptorPlayer1.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer1 + ")");
textViewDeviceDescriptorPlayer1
.setText(getString(R.string.controller_not_connected)
+ " (" + deviceDescriptorPlayer1 + ")");
buttonRemoveControllerPlayer1.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer1.setText(getString(R.string.controller_none_selected));
textViewDeviceDescriptorPlayer1
.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer1.setEnabled(false);
}
}
TextView textViewDeviceDescriptorPlayer2 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer2);
Button buttonRemoveControllerPlayer2 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer2);
Button buttonRemoveControllerPlayer2 = (Button) getView().findViewById(
R.id.buttonRemoveControllerPlayer2);
if (labelPlayer2 != null) {
textViewDeviceDescriptorPlayer2.setText(labelPlayer2);
buttonRemoveControllerPlayer2.setEnabled(true);
} else {
if (deviceDescriptorPlayer2 != null) {
textViewDeviceDescriptorPlayer2.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer2 + ")");
textViewDeviceDescriptorPlayer2
.setText(getString(R.string.controller_not_connected)
+ " (" + deviceDescriptorPlayer2 + ")");
buttonRemoveControllerPlayer2.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer2.setText(getString(R.string.controller_none_selected));
textViewDeviceDescriptorPlayer2
.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer2.setEnabled(false);
}
}
TextView textViewDeviceDescriptorPlayer3 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer3);
Button buttonRemoveControllerPlayer3 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer3);
Button buttonRemoveControllerPlayer3 = (Button) getView().findViewById(
R.id.buttonRemoveControllerPlayer3);
if (labelPlayer3 != null) {
textViewDeviceDescriptorPlayer3.setText(labelPlayer3);
buttonRemoveControllerPlayer3.setEnabled(true);
} else {
if (deviceDescriptorPlayer3 != null) {
textViewDeviceDescriptorPlayer3.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer3 + ")");
textViewDeviceDescriptorPlayer3
.setText(getString(R.string.controller_not_connected)
+ " (" + deviceDescriptorPlayer3 + ")");
buttonRemoveControllerPlayer3.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer3.setText(getString(R.string.controller_none_selected));
textViewDeviceDescriptorPlayer3
.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer3.setEnabled(false);
}
}
TextView textViewDeviceDescriptorPlayer4 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer4);
Button buttonRemoveControllerPlayer4 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer4);
Button buttonRemoveControllerPlayer4 = (Button) getView().findViewById(
R.id.buttonRemoveControllerPlayer4);
if (labelPlayer4 != null) {
textViewDeviceDescriptorPlayer4.setText(labelPlayer4);
buttonRemoveControllerPlayer4.setEnabled(true);
} else {
if (deviceDescriptorPlayer4 != null) {
textViewDeviceDescriptorPlayer4.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer4 + ")");
textViewDeviceDescriptorPlayer4
.setText(getString(R.string.controller_not_connected)
+ " (" + deviceDescriptorPlayer4 + ")");
buttonRemoveControllerPlayer4.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer4.setText(getString(R.string.controller_none_selected));
textViewDeviceDescriptorPlayer4
.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer4.setEnabled(false);
}
}
@ -350,7 +369,8 @@ public class InputFragment extends Fragment {
}
});
builder.setOnKeyListener(new Dialog.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
return mapDevice(keyCode, event);
}
});
@ -359,13 +379,16 @@ public class InputFragment extends Fragment {
}
private boolean mapDevice(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK ||
keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
if (keyCode == KeyEvent.KEYCODE_MENU
|| keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
return false;
if (!pad.IsXperiaPlay() && keyCode == KeyEvent.KEYCODE_BACK)
return false;
String descriptor = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (moga.isActiveMoga[listenForButton]) {
if (pad.isActiveMoga[listenForButton]) {
MogaListener config = new MogaListener(listenForButton);
moga.mController.setListener(config, new Handler());
descriptor = config.getController();
@ -380,35 +403,52 @@ public class InputFragment extends Fragment {
if (descriptor == null)
return false;
String deviceDescriptorPlayer1 = sharedPreferences.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = sharedPreferences.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = sharedPreferences.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = sharedPreferences.getString("device_descriptor_player_4", null);
String deviceDescriptorPlayer1 = sharedPreferences.getString(
"device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = sharedPreferences.getString(
"device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = sharedPreferences.getString(
"device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = sharedPreferences.getString(
"device_descriptor_player_4", null);
if (descriptor.equals(deviceDescriptorPlayer1) || descriptor.equals(deviceDescriptorPlayer2) ||
descriptor.equals(deviceDescriptorPlayer3) || descriptor.equals(deviceDescriptorPlayer4)) {
Toast.makeText(parentActivity, getString(R.string.controller_already_in_use), Toast.LENGTH_SHORT).show();
if (descriptor.equals(deviceDescriptorPlayer1)
|| descriptor.equals(deviceDescriptorPlayer2)
|| descriptor.equals(deviceDescriptorPlayer3)
|| descriptor.equals(deviceDescriptorPlayer4)) {
Toast.makeText(parentActivity,
getString(R.string.controller_already_in_use),
Toast.LENGTH_SHORT).show();
return true;
}
switch(listenForButton) {
case 0:
return false;
case 1:
sharedPreferences.edit().putString("device_descriptor_player_1", descriptor).commit();
break;
case 2:
sharedPreferences.edit().putString("device_descriptor_player_2", descriptor).commit();
break;
case 3:
sharedPreferences.edit().putString("device_descriptor_player_3", descriptor).commit();
break;
case 4:
sharedPreferences.edit().putString("device_descriptor_player_4", descriptor).commit();
break;
switch (listenForButton) {
case 0:
return false;
case 1:
sharedPreferences.edit()
.putString("device_descriptor_player_1", descriptor)
.commit();
break;
case 2:
sharedPreferences.edit()
.putString("device_descriptor_player_2", descriptor)
.commit();
break;
case 3:
sharedPreferences.edit()
.putString("device_descriptor_player_3", descriptor)
.commit();
break;
case 4:
sharedPreferences.edit()
.putString("device_descriptor_player_4", descriptor)
.commit();
break;
}
Log.d("New controller for port " + String.valueOf(listenForButton) + ":", descriptor);
Log.d("New controller for port " + String.valueOf(listenForButton)
+ ":", descriptor);
listenForButton = 0;
alertDialogSelectController.cancel();
@ -418,19 +458,23 @@ public class InputFragment extends Fragment {
}
private void removeController(int playerNum) {
switch(playerNum) {
case 1:
sharedPreferences.edit().putString("device_descriptor_player_1", null).commit();
break;
case 2:
sharedPreferences.edit().putString("device_descriptor_player_2", null).commit();
break;
case 3:
sharedPreferences.edit().putString("device_descriptor_player_3", null).commit();
break;
case 4:
sharedPreferences.edit().putString("device_descriptor_player_4", null).commit();
break;
switch (playerNum) {
case 1:
sharedPreferences.edit()
.putString("device_descriptor_player_1", null).commit();
break;
case 2:
sharedPreferences.edit()
.putString("device_descriptor_player_2", null).commit();
break;
case 3:
sharedPreferences.edit()
.putString("device_descriptor_player_3", null).commit();
break;
case 4:
sharedPreferences.edit()
.putString("device_descriptor_player_4", null).commit();
break;
}
updateControllers();
@ -462,9 +506,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.isActiveMoga[playerNum] = true;
pad.isActiveMoga[playerNum] = true;
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
moga.isActiveMoga[playerNum] = true;
pad.isActiveMoga[playerNum] = true;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,237 @@
package com.reicast.emulator.emu;
import java.util.Locale;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import android.opengl.GLSurfaceView;
import android.util.Log;
public class GLCFactory {
private static void LOGI(String S) { Log.i("GL2JNIView-v6",S); }
private static void LOGW(String S) { Log.w("GL2JNIView-v6",S); }
private static void LOGE(String S) { Log.e("GL2JNIView-v6",S); }
public static class ContextFactory implements GLSurfaceView.EGLContextFactory
{
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext(EGL10 egl,EGLDisplay display,EGLConfig eglConfig)
{
int[] attrList = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
LOGI("Creating OpenGL ES 2.0 context");
checkEglError("Before eglCreateContext",egl);
EGLContext context = egl.eglCreateContext(display,eglConfig,EGL10.EGL_NO_CONTEXT,attrList);
checkEglError("After eglCreateContext",egl);
return(context);
}
public void destroyContext(EGL10 egl,EGLDisplay display,EGLContext context)
{
LOGI("Destroying OpenGL ES 2.0 context");
egl.eglDestroyContext(display,context);
}
}
private static void checkEglError(String prompt,EGL10 egl)
{
int error;
while((error=egl.eglGetError()) != EGL10.EGL_SUCCESS)
LOGE(String.format("%s: EGL error: 0x%x",prompt,error));
}
public static class ConfigChooser implements GLSurfaceView.EGLConfigChooser
{
// Subclasses can adjust these values:
protected int mRedSize;
protected int mGreenSize;
protected int mBlueSize;
protected int mAlphaSize;
protected int mDepthSize;
protected int mStencilSize;
private int[] mValue = new int[1];
public ConfigChooser(int r,int g,int b,int a,int depth,int stencil)
{
mRedSize = r;
mGreenSize = g;
mBlueSize = b;
mAlphaSize = a;
mDepthSize = depth;
mStencilSize = stencil;
}
// This EGL config specification is used to specify 2.0 rendering.
// We use a minimum size of 4 bits for red/green/blue, but will
// perform actual matching in chooseConfig() below.
private static final int EGL_OPENGL_ES2_BIT = 4;
private static final int[] cfgAttrs =
{
EGL10.EGL_RED_SIZE, 4,
EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_DEPTH_SIZE, 24,
EGL10.EGL_NONE
};
public EGLConfig chooseConfig(EGL10 egl,EGLDisplay display)
{
// Get the number of minimally matching EGL configurations
int[] cfgCount = new int[1];
egl.eglChooseConfig(display,cfgAttrs,null,0,cfgCount);
if(cfgCount[0]<=0)
{
cfgAttrs[9]=16;
egl.eglChooseConfig(display,cfgAttrs,null,0,cfgCount);
}
if(cfgCount[0]<=0)
throw new IllegalArgumentException("No configs match configSpec");
// Allocate then read the array of minimally matching EGL configs
EGLConfig[] configs = new EGLConfig[cfgCount[0]];
egl.eglChooseConfig(display,cfgAttrs,configs,cfgCount[0],cfgCount);
if(GL2JNIView.DEBUG)
printConfigs(egl,display,configs);
// Now return the "best" one
return(chooseConfig(egl,display,configs));
}
public EGLConfig chooseConfig(EGL10 egl,EGLDisplay display,EGLConfig[] configs)
{
for(EGLConfig config : configs)
{
int d = findConfigAttrib(egl,display,config,EGL10.EGL_DEPTH_SIZE,0);
int s = findConfigAttrib(egl,display,config,EGL10.EGL_STENCIL_SIZE,0);
// We need at least mDepthSize and mStencilSize bits
if(d>=mDepthSize || s>=mStencilSize)
{
// We want an *exact* match for red/green/blue/alpha
int r = findConfigAttrib(egl,display,config,EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl,display,config,EGL10.EGL_GREEN_SIZE,0);
int b = findConfigAttrib(egl,display,config,EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl,display,config,EGL10.EGL_ALPHA_SIZE,0);
if(r==mRedSize && g==mGreenSize && b==mBlueSize && a==mAlphaSize)
return(config);
}
}
return(null);
}
private int findConfigAttrib(EGL10 egl,EGLDisplay display,EGLConfig config,int attribute,int defaultValue)
{
return(egl.eglGetConfigAttrib(display,config,attribute,mValue)? mValue[0] : defaultValue);
}
private void printConfigs(EGL10 egl,EGLDisplay display,EGLConfig[] configs)
{
LOGW(String.format(Locale.getDefault(), "%d configurations", configs.length));
for(int i=0 ; i<configs.length ; i++)
{
LOGW(String.format(Locale.getDefault(), "Configuration %d:", i));
printConfig(egl,display,configs[i]);
}
}
private void printConfig(EGL10 egl,EGLDisplay display,EGLConfig config)
{
final int[] attributes =
{
EGL10.EGL_BUFFER_SIZE,
EGL10.EGL_ALPHA_SIZE,
EGL10.EGL_BLUE_SIZE,
EGL10.EGL_GREEN_SIZE,
EGL10.EGL_RED_SIZE,
EGL10.EGL_DEPTH_SIZE,
EGL10.EGL_STENCIL_SIZE,
EGL10.EGL_CONFIG_CAVEAT,
EGL10.EGL_CONFIG_ID,
EGL10.EGL_LEVEL,
EGL10.EGL_MAX_PBUFFER_HEIGHT,
EGL10.EGL_MAX_PBUFFER_PIXELS,
EGL10.EGL_MAX_PBUFFER_WIDTH,
EGL10.EGL_NATIVE_RENDERABLE,
EGL10.EGL_NATIVE_VISUAL_ID,
EGL10.EGL_NATIVE_VISUAL_TYPE,
0x3030, // EGL10.EGL_PRESERVED_RESOURCES,
EGL10.EGL_SAMPLES,
EGL10.EGL_SAMPLE_BUFFERS,
EGL10.EGL_SURFACE_TYPE,
EGL10.EGL_TRANSPARENT_TYPE,
EGL10.EGL_TRANSPARENT_RED_VALUE,
EGL10.EGL_TRANSPARENT_GREEN_VALUE,
EGL10.EGL_TRANSPARENT_BLUE_VALUE,
0x3039, // EGL10.EGL_BIND_TO_TEXTURE_RGB,
0x303A, // EGL10.EGL_BIND_TO_TEXTURE_RGBA,
0x303B, // EGL10.EGL_MIN_SWAP_INTERVAL,
0x303C, // EGL10.EGL_MAX_SWAP_INTERVAL,
EGL10.EGL_LUMINANCE_SIZE,
EGL10.EGL_ALPHA_MASK_SIZE,
EGL10.EGL_COLOR_BUFFER_TYPE,
EGL10.EGL_RENDERABLE_TYPE,
0x3042 // EGL10.EGL_CONFORMANT
};
final String[] names =
{
"EGL_BUFFER_SIZE",
"EGL_ALPHA_SIZE",
"EGL_BLUE_SIZE",
"EGL_GREEN_SIZE",
"EGL_RED_SIZE",
"EGL_DEPTH_SIZE",
"EGL_STENCIL_SIZE",
"EGL_CONFIG_CAVEAT",
"EGL_CONFIG_ID",
"EGL_LEVEL",
"EGL_MAX_PBUFFER_HEIGHT",
"EGL_MAX_PBUFFER_PIXELS",
"EGL_MAX_PBUFFER_WIDTH",
"EGL_NATIVE_RENDERABLE",
"EGL_NATIVE_VISUAL_ID",
"EGL_NATIVE_VISUAL_TYPE",
"EGL_PRESERVED_RESOURCES",
"EGL_SAMPLES",
"EGL_SAMPLE_BUFFERS",
"EGL_SURFACE_TYPE",
"EGL_TRANSPARENT_TYPE",
"EGL_TRANSPARENT_RED_VALUE",
"EGL_TRANSPARENT_GREEN_VALUE",
"EGL_TRANSPARENT_BLUE_VALUE",
"EGL_BIND_TO_TEXTURE_RGB",
"EGL_BIND_TO_TEXTURE_RGBA",
"EGL_MIN_SWAP_INTERVAL",
"EGL_MAX_SWAP_INTERVAL",
"EGL_LUMINANCE_SIZE",
"EGL_ALPHA_MASK_SIZE",
"EGL_COLOR_BUFFER_TYPE",
"EGL_RENDERABLE_TYPE",
"EGL_CONFORMANT"
};
int[] value = new int[1];
for(int i=0 ; i<attributes.length ; i++)
if(egl.eglGetConfigAttrib(display,config,attributes[i],value))
LOGI(String.format(Locale.getDefault(), " %s: %d\n",names[i],value[0]));
else
while(egl.eglGetError()!=EGL10.EGL_SUCCESS);
}
}
}

View File

@ -21,19 +21,15 @@ 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;
import com.reicast.emulator.config.Config;
import com.reicast.emulator.periph.VmuLcd;
public class OnScreenMenu {
private GL2JNIActivity mContext;
private Context mContext;
private SharedPreferences prefs;
private LinearLayout hlay;
private LayoutParams params;
private int frameskip;
private boolean widescreen;
private boolean limitframes;
private boolean audiodisabled;
private VmuLcd vmuLcd;
@ -42,39 +38,41 @@ public class OnScreenMenu {
private File sdcard = Environment.getExternalStorageDirectory();
private String home_directory = sdcard + "/dc";
public OnScreenMenu(Context mContext, SharedPreferences prefs) {
if (mContext instanceof GL2JNIActivity) {
this.mContext = (GL2JNIActivity) mContext;
public OnScreenMenu(Context context, SharedPreferences prefs) {
if (context instanceof GL2JNIActivity) {
this.mContext = (GL2JNIActivity) context;
}
popups = new Vector<PopupWindow>();
if (prefs != null) {
this.prefs = prefs;
home_directory = prefs.getString("home_directory", home_directory);
widescreen = ConfigureFragment.widescreen;
frameskip = ConfigureFragment.frameskip;
}
vmuLcd = new VmuLcd(mContext);
vmuLcd.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
OnScreenMenu.this.mContext.toggleVmu();
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) OnScreenMenu.this.mContext).toggleVmu();
}
}
});
}
void displayDebugPopup(final PopupWindow popUp) {
mContext.displayDebug(new DebugPopup(mContext));
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) mContext).displayDebug(new DebugPopup(mContext));
}
}
public class FpsPopup extends PopupWindow {
private TextView fpsText;
public FpsPopup(Context c) {
super(c);
setBackgroundDrawable(null);
fpsText = new TextView(mContext);
fpsText.setTextAppearance(mContext,
R.style.fpsOverlayText);
fpsText.setTextAppearance(mContext, R.style.fpsOverlayText);
fpsText.setGravity(Gravity.CENTER);
fpsText.setText("XX");
setContentView(fpsText);
@ -102,7 +100,10 @@ public class OnScreenMenu {
public void onClick(View v) {
popups.remove(this);
dismiss();
mContext.displayPopUp(OnScreenMenu.this.mContext.popUp);
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) mContext)
.displayPopUp(((GL2JNIActivity) OnScreenMenu.this.mContext).popUp);
}
}
}), debugParams);
@ -147,7 +148,10 @@ public class OnScreenMenu {
}
void displayConfigPopup(final PopupWindow popUp) {
mContext.displayConfig(new ConfigPopup(mContext));
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) mContext)
.displayConfig(new ConfigPopup(mContext));
}
}
public class ConfigPopup extends PopupWindow {
@ -157,9 +161,9 @@ public class OnScreenMenu {
private View audiosetting;
private View fdown;
private View fup;
private int frames = ConfigureFragment.frameskip;
private boolean screen = ConfigureFragment.widescreen;
private boolean limit = ConfigureFragment.limitfps;
private int frames = Config.frameskip;
private boolean screen = Config.widescreen;
private boolean limit = Config.limitfps;
private boolean audio;
public ConfigPopup(Context c) {
@ -176,89 +180,105 @@ public class OnScreenMenu {
public void onClick(View v) {
popups.remove(this);
dismiss();
mContext.displayPopUp(OnScreenMenu.this.mContext.popUp);
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) mContext)
.displayPopUp(((GL2JNIActivity) OnScreenMenu.this.mContext).popUp);
}
}
}), configParams);
fullscreen = addbut(R.drawable.widescreen,
new OnClickListener() {
fullscreen = addbut(R.drawable.widescreen, new OnClickListener() {
public void onClick(View v) {
if (screen) {
JNIdc.widescreen(1);
screen = true;
((ImageButton) fullscreen).setImageResource(R.drawable.normal_view);
((ImageButton) fullscreen)
.setImageResource(R.drawable.normal_view);
} else {
JNIdc.widescreen(0);
screen = false;
((ImageButton) fullscreen).setImageResource(R.drawable.widescreen);
((ImageButton) fullscreen)
.setImageResource(R.drawable.widescreen);
}
dismiss();
}
});
if (screen) {
((ImageButton) fullscreen).setImageResource(R.drawable.normal_view);
((ImageButton) fullscreen)
.setImageResource(R.drawable.normal_view);
}
hlay.addView(fullscreen, params);
fdown = addbut(R.drawable.frames_down, new OnClickListener() {
public void onClick(View v) {
frameskip++;
JNIdc.frameskip(frameskip);
enableState(fup, fdown);
frames--;
JNIdc.frameskip(frames);
enableState(fup, fdown, frames);
}
});
fup = addbut(R.drawable.frames_up, new OnClickListener() {
public void onClick(View v) {
frameskip--;
JNIdc.frameskip(frameskip);
enableState(fup, fdown);
frames++;
JNIdc.frameskip(frames);
enableState(fup, fdown, frames);
}
});
hlay.addView(fup, params);
hlay.addView(fdown, params);
enableState(fup, fdown);
hlay.addView(fup, params);
enableState(fdown, fup, frames);
framelimit = addbut(R.drawable.frames_limit_on,
new OnClickListener() {
public void onClick(View v) {
if (limit) {
JNIdc.limitfps(0);
limit = false;
((ImageButton) audiosetting).setImageResource(R.drawable.frames_limit_on);
} else {
JNIdc.limitfps(1);
limit = true;
((ImageButton) audiosetting).setImageResource(R.drawable.frames_limit_off);
}
dismiss();
public void onClick(View v) {
if (limit) {
JNIdc.limitfps(0);
limit = false;
((ImageButton) audiosetting)
.setImageResource(R.drawable.frames_limit_on);
} else {
JNIdc.limitfps(1);
limit = true;
((ImageButton) audiosetting)
.setImageResource(R.drawable.frames_limit_off);
}
dismiss();
}
});
}
});
if (limit) {
((ImageButton) audiosetting).setImageResource(R.drawable.frames_limit_off);
((ImageButton) audiosetting)
.setImageResource(R.drawable.frames_limit_off);
}
hlay.addView(framelimit, params);
audiosetting = addbut(R.drawable.enable_sound,
new OnClickListener() {
public void onClick(View v) {
if (audio) {
((ImageButton) audiosetting).setImageResource(R.drawable.mute_sound);
mContext.mView.audioDisable(false);
} else {
((ImageButton) audiosetting).setImageResource(R.drawable.enable_sound);
mContext.mView.audioDisable(true);
}
dismiss();
audio = true;
}
});
public void onClick(View v) {
if (audio) {
((ImageButton) audiosetting)
.setImageResource(R.drawable.mute_sound);
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) mContext).mView
.audioDisable(false);
}
} else {
((ImageButton) audiosetting)
.setImageResource(R.drawable.enable_sound);
if (mContext instanceof GL2JNIActivity) {
((GL2JNIActivity) mContext).mView
.audioDisable(true);
}
}
dismiss();
audio = true;
}
});
audio = prefs.getBoolean("sound_enabled", true);
if (audio) {
((ImageButton) audiosetting).setImageResource(R.drawable.mute_sound);
((ImageButton) audiosetting)
.setImageResource(R.drawable.mute_sound);
}
hlay.addView(audiosetting, params);
@ -274,16 +294,16 @@ public class OnScreenMenu {
}
}
private void enableState(View frames_up, View frames_down) {
if (frameskip <= 0) {
frames_down.setEnabled(false);
private void enableState(View fdown, View fup, int frames) {
if (frames <= 0) {
fdown.setEnabled(false);
} else {
frames_down.setEnabled(true);
fdown.setEnabled(true);
}
if (frameskip >= 5) {
frames_up.setEnabled(false);
if (frames >= 5) {
fup.setEnabled(false);
} else {
frames_up.setEnabled(true);
fup.setEnabled(true);
}
}
@ -375,19 +395,24 @@ public class OnScreenMenu {
rsticksetting = addbut(R.drawable.toggle_a_b,
new OnClickListener() {
public void onClick(View v) {
if (prefs.getBoolean("right_buttons", true)) {
prefs.edit().putBoolean("right_buttons", false).commit();
((ImageButton) rsticksetting).setImageResource(R.drawable.toggle_a_b);
} else {
prefs.edit().putBoolean("right_buttons", true).commit();
((ImageButton) rsticksetting).setImageResource(R.drawable.toggle_r_l);
}
dismiss();
}
});
public void onClick(View v) {
if (prefs.getBoolean("right_buttons", true)) {
prefs.edit().putBoolean("right_buttons", false)
.commit();
((ImageButton) rsticksetting)
.setImageResource(R.drawable.toggle_a_b);
} else {
prefs.edit().putBoolean("right_buttons", true)
.commit();
((ImageButton) rsticksetting)
.setImageResource(R.drawable.toggle_r_l);
}
dismiss();
}
});
if (prefs.getBoolean("right_buttons", true)) {
((ImageButton) rsticksetting).setImageResource(R.drawable.toggle_r_l);
((ImageButton) rsticksetting)
.setImageResource(R.drawable.toggle_r_l);
}
hlay.addView(rsticksetting, params);

View File

@ -1,17 +1,41 @@
package com.reicast.emulator.periph;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import tv.ouya.console.api.OuyaController;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.SparseArray;
import android.view.KeyEvent;
public class Gamepad {
public static boolean isXperiaPlay;
public static boolean isOuyaOrTV;
public String[] portId = { "_A", "_B", "_C", "_D" };
public boolean[] compat = { false, false, false, false };
public boolean[] custom = { false, false, false, false };
public int[] name = { -1, -1, -1, -1 };
public float[] globalLS_X = new float[4], globalLS_Y = new float[4],
previousLS_X = new float[4], previousLS_Y = new float[4];
public int map[][] = new int[4][];
public SparseArray<String> deviceId_deviceDescriptor = new SparseArray<String>();
public HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
public boolean isActiveMoga[] = { false, false, false, false };
public boolean isMogaPro[] = { false, false, false, false };
public SparseArray<Integer> playerNumX = new SparseArray<Integer>();
public List<Integer> keypadZeus = new ArrayList<Integer>();
public boolean isXperiaPlay;
public boolean isOuyaOrTV;
// public boolean isNvidiaShield;
public static final int Xperia_Touchpad = 1048584;
public static final int key_CONT_B = 0x0002;
public static final int key_CONT_A = 0x0004;
@ -23,7 +47,7 @@ public class Gamepad {
public static final int key_CONT_Y = 0x0200;
public static final int key_CONT_X = 0x0400;
public static int[] getConsoleController() {
public int[] getConsoleController() {
return new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
@ -41,7 +65,7 @@ public class Gamepad {
};
}
public static int[] getXPlayController() {
public int[] getXPlayController() {
return new int[] {
KeyEvent.KEYCODE_DPAD_CENTER, key_CONT_A,
KeyEvent.KEYCODE_BACK, key_CONT_B,
@ -59,7 +83,7 @@ public class Gamepad {
};
}
public static int[] getOUYAController() {
public int[] getOUYAController() {
return new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
@ -87,7 +111,7 @@ public class Gamepad {
};
}
public static int[] getMogaController() {
public int[] getMogaController() {
return new int[] {
KeyEvent.KEYCODE_BUTTON_B, key_CONT_B,
KeyEvent.KEYCODE_BUTTON_A, key_CONT_A,
@ -104,7 +128,7 @@ public class Gamepad {
};
}
public static int[] setModifiedKeys(String id, int playerNum, SharedPreferences mPrefs) {
public 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,
@ -121,7 +145,7 @@ public class Gamepad {
};
}
public static boolean IsXperiaPlay() {
public boolean IsXperiaPlay() {
return android.os.Build.MODEL.equals("R800a")
|| android.os.Build.MODEL.equals("R800i")
|| android.os.Build.MODEL.equals("R800x")
@ -130,7 +154,7 @@ public class Gamepad {
|| android.os.Build.MODEL.equals("zeus");
}
public static boolean IsOuyaOrTV(Context context) {
public boolean IsOuyaOrTV(Context context) {
PackageManager pMan = context.getPackageManager();
if (pMan.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
return true;
@ -138,7 +162,7 @@ public class Gamepad {
return false;
}
public static int getStartButtonCode() {
public int getStartButtonCode() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
return 108;
} else {
@ -146,7 +170,7 @@ public class Gamepad {
}
}
public static int getSelectButtonCode() {
public int getSelectButtonCode() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
return 109;
} else {
@ -154,7 +178,7 @@ public class Gamepad {
}
}
public static boolean IsNvidiaShield() {
public boolean IsNvidiaShield() {
return android.os.Build.MODEL.equals("SHIELD")
|| android.os.Build.DEVICE.equals("roth")
|| android.os.Build.PRODUCT.equals("thor");

View File

@ -37,21 +37,10 @@ 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 pad;
Activity act;
public MOGAInput()
@ -88,13 +77,10 @@ public class MOGAInput
*/
}
public void onCreate(Activity act,
SparseArray<String> deviceId_deviceDescriptor,
HashMap<String, Integer> deviceDescriptor_PlayerNum) {
public void onCreate(Activity act, Gamepad pad) {
this.act = act;
this.deviceId_deviceDescriptor = deviceId_deviceDescriptor;
this.deviceDescriptor_PlayerNum = deviceDescriptor_PlayerNum;
this.pad = pad;
handler = new Handler();
prefs = PreferenceManager
@ -147,13 +133,13 @@ public class MOGAInput
{
public void onKeyEvent(KeyEvent event)
{
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getControllerId()));
Integer playerNum = pad.deviceDescriptor_PlayerNum.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
if (playerNum == null)
return;
String id = portId[playerNum];
if (custom[playerNum]) {
String id = pad.portId[playerNum];
if (pad.custom[playerNum]) {
if (event.getKeyCode() == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
simulatedTouchEvent(playerNum, 1.0f, 0.0f);
simulatedTouchEvent(playerNum, 0.0f, 0.0f);
@ -167,12 +153,12 @@ public class MOGAInput
if(playerNum == 0)
JNIdc.hide_osd();
for (int i = 0; i < map.length; i += 2) {
if (map[playerNum][i + 0] == event.getKeyCode()) {
for (int i = 0; i < pad.map.length; i += 2) {
if (pad.map[playerNum][i + 0] == event.getKeyCode()) {
if (event.getAction() == 0) //FIXME to const
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
GL2JNIView.kcode_raw[playerNum] &= ~pad.map[playerNum][i + 1];
else
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
GL2JNIView.kcode_raw[playerNum] |= pad.map[playerNum][i + 1];
break;
}
}
@ -181,10 +167,10 @@ public class MOGAInput
public void simulatedTouchEvent(int playerNum, float L2, float R2) {
if(playerNum == 0)
JNIdc.hide_osd();
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = 0;
globalLS_Y[playerNum] = 0;
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
pad.globalLS_X[playerNum] = 0;
pad.globalLS_Y[playerNum] = 0;
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.jx[playerNum] = (int) (0 * 126);
@ -193,7 +179,7 @@ public class MOGAInput
public void onMotionEvent(MotionEvent event)
{
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getControllerId()));
Integer playerNum = pad.deviceDescriptor_PlayerNum.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
if (playerNum == null)
return;
@ -206,10 +192,10 @@ public class MOGAInput
float L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
float R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = S_X;
globalLS_Y[playerNum] = S_Y;
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
pad.globalLS_X[playerNum] = S_X;
pad.globalLS_Y[playerNum] = S_Y;
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
@ -228,7 +214,7 @@ public class MOGAInput
public void onStateEvent(StateEvent event)
{
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getControllerId()));
Integer playerNum = pad.deviceDescriptor_PlayerNum.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
if (playerNum == null)
return;
@ -236,27 +222,27 @@ public class MOGAInput
if(playerNum == 0)
JNIdc.hide_osd();
String id = portId[playerNum];
custom[playerNum] = prefs.getBoolean("modified_key_layout" + id, false);
String id = pad.portId[playerNum];
pad.custom[playerNum] = prefs.getBoolean("modified_key_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) {
isActiveMoga[playerNum] = true;
isMogaPro[playerNum] = true;
if (custom[playerNum]) {
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
pad.isActiveMoga[playerNum] = true;
pad.isMogaPro[playerNum] = true;
if (pad.custom[playerNum]) {
pad.map[playerNum] = pad.setModifiedKeys(id, playerNum, prefs);
} else {
map[playerNum] = Gamepad.getMogaController();
pad.map[playerNum] = pad.getMogaController();
}
notify = act.getApplicationContext().getString(R.string.moga_pro_connect);
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
isActiveMoga[playerNum] = true;
isMogaPro[playerNum] = false;
if (custom[playerNum]) {
map[playerNum] = Gamepad.setModifiedKeys(id, playerNum, prefs);
pad.isActiveMoga[playerNum] = true;
pad.isMogaPro[playerNum] = false;
if (pad.custom[playerNum]) {
pad.map[playerNum] = pad.setModifiedKeys(id, playerNum, prefs);
} else {
map[playerNum] = Gamepad.getMogaController();
pad.map[playerNum] = pad.getMogaController();
}
notify = act.getApplicationContext().getString(R.string.moga_connect);
}