From 1619d856633e49a9d6b8a5e76baa1bdbbff4b76a Mon Sep 17 00:00:00 2001 From: Ender's Games Date: Tue, 21 Aug 2018 10:07:07 -0400 Subject: [PATCH] Android: Add dynamic per-player peripheral support Android: Add a UI shell for implementing peripherals Android: Replace hardcoded mic assignment with dynamic Android: Convert mic option to general recording option Android: Hardcoded VMUs for controller 1 Android: Fix preferences and config for microphone Android: Add defaults, documentation, and wiring --- .../com/reicast/emulator/GL2JNIActivity.java | 39 ++-- .../com/reicast/emulator/GL2JNINative.java | 37 ++- .../com/reicast/emulator/config/Config.java | 1 - .../emulator/config/InputFragment.java | 214 +++++++++++++----- .../java/com/reicast/emulator/emu/JNIdc.java | 2 +- .../com/reicast/emulator/periph/Gamepad.java | 6 + .../reicast/src/main/jni/src/Android.cpp | 57 ++++- .../main/res/layout-v14/input_fragment.xml | 118 ++++++++-- .../src/main/res/layout/input_fragment.xml | 118 ++++++++-- .../src/main/res/values-da/strings.xml | 3 +- .../src/main/res/values-de/strings.xml | 3 +- .../src/main/res/values-fr/strings.xml | 3 +- .../src/main/res/values-it/strings.xml | 3 +- .../src/main/res/values-jp/strings.xml | 3 +- .../src/main/res/values-pt/strings.xml | 5 +- .../src/main/res/values-ru/strings.xml | 3 +- .../src/main/res/values-zh-rCN/strings.xml | 1 - .../src/main/res/values-zh/strings.xml | 1 - .../src/main/res/values/donottranslate.xml | 7 + .../reicast/src/main/res/values/strings.xml | 3 +- 20 files changed, 484 insertions(+), 143 deletions(-) diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNIActivity.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNIActivity.java index 4a055b63c..19512eb4b 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNIActivity.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNIActivity.java @@ -89,9 +89,12 @@ public class GL2JNIActivity extends Activity { prefs.getString(Gamepad.pref_player4, null), 3); pad.deviceDescriptor_PlayerNum.remove(null); - boolean controllerTwoConnected = false; - boolean controllerThreeConnected = false; - boolean controllerFourConnected = false; + boolean player2connected = false; + boolean player3connected = false; + boolean player4connected = false; + int p2periphs[] = {0, 0}; + int p3periphs[] = {0, 0}; + int p4periphs[] = {0, 0}; for (HashMap.Entry e : pad.deviceDescriptor_PlayerNum.entrySet()) { String descriptor = e.getKey(); @@ -99,22 +102,32 @@ public class GL2JNIActivity extends Activity { switch (playerNum) { case 1: - if (descriptor != null) - controllerTwoConnected = true; + if (descriptor != null) { + player2connected = true; + p2periphs[0] = prefs.getInt(Gamepad.p2_peripheral + 1, 0); + p2periphs[1] = prefs.getInt(Gamepad.p2_peripheral + 2, 0); + } break; case 2: - if (descriptor != null) - controllerThreeConnected = true; + if (descriptor != null) { + player3connected = true; + p3periphs[0] = prefs.getInt(Gamepad.p3_peripheral + 1, 0); + p3periphs[1] = prefs.getInt(Gamepad.p3_peripheral + 2, 0); + } break; case 3: - if (descriptor != null) - controllerFourConnected = true; + if (descriptor != null) { + player4connected = true; + p4periphs[0] = prefs.getInt(Gamepad.p4_peripheral + 1, 0); + p4periphs[1] = prefs.getInt(Gamepad.p4_peripheral + 2, 0); + } break; } } - JNIdc.initControllers(new boolean[] { controllerTwoConnected, - controllerThreeConnected, controllerFourConnected }); + JNIdc.initControllers( + new boolean[] { player2connected, player3connected, player4connected }, + new int[][] { p2periphs, p3periphs, p4periphs }); int joys[] = InputDevice.getDeviceIds(); for (int joy: joys) { String descriptor = null; @@ -189,8 +202,8 @@ public class GL2JNIActivity extends Activity { setContentView(mView); //setup mic - boolean micPluggedIn = prefs.getBoolean(Config.pref_mic, false); - if(micPluggedIn){ + boolean micPluggedIn = prefs.getBoolean(Gamepad.pref_mic, false); + if (micPluggedIn) { SipEmulator sip = new SipEmulator(); sip.startRecording(); JNIdc.setupMic(sip); diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNINative.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNINative.java index a27beb5d4..e092c6341 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNINative.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/GL2JNINative.java @@ -90,9 +90,12 @@ public class GL2JNINative extends NativeActivity { prefs.getString(Gamepad.pref_player4, null), 3); pad.deviceDescriptor_PlayerNum.remove(null); - boolean controllerTwoConnected = false; - boolean controllerThreeConnected = false; - boolean controllerFourConnected = false; + boolean player2connected = false; + boolean player3connected = false; + boolean player4connected = false; + int p2periphs[] = {0, 0}; + int p3periphs[] = {0, 0}; + int p4periphs[] = {0, 0}; for (HashMap.Entry e : pad.deviceDescriptor_PlayerNum .entrySet()) { @@ -101,22 +104,32 @@ public class GL2JNINative extends NativeActivity { switch (playerNum) { case 1: - if (descriptor != null) - controllerTwoConnected = true; + if (descriptor != null) { + player2connected = true; + p2periphs[0] = prefs.getInt(Gamepad.p2_peripheral + 1, 0); + p2periphs[1] = prefs.getInt(Gamepad.p2_peripheral + 2, 0); + } break; case 2: - if (descriptor != null) - controllerThreeConnected = true; + if (descriptor != null) { + player3connected = true; + p3periphs[0] = prefs.getInt(Gamepad.p3_peripheral + 1, 0); + p3periphs[1] = prefs.getInt(Gamepad.p3_peripheral + 2, 0); + } break; case 3: - if (descriptor != null) - controllerFourConnected = true; + if (descriptor != null) { + player4connected = true; + p4periphs[0] = prefs.getInt(Gamepad.p4_peripheral + 1, 0); + p4periphs[1] = prefs.getInt(Gamepad.p4_peripheral + 2, 0); + } break; } } - JNIdc.initControllers(new boolean[] { controllerTwoConnected, - controllerThreeConnected, controllerFourConnected }); + JNIdc.initControllers( + new boolean[] { player2connected, player3connected, player4connected }, + new int[][] { p2periphs, p3periphs, p4periphs }); int joys[] = InputDevice.getDeviceIds(); for (int joy : joys) { String descriptor = descriptor = InputDevice.getDevice(joy).getDescriptor(); @@ -189,7 +202,7 @@ public class GL2JNINative extends NativeActivity { setContentView(mView); //setup mic - boolean micPluggedIn = prefs.getBoolean(Config.pref_mic, false); + boolean micPluggedIn = prefs.getBoolean(Gamepad.pref_mic, false); if(micPluggedIn){ SipEmulator sip = new SipEmulator(); sip.startRecording(); diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/Config.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/Config.java index 831d92fc5..41245331e 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/Config.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/Config.java @@ -21,7 +21,6 @@ public class Config { public static int vibrationDuration = 20; - public static final String pref_mic = "mic_plugged_in"; public static final String pref_vmu = "vmu_floating"; public static String git_api = "https://api.github.com/repos/reicast/reicast-emulator/commits"; diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/InputFragment.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/InputFragment.java index 65dbbf869..020a3de2c 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/InputFragment.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/config/InputFragment.java @@ -18,12 +18,15 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -35,9 +38,9 @@ public class InputFragment extends Fragment { private int listenForButton = 0; private AlertDialog alertDialogSelectController; - private SharedPreferences sharedPreferences; + private SharedPreferences mPrefs; private CompoundButton switchTouchVibrationEnabled; - private CompoundButton micPluggedIntoFirstController; + private CompoundButton micPluggedIntoController; private Gamepad pad = new Gamepad(); Vibrator vib; @@ -56,10 +59,9 @@ public class InputFragment extends Fragment { @Override public void onViewCreated(View view, Bundle savedInstanceState) { - sharedPreferences = PreferenceManager - .getDefaultSharedPreferences(getActivity()); + mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); - Config.vibrationDuration = sharedPreferences.getInt(Config.pref_vibrationDuration, 20); + Config.vibrationDuration = mPrefs.getInt(Config.pref_vibrationDuration, 20); vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); ImageView icon_a = (ImageView) getView().findViewById( @@ -84,7 +86,6 @@ public class InputFragment extends Fragment { } }); - SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String home_directory = mPrefs.getString(Config.pref_home, Environment.getExternalStorageDirectory().getAbsolutePath()); @@ -95,7 +96,7 @@ public class InputFragment extends Fragment { final LinearLayout vibLay = (LinearLayout) getView().findViewById(R.id.vibDuration_layout); final SeekBar vibSeek = (SeekBar) getView().findViewById(R.id.vib_seekBar); - if (sharedPreferences.getBoolean(Config.pref_touchvibe, true)) { + if (mPrefs.getBoolean(Config.pref_touchvibe, true)) { vibLay.setVisibility(View.VISIBLE); } else { vibLay.setVisibility(View.GONE); @@ -115,7 +116,7 @@ public class InputFragment extends Fragment { public void onStopTrackingTouch(SeekBar seekBar) { int progress = seekBar.getProgress() + 5; - sharedPreferences.edit().putInt(Config.pref_vibrationDuration, progress).apply(); + mPrefs.edit().putInt(Config.pref_vibrationDuration, progress).apply(); Config.vibrationDuration = progress; vib.vibrate(progress); } @@ -124,14 +125,13 @@ public class InputFragment extends Fragment { OnCheckedChangeListener touch_vibration = new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - sharedPreferences.edit() - .putBoolean(Config.pref_touchvibe, isChecked).apply(); + mPrefs.edit().putBoolean(Config.pref_touchvibe, isChecked).apply(); vibLay.setVisibility( isChecked ? View.VISIBLE : View.GONE ); } }; switchTouchVibrationEnabled = (CompoundButton) getView().findViewById( R.id.switchTouchVibrationEnabled); - boolean vibrate = sharedPreferences.getBoolean(Config.pref_touchvibe, true); + boolean vibrate = mPrefs.getBoolean(Config.pref_touchvibe, true); if (vibrate) { switchTouchVibrationEnabled.setChecked(true); } else { @@ -139,23 +139,19 @@ public class InputFragment extends Fragment { } switchTouchVibrationEnabled.setOnCheckedChangeListener(touch_vibration); - micPluggedIntoFirstController = (CompoundButton) getView().findViewById( - R.id.micInPort2); - boolean micPluggedIn = sharedPreferences.getBoolean(Config.pref_mic, - false); - micPluggedIntoFirstController.setChecked(micPluggedIn); - if (getActivity().getPackageManager().hasSystemFeature( - PackageManager.FEATURE_MICROPHONE)) { + micPluggedIntoController = (CompoundButton) getView().findViewById(R.id.micEnabled); + boolean micPluggedIn = mPrefs.getBoolean(Gamepad.pref_mic, false); + micPluggedIntoController.setChecked(micPluggedIn); + if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE)) { // Microphone is present on the device - micPluggedIntoFirstController + micPluggedIntoController .setOnCheckedChangeListener(new OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { - sharedPreferences.edit().putBoolean(Config.pref_mic, isChecked).apply(); + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mPrefs.edit().putBoolean(Gamepad.pref_mic, isChecked).apply(); } }); } else { - micPluggedIntoFirstController.setEnabled(false); + micPluggedIntoController.setEnabled(false); } Button buttonKeycodeEditor = (Button) getView().findViewById( @@ -164,10 +160,9 @@ public class InputFragment extends Fragment { public void onClick(View v) { InputModFragment inputModFrag = new InputModFragment(); getActivity() - .getSupportFragmentManager() - .beginTransaction() - .replace(R.id.fragment_container, inputModFrag, - "INPUT_MOD_FRAG").addToBackStack(null).commit(); + .getSupportFragmentManager().beginTransaction() + .replace(R.id.fragment_container, inputModFrag, "INPUT_MOD_FRAG") + .addToBackStack(null).commit(); } }); @@ -246,20 +241,15 @@ public class InputFragment extends Fragment { } private void updateVibration() { - boolean touchVibrationEnabled = sharedPreferences.getBoolean( - Config.pref_touchvibe, true); + boolean touchVibrationEnabled = mPrefs.getBoolean(Config.pref_touchvibe, true); switchTouchVibrationEnabled.setChecked(touchVibrationEnabled); } private void updateControllers() { - String deviceDescriptorPlayer1 = sharedPreferences.getString( - Gamepad.pref_player1, null); - String deviceDescriptorPlayer2 = sharedPreferences.getString( - Gamepad.pref_player2, null); - String deviceDescriptorPlayer3 = sharedPreferences.getString( - Gamepad.pref_player3, null); - String deviceDescriptorPlayer4 = sharedPreferences.getString( - Gamepad.pref_player4, null); + String deviceDescriptorPlayer1 = mPrefs.getString(Gamepad.pref_player1, null); + String deviceDescriptorPlayer2 = mPrefs.getString(Gamepad.pref_player2, null); + String deviceDescriptorPlayer3 = mPrefs.getString(Gamepad.pref_player3, null); + String deviceDescriptorPlayer4 = mPrefs.getString(Gamepad.pref_player4, null); String labelPlayer1 = null, labelPlayer2 = null, labelPlayer3 = null, labelPlayer4 = null; @@ -319,6 +309,48 @@ public class InputFragment extends Fragment { } } + String[] periphs = getResources().getStringArray(R.array.peripherals); + + Spinner p2periph1spnr = (Spinner) getView().findViewById(R.id.spnr_player2_periph1); + ArrayAdapter p2periph1Adapter = new ArrayAdapter( + getActivity(), R.layout.spinner_selected, periphs); + p2periph1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + p2periph1spnr.setAdapter(p2periph1Adapter); + + String p2periph1 = String.valueOf(mPrefs.getInt(Gamepad.p2_peripheral + 1, 0)); + p2periph1spnr.setSelection(p2periph1Adapter.getPosition(p2periph1), true); + + p2periph1spnr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + mPrefs.edit().putInt(Gamepad.p2_peripheral + 1, pos).apply(); + } + + public void onNothingSelected(AdapterView arg0) { + + } + }); + + Spinner p2periph2spnr = (Spinner) getView().findViewById(R.id.spnr_player2_periph2); + ArrayAdapter p2periph2Adapter = new ArrayAdapter( + getActivity(), R.layout.spinner_selected, periphs); + p2periph2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + p2periph2spnr.setAdapter(p2periph2Adapter); + + String p2periph2 = String.valueOf(mPrefs.getInt(Gamepad.p2_peripheral + 2, 0)); + p2periph2spnr.setSelection(p2periph2Adapter.getPosition(p2periph2), true); + + p2periph2spnr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + mPrefs.edit().putInt(Gamepad.p2_peripheral + 2, pos).apply(); + } + + public void onNothingSelected(AdapterView arg0) { + + } + }); + TextView textViewDeviceDescriptorPlayer3 = (TextView) getView() .findViewById(R.id.textViewDeviceDescriptorPlayer3); Button buttonRemoveControllerPlayer3 = (Button) getView().findViewById( @@ -339,6 +371,46 @@ public class InputFragment extends Fragment { } } + Spinner p3periph1spnr = (Spinner) getView().findViewById(R.id.spnr_player3_periph1); + ArrayAdapter p3periph1Adapter = new ArrayAdapter( + getActivity(), R.layout.spinner_selected, periphs); + p3periph1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + p3periph1spnr.setAdapter(p3periph1Adapter); + + String p3periph1 = String.valueOf(mPrefs.getInt(Gamepad.p3_peripheral + 1, 0)); + p3periph1spnr.setSelection(p3periph1Adapter.getPosition(p3periph1), true); + + p3periph1spnr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + mPrefs.edit().putInt(Gamepad.p3_peripheral + 1, pos).apply(); + } + + public void onNothingSelected(AdapterView arg0) { + + } + }); + + Spinner p3periph2spnr = (Spinner) getView().findViewById(R.id.spnr_player3_periph2); + ArrayAdapter p3periph2Adapter = new ArrayAdapter( + getActivity(), R.layout.spinner_selected, periphs); + p3periph2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + p3periph2spnr.setAdapter(p3periph2Adapter); + + String p3periph2 = String.valueOf(mPrefs.getInt(Gamepad.p3_peripheral + 2, 0)); + p3periph2spnr.setSelection(p3periph2Adapter.getPosition(p3periph2), true); + + p3periph2spnr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + mPrefs.edit().putInt(Gamepad.p3_peripheral + 2, pos).apply(); + } + + public void onNothingSelected(AdapterView arg0) { + + } + }); + TextView textViewDeviceDescriptorPlayer4 = (TextView) getView() .findViewById(R.id.textViewDeviceDescriptorPlayer4); Button buttonRemoveControllerPlayer4 = (Button) getView().findViewById( @@ -358,6 +430,46 @@ public class InputFragment extends Fragment { buttonRemoveControllerPlayer4.setEnabled(false); } } + + Spinner p4periph1spnr = (Spinner) getView().findViewById(R.id.spnr_player4_periph1); + ArrayAdapter p4periph1Adapter = new ArrayAdapter( + getActivity(), R.layout.spinner_selected, periphs); + p4periph1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + p4periph1spnr.setAdapter(p4periph1Adapter); + + String p4periph1 = String.valueOf(mPrefs.getInt(Gamepad.p4_peripheral + 1, 0)); + p4periph1spnr.setSelection(p2periph2Adapter.getPosition(p4periph1), true); + + p4periph1spnr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + mPrefs.edit().putInt(Gamepad.p4_peripheral + 1, pos).apply(); + } + + public void onNothingSelected(AdapterView arg0) { + + } + }); + + Spinner p4periph2spnr = (Spinner) getView().findViewById(R.id.spnr_player4_periph2); + ArrayAdapter p4periph2Adapter = new ArrayAdapter( + getActivity(), R.layout.spinner_selected, periphs); + p4periph2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + p4periph2spnr.setAdapter(p4periph2Adapter); + + String p4periph2 = String.valueOf(mPrefs.getInt(Gamepad.p4_peripheral + 2, 0)); + p4periph2spnr.setSelection(p2periph2Adapter.getPosition(p4periph2), true); + + p4periph2spnr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + mPrefs.edit().putInt(Gamepad.p4_peripheral + 2, pos).apply(); + } + + public void onNothingSelected(AdapterView arg0) { + + } + }); } private void selectController(int playerNum) { @@ -414,14 +526,10 @@ public class InputFragment extends Fragment { if (descriptor == null) return false; - String deviceDescriptorPlayer1 = sharedPreferences.getString( - Gamepad.pref_player1, null); - String deviceDescriptorPlayer2 = sharedPreferences.getString( - Gamepad.pref_player2, null); - String deviceDescriptorPlayer3 = sharedPreferences.getString( - Gamepad.pref_player3, null); - String deviceDescriptorPlayer4 = sharedPreferences.getString( - Gamepad.pref_player4, null); + String deviceDescriptorPlayer1 = mPrefs.getString(Gamepad.pref_player1, null); + String deviceDescriptorPlayer2 = mPrefs.getString(Gamepad.pref_player2, null); + String deviceDescriptorPlayer3 = mPrefs.getString(Gamepad.pref_player3, null); + String deviceDescriptorPlayer4 = mPrefs.getString(Gamepad.pref_player4, null); if (descriptor.equals(deviceDescriptorPlayer1) || descriptor.equals(deviceDescriptorPlayer2) @@ -436,16 +544,16 @@ public class InputFragment extends Fragment { case 0: return false; case 1: - sharedPreferences.edit().putString(Gamepad.pref_player1, descriptor).apply(); + mPrefs.edit().putString(Gamepad.pref_player1, descriptor).apply(); break; case 2: - sharedPreferences.edit().putString(Gamepad.pref_player2, descriptor).apply(); + mPrefs.edit().putString(Gamepad.pref_player2, descriptor).apply(); break; case 3: - sharedPreferences.edit().putString(Gamepad.pref_player3, descriptor).apply(); + mPrefs.edit().putString(Gamepad.pref_player3, descriptor).apply(); break; case 4: - sharedPreferences.edit().putString(Gamepad.pref_player4, descriptor).apply(); + mPrefs.edit().putString(Gamepad.pref_player4, descriptor).apply(); break; } @@ -461,16 +569,16 @@ public class InputFragment extends Fragment { private void removeController(int playerNum) { switch (playerNum) { case 1: - sharedPreferences.edit().putString(Gamepad.pref_player1, null).apply(); + mPrefs.edit().putString(Gamepad.pref_player1, null).apply(); break; case 2: - sharedPreferences.edit().putString(Gamepad.pref_player2, null).apply(); + mPrefs.edit().putString(Gamepad.pref_player2, null).apply(); break; case 3: - sharedPreferences.edit().putString(Gamepad.pref_player3, null).apply(); + mPrefs.edit().putString(Gamepad.pref_player3, null).apply(); break; case 4: - sharedPreferences.edit().putString(Gamepad.pref_player4, null).apply(); + mPrefs.edit().putString(Gamepad.pref_player4, null).apply(); break; } diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java index 7d3093bca..781620d10 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java @@ -22,7 +22,7 @@ public final class JNIdc public static native void vjoy(int id,float x, float y, float w, float h); //public static native int play(short result[],int size); - public static native void initControllers(boolean[] controllers); + public static native void initControllers(boolean[] controllers, int[][] peripherals); public static native void setupMic(Object sip); public static native void diskSwap(String disk); diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/Gamepad.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/Gamepad.java index 644676b04..3b004df60 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/Gamepad.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/Gamepad.java @@ -23,6 +23,12 @@ public class Gamepad { public static final String pref_player4 = "device_descriptor_player_4"; public static final String pref_pad = "controller"; + public static final String pref_mic = "mic_plugged_in"; + + public static final String p2_peripheral = "p2_peripheral"; + public static final String p3_peripheral = "p3_peripheral"; + public static final String p4_peripheral = "p4_peripheral"; + public static final String pref_js_modified = "modified_key_layout"; public static final String pref_js_compat = "controller_compat"; public static final String pref_js_merged = "merged_joystick"; diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index 6a3a4f1af..fc57a1b48 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -36,7 +36,7 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, j JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_vjoy(JNIEnv * env, jobject obj,u32 id,float x, float y, float w, float h) __attribute__((visibility("default"))); //JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_play(JNIEnv *env,jobject obj,jshortArray result,jint size); -JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_initControllers(JNIEnv *env, jobject obj, jbooleanArray controllers) __attribute__((visibility("default"))); +JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_initControllers(JNIEnv *env, jobject obj, jbooleanArray controllers, jobjectArray peripherals) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupMic(JNIEnv *env,jobject obj,jobject sip) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_diskSwap(JNIEnv *env,jobject obj, jstring newdisk) __attribute__((visibility("default"))); @@ -186,6 +186,7 @@ static char CurFileName[256]; // Additonal controllers 2, 3 and 4 connected ? static bool add_controllers[3] = { false, false, false }; +int **controller_periphs; u16 kcode[4]; u32 vks[4]; @@ -256,6 +257,21 @@ void *libPvr_GetRenderSurface() void common_linux_setup(); +MapleDeviceType GetMapleDeviceType(int value) +{ + switch (value) + { + case 1: + return MDT_SegaVMU; + case 2: + return MDT_Microphone; + case 3: + return MDT_PurupuruPack; + default: + return MDT_None; + } +} + void os_SetupInput() { // Create first controller @@ -265,7 +281,10 @@ void os_SetupInput() for (int i = 0; i < 3; i++) { if (add_controllers[i]) - mcfg_CreateController(i+1, MDT_None, MDT_None); + mcfg_CreateController(i + 1, + GetMapleDeviceType(controller_periphs[i + 1][0]), + GetMapleDeviceType(controller_periphs[i + 1][1]) + ); } } @@ -384,8 +403,17 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupMic(JNIEnv *env, { sipemu = env->NewGlobalRef(sip); getmicdata = env->GetMethodID(env->GetObjectClass(sipemu),"getData","()[B"); - delete MapleDevices[0][1]; - mcfg_Create(MDT_Microphone,0,1); + for (int i = 0; i < 3; i++) + { + if (controller_periphs[i + 1][0] == MDT_Microphone) { + delete MapleDevices[i + 1][0]; + mcfg_Create(MDT_Microphone, i + 1, 0); + } + if (controller_periphs[i + 1][1] == MDT_Microphone) { + delete MapleDevices[i + 1][1]; + mcfg_Create(MDT_Microphone, i + 1, 1); + } + } } JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupVmu(JNIEnv *env,jobject obj,jobject vmu) @@ -527,11 +555,30 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_vjoy(JNIEnv * env, jo } } -JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_initControllers(JNIEnv *env, jobject obj, jbooleanArray controllers) +JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_initControllers(JNIEnv *env, jobject obj, jbooleanArray controllers, jobjectArray peripherals) { jboolean *controllers_body = env->GetBooleanArrayElements(controllers, 0); memcpy(add_controllers, controllers_body, 3); env->ReleaseBooleanArrayElements(controllers, controllers_body, 0); + + int obj_len = env->GetArrayLength(peripherals); + jintArray port = (jintArray) env->GetObjectArrayElement(peripherals, 0); + int port_len = env->GetArrayLength(port); + controller_periphs = new int*[obj_len]; + for (int i = 0; i < obj_len; ++i) { + port = (jintArray) env->GetObjectArrayElement(peripherals, i); + jint *items = env->GetIntArrayElements(port, 0); + controller_periphs[i] = new int[port_len]; + for (int j = 0; j < port_len; ++j) { + controller_periphs[i][j]= items[j]; + } + } + for (int i = 0; i < obj_len; i++) { + jintArray port = (jintArray) env->GetObjectArrayElement(peripherals, i); + jint *items = env->GetIntArrayElements(port, 0); + env->ReleaseIntArrayElements(port, items, 0); + env->DeleteLocalRef(port); + } } // Audio Stuff diff --git a/shell/android-studio/reicast/src/main/res/layout-v14/input_fragment.xml b/shell/android-studio/reicast/src/main/res/layout-v14/input_fragment.xml index 62b5a2a8d..91738d995 100644 --- a/shell/android-studio/reicast/src/main/res/layout-v14/input_fragment.xml +++ b/shell/android-studio/reicast/src/main/res/layout-v14/input_fragment.xml @@ -148,35 +148,35 @@ android:text="@string/launch_editor" /> - - - - - - - - - + + + + @@ -255,6 +255,15 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + @@ -337,6 +346,29 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + + + + + + @@ -419,6 +451,29 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + + + + + + @@ -501,6 +556,29 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + + + + + + diff --git a/shell/android-studio/reicast/src/main/res/layout/input_fragment.xml b/shell/android-studio/reicast/src/main/res/layout/input_fragment.xml index d88f02a2e..8fb6343e6 100644 --- a/shell/android-studio/reicast/src/main/res/layout/input_fragment.xml +++ b/shell/android-studio/reicast/src/main/res/layout/input_fragment.xml @@ -148,35 +148,35 @@ android:text="@string/launch_editor" /> - - - - - - - - - + + + + @@ -255,6 +255,15 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + @@ -337,6 +346,29 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + + + + + + @@ -419,6 +451,29 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + + + + + + @@ -501,6 +556,29 @@ android:layout_height="wrap_content" android:ems="10" android:text="@string/controller_none_selected" /> + + + + + + + diff --git a/shell/android-studio/reicast/src/main/res/values-da/strings.xml b/shell/android-studio/reicast/src/main/res/values-da/strings.xml index 6896ba519..340dc7e6b 100644 --- a/shell/android-studio/reicast/src/main/res/values-da/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-da/strings.xml @@ -66,8 +66,7 @@ Aktiver brugerdefineret layout Aktiver kompatibilitesmode Gamepad IME detekteret!\nDeaktiver native interface - Mikrofon tilsluttet port 2 - + Tilpas fysiske taster Tilpas controller Tryk på den nye controller taste for %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-de/strings.xml b/shell/android-studio/reicast/src/main/res/values-de/strings.xml index d119453b2..e2701f060 100644 --- a/shell/android-studio/reicast/src/main/res/values-de/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-de/strings.xml @@ -75,8 +75,7 @@ Benutzerdefiniertes Layout Kompatibilitätsmodus aktivieren Gamepad-IME erkannt!\nBitte deaktivieren Sie das native Interface. - Mikrophon in Port 2 eingesteckt - + Physische Controller anpassen Controller ändern Drücken Sie die neue Controller-Taste für %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-fr/strings.xml b/shell/android-studio/reicast/src/main/res/values-fr/strings.xml index 488a71026..a07576d0b 100644 --- a/shell/android-studio/reicast/src/main/res/values-fr/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-fr/strings.xml @@ -72,8 +72,7 @@ Last Edit: 21 May 2014 Activer la fonction de disposition des touches Activer le mode de compatibilité Manette IME détéctée!\nVeuillez S\'il vous plait désactiver l\'interface native - Microphone branché au port 2 - + Customiser les touches physiques Modifier la manette Pressez une nouvelle touche pour %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-it/strings.xml b/shell/android-studio/reicast/src/main/res/values-it/strings.xml index 2fec0e9ff..e04ad23d0 100644 --- a/shell/android-studio/reicast/src/main/res/values-it/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-it/strings.xml @@ -72,8 +72,7 @@ Abilita la Disposizione Personalizzata dei Tasti Abilita Modalità di Compatibilità Rilevato Gamepad IME !\nPer favore disabilita l\'interfaccia nativa - Microfono inserito nella porta 2 - + Personalizza Controlli Fisici Modifica Controller Premi il nuovo tasto sul controller per %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-jp/strings.xml b/shell/android-studio/reicast/src/main/res/values-jp/strings.xml index 4e3cd62b0..e7695c6b9 100644 --- a/shell/android-studio/reicast/src/main/res/values-jp/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-jp/strings.xml @@ -58,8 +58,7 @@ Dパッドとしてジョイスティックを使用 カスタムキーレイアウトを有効に 互換モードを有効に - ポート2に接続されたマイク - + 物理コントロールを編集 コントローラを編集する %1$sボタンを押してください diff --git a/shell/android-studio/reicast/src/main/res/values-pt/strings.xml b/shell/android-studio/reicast/src/main/res/values-pt/strings.xml index 79701448a..14928d7ba 100644 --- a/shell/android-studio/reicast/src/main/res/values-pt/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-pt/strings.xml @@ -75,9 +75,8 @@ Usar Joystick para entrada D-Pad Habilitar layout de botões personalizado Habilitar modo de compatibilidade - Gamepad IME detectado!\nPor favor, desative a interface nativa - Microfone conectado na porta 2 - + Gamepad IME detectado!\nPor favor, desative a interface nativa + Personalizar controles físicos Modificar controle Pressione o novo botão para o controle %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-ru/strings.xml b/shell/android-studio/reicast/src/main/res/values-ru/strings.xml index b28463f54..429deee31 100644 --- a/shell/android-studio/reicast/src/main/res/values-ru/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-ru/strings.xml @@ -79,8 +79,7 @@ Разрешить изменение раскладки Режим совместимости Обнаружен Gamepad IME!\nПожалуйста, отключите нативный интерфейс - Подключить микрофон к порту 2 - + Настройка аппаратных кнопок Настройка контроллера Нажмите кнопку контроллера для %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-zh-rCN/strings.xml b/shell/android-studio/reicast/src/main/res/values-zh-rCN/strings.xml index acf1b53a3..659b96a44 100644 --- a/shell/android-studio/reicast/src/main/res/values-zh-rCN/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-zh-rCN/strings.xml @@ -40,7 +40,6 @@ 该控制器已被使用! 启用自定义按键布局 启用兼容模式 - 麦克风已插入 Port 2 自定义物理控制 修改控制器 按下控制器按钮来映射 %1$s diff --git a/shell/android-studio/reicast/src/main/res/values-zh/strings.xml b/shell/android-studio/reicast/src/main/res/values-zh/strings.xml index 64817765d..5dacb722a 100644 --- a/shell/android-studio/reicast/src/main/res/values-zh/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values-zh/strings.xml @@ -40,7 +40,6 @@ 該控制器已被使用! 啟用自定義按鍵布局 啟用兼容模式 - 麥克風已插入 Port 2 自定義物理控制 修改控制器 按下控制器按鈕來映射 %1$s diff --git a/shell/android-studio/reicast/src/main/res/values/donottranslate.xml b/shell/android-studio/reicast/src/main/res/values/donottranslate.xml index a1249f51b..9feed5f46 100644 --- a/shell/android-studio/reicast/src/main/res/values/donottranslate.xml +++ b/shell/android-studio/reicast/src/main/res/values/donottranslate.xml @@ -67,4 +67,11 @@ pgc + + None + VMU + Microphone + Purupuru + + \ No newline at end of file diff --git a/shell/android-studio/reicast/src/main/res/values/strings.xml b/shell/android-studio/reicast/src/main/res/values/strings.xml index 3b5018134..ddc966228 100644 --- a/shell/android-studio/reicast/src/main/res/values/strings.xml +++ b/shell/android-studio/reicast/src/main/res/values/strings.xml @@ -94,7 +94,8 @@ Enable Custom Key Layout Enable Compatibility Mode Gamepad IME detected!\nPlease disable native interface - Microphone plugged into port 2 + Enable Microphone(s) + Includes 2 VMUs (Cannot be modified) Customize Physical Controls Modify Controller