Android: Add an option for disabling native motion controls

This commit is contained in:
JosJuice 2019-11-20 20:09:16 +01:00
parent c8b8a60033
commit 2d4a3f4597
5 changed files with 59 additions and 4 deletions

View File

@ -100,7 +100,7 @@ public final class EmulationActivity extends AppCompatActivity
MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP,
MENU_ACTION_SCREEN_ORIENTATION})
MENU_ACTION_SCREEN_ORIENTATION, MENU_ACTION_MOTION_CONTROLS})
public @interface MenuAction
{
}
@ -135,6 +135,7 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_SET_IR_SENSITIVITY = 27;
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
public static final int MENU_ACTION_SCREEN_ORIENTATION = 29;
public static final int MENU_ACTION_MOTION_CONTROLS = 30;
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@ -183,6 +184,8 @@ public final class EmulationActivity extends AppCompatActivity
EmulationActivity.MENU_ACTION_CHOOSE_DOUBLETAP);
buttonsActionsMap.append(R.id.menu_screen_orientation,
EmulationActivity.MENU_ACTION_SCREEN_ORIENTATION);
buttonsActionsMap.append(R.id.menu_emulation_motion_controls,
EmulationActivity.MENU_ACTION_MOTION_CONTROLS);
}
private static String[] scanForSecondDisc(GameFile gameFile)
@ -349,7 +352,7 @@ public final class EmulationActivity extends AppCompatActivity
protected void onResume()
{
super.onResume();
if (!sIsGameCubeGame)
if (!sIsGameCubeGame && mPreferences.getInt("motionControlsEnabled", 0) != 2)
mMotionListener.enable();
}
@ -357,7 +360,6 @@ public final class EmulationActivity extends AppCompatActivity
protected void onPause()
{
super.onPause();
if (!sIsGameCubeGame)
mMotionListener.disable();
}
@ -651,6 +653,10 @@ public final class EmulationActivity extends AppCompatActivity
chooseOrientation();
return;
case MENU_ACTION_MOTION_CONTROLS:
showMotionControlsOptions();
return;
case MENU_ACTION_EXIT:
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
if (TvUtil.isLeanback(getApplicationContext()))
@ -888,6 +894,32 @@ public final class EmulationActivity extends AppCompatActivity
alertDialog.show();
}
private void showMotionControlsOptions()
{
final SharedPreferences.Editor editor = mPreferences.edit();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_motion_controls);
builder.setSingleChoiceItems(R.array.motionControlsEntries,
mPreferences.getInt("motionControlsEnabled", 0),
(dialog, indexSelected) ->
{
editor.putInt("motionControlsEnabled", indexSelected);
if (indexSelected != 2)
mMotionListener.enable();
else
mMotionListener.disable();
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "IMUIR/Enabled",
indexSelected != 1 ? "True" : "False");
NativeLibrary.ReloadWiimoteConfig();
});
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> editor.apply());
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
private void chooseOrientation()
{
final int[] orientationValues = getResources().getIntArray(R.array.orientationValues);

View File

@ -18,6 +18,8 @@ public class MotionListener implements SensorEventListener
private final Sensor mAccelSensor;
private final Sensor mGyroSensor;
private boolean mEnabled = false;
// The same sampling period as for Wii Remotes
private static final int SAMPLING_PERIOD_US = 1000000 / 200;
@ -97,18 +99,28 @@ public class MotionListener implements SensorEventListener
public void enable()
{
if (mEnabled)
return;
if (mAccelSensor != null)
mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US);
if (mGyroSensor != null)
mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US);
NativeLibrary.SetMotionSensorsEnabled(mAccelSensor != null, mGyroSensor != null);
mEnabled = true;
}
public void disable()
{
if (!mEnabled)
return;
mSensorManager.unregisterListener(this);
NativeLibrary.SetMotionSensorsEnabled(false, false);
mEnabled = false;
}
}

View File

@ -112,6 +112,10 @@
<item
android:id="@+id/menu_emulation_choose_controller"
android:title="@string/emulation_choose_controller"/>
<item
android:id="@+id/menu_emulation_motion_controls"
android:title="@string/emulation_motion_controls"/>
<item
android:id="@+id/menu_emulation_ir_group"
android:title="@string/emulation_ir_group"

View File

@ -359,4 +359,10 @@
<item>1</item>
<item>-1</item>
</integer-array>
<string-array name="motionControlsEntries">
<item>Use Device Sensors (With Pointer Emulation)</item>
<item>Use Device Sensors (Without Pointer Emulation)</item>
<item>Don\'t Use Device Sensors</item>
</string-array>
</resources>

View File

@ -314,6 +314,7 @@
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
<string name="emulation_choose_doubletap">Double tap button</string>
<string name="emulation_screen_orientation">Screen Orientation</string>
<string name="emulation_motion_controls">Motion Controls</string>
<!-- GC Adapter Menu-->
<string name="gc_adapter_rumble">Enable Vibration</string>