Skip to content
Permalink
Browse files

Android: Add an option for disabling native motion controls

  • Loading branch information
JosJuice committed Nov 20, 2019
1 parent c8b8a60 commit 2d4a3f4597f14b2563fac7acf080b91fa4bac5e8
@@ -100,7 +100,7 @@
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 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 @@
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,16 +352,15 @@ protected void restoreState(Bundle savedInstanceState)
protected void onResume()
{
super.onResume();
if (!sIsGameCubeGame)
if (!sIsGameCubeGame && mPreferences.getInt("motionControlsEnabled", 0) != 2)
mMotionListener.enable();
}

@Override
protected void onPause()
{
super.onPause();
if (!sIsGameCubeGame)
mMotionListener.disable();
mMotionListener.disable();
}

@Override
@@ -651,6 +653,10 @@ public void handleMenuAction(@MenuAction int menuAction)
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 @@ private void chooseController()
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);
@@ -18,6 +18,8 @@
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 void onAccuracyChanged(Sensor sensor, int i)

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;
}
}
@@ -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"
@@ -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>
@@ -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>

0 comments on commit 2d4a3f4

Please sign in to comment.
You can’t perform that action at this time.