Android: Add an option for disabling native motion controls
This commit is contained in:
parent
c8b8a60033
commit
2d4a3f4597
|
@ -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_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
|
||||||
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
|
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_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
|
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_SET_IR_SENSITIVITY = 27;
|
||||||
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
|
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
|
||||||
public static final int MENU_ACTION_SCREEN_ORIENTATION = 29;
|
public static final int MENU_ACTION_SCREEN_ORIENTATION = 29;
|
||||||
|
public static final int MENU_ACTION_MOTION_CONTROLS = 30;
|
||||||
|
|
||||||
|
|
||||||
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
||||||
|
@ -183,6 +184,8 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
EmulationActivity.MENU_ACTION_CHOOSE_DOUBLETAP);
|
EmulationActivity.MENU_ACTION_CHOOSE_DOUBLETAP);
|
||||||
buttonsActionsMap.append(R.id.menu_screen_orientation,
|
buttonsActionsMap.append(R.id.menu_screen_orientation,
|
||||||
EmulationActivity.MENU_ACTION_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)
|
private static String[] scanForSecondDisc(GameFile gameFile)
|
||||||
|
@ -349,7 +352,7 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (!sIsGameCubeGame)
|
if (!sIsGameCubeGame && mPreferences.getInt("motionControlsEnabled", 0) != 2)
|
||||||
mMotionListener.enable();
|
mMotionListener.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +360,6 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (!sIsGameCubeGame)
|
|
||||||
mMotionListener.disable();
|
mMotionListener.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,6 +653,10 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
chooseOrientation();
|
chooseOrientation();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case MENU_ACTION_MOTION_CONTROLS:
|
||||||
|
showMotionControlsOptions();
|
||||||
|
return;
|
||||||
|
|
||||||
case MENU_ACTION_EXIT:
|
case MENU_ACTION_EXIT:
|
||||||
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
|
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
|
||||||
if (TvUtil.isLeanback(getApplicationContext()))
|
if (TvUtil.isLeanback(getApplicationContext()))
|
||||||
|
@ -888,6 +894,32 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
alertDialog.show();
|
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()
|
private void chooseOrientation()
|
||||||
{
|
{
|
||||||
final int[] orientationValues = getResources().getIntArray(R.array.orientationValues);
|
final int[] orientationValues = getResources().getIntArray(R.array.orientationValues);
|
||||||
|
|
|
@ -18,6 +18,8 @@ public class MotionListener implements SensorEventListener
|
||||||
private final Sensor mAccelSensor;
|
private final Sensor mAccelSensor;
|
||||||
private final Sensor mGyroSensor;
|
private final Sensor mGyroSensor;
|
||||||
|
|
||||||
|
private boolean mEnabled = false;
|
||||||
|
|
||||||
// The same sampling period as for Wii Remotes
|
// The same sampling period as for Wii Remotes
|
||||||
private static final int SAMPLING_PERIOD_US = 1000000 / 200;
|
private static final int SAMPLING_PERIOD_US = 1000000 / 200;
|
||||||
|
|
||||||
|
@ -97,18 +99,28 @@ public class MotionListener implements SensorEventListener
|
||||||
|
|
||||||
public void enable()
|
public void enable()
|
||||||
{
|
{
|
||||||
|
if (mEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
if (mAccelSensor != null)
|
if (mAccelSensor != null)
|
||||||
mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US);
|
mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US);
|
||||||
if (mGyroSensor != null)
|
if (mGyroSensor != null)
|
||||||
mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US);
|
mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US);
|
||||||
|
|
||||||
NativeLibrary.SetMotionSensorsEnabled(mAccelSensor != null, mGyroSensor != null);
|
NativeLibrary.SetMotionSensorsEnabled(mAccelSensor != null, mGyroSensor != null);
|
||||||
|
|
||||||
|
mEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable()
|
public void disable()
|
||||||
{
|
{
|
||||||
|
if (!mEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
mSensorManager.unregisterListener(this);
|
mSensorManager.unregisterListener(this);
|
||||||
|
|
||||||
NativeLibrary.SetMotionSensorsEnabled(false, false);
|
NativeLibrary.SetMotionSensorsEnabled(false, false);
|
||||||
|
|
||||||
|
mEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,10 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_choose_controller"
|
android:id="@+id/menu_emulation_choose_controller"
|
||||||
android:title="@string/emulation_choose_controller"/>
|
android:title="@string/emulation_choose_controller"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_motion_controls"
|
||||||
|
android:title="@string/emulation_motion_controls"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_ir_group"
|
android:id="@+id/menu_emulation_ir_group"
|
||||||
android:title="@string/emulation_ir_group"
|
android:title="@string/emulation_ir_group"
|
||||||
|
|
|
@ -359,4 +359,10 @@
|
||||||
<item>1</item>
|
<item>1</item>
|
||||||
<item>-1</item>
|
<item>-1</item>
|
||||||
</integer-array>
|
</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>
|
</resources>
|
||||||
|
|
|
@ -314,6 +314,7 @@
|
||||||
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
|
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
|
||||||
<string name="emulation_choose_doubletap">Double tap button</string>
|
<string name="emulation_choose_doubletap">Double tap button</string>
|
||||||
<string name="emulation_screen_orientation">Screen Orientation</string>
|
<string name="emulation_screen_orientation">Screen Orientation</string>
|
||||||
|
<string name="emulation_motion_controls">Motion Controls</string>
|
||||||
|
|
||||||
<!-- GC Adapter Menu-->
|
<!-- GC Adapter Menu-->
|
||||||
<string name="gc_adapter_rumble">Enable Vibration</string>
|
<string name="gc_adapter_rumble">Enable Vibration</string>
|
||||||
|
|
Loading…
Reference in New Issue