summaryrefslogtreecommitdiff
path: root/Source/Android
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2019-11-20 20:09:16 +0100
committerJosJuice <josjuice@gmail.com>2019-11-20 23:21:06 +0100
commit2d4a3f4597f14b2563fac7acf080b91fa4bac5e8 (patch)
tree9090485f7d21128ee282ee4b10bff6e55d3eb191 /Source/Android
parentc8b8a60033bb35917c10eeb5c4043ee428ae61a6 (diff)
Android: Add an option for disabling native motion controls
Diffstat (limited to 'Source/Android')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java40
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java12
-rw-r--r--Source/Android/app/src/main/res/menu/menu_emulation_wii.xml4
-rw-r--r--Source/Android/app/src/main/res/values/arrays.xml6
-rw-r--r--Source/Android/app/src/main/res/values/strings.xml1
5 files changed, 59 insertions, 4 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
index f6756d30b0..4f4ddf2c71 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
@@ -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,8 +360,7 @@ public final class EmulationActivity extends AppCompatActivity
protected void onPause()
{
super.onPause();
- if (!sIsGameCubeGame)
- mMotionListener.disable();
+ mMotionListener.disable();
}
@Override
@@ -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);
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java
index 4230b0b7bc..31d1641aba 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java
@@ -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;
}
}
diff --git a/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml b/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml
index d8b1de13ff..73a4d6a506 100644
--- a/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml
+++ b/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml
@@ -113,6 +113,10 @@
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"
app:showAsAction="never">
diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml
index aa0a403402..84d5a3b617 100644
--- a/Source/Android/app/src/main/res/values/arrays.xml
+++ b/Source/Android/app/src/main/res/values/arrays.xml
@@ -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>
diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml
index 14b992aea2..fa48815ec9 100644
--- a/Source/Android/app/src/main/res/values/strings.xml
+++ b/Source/Android/app/src/main/res/values/strings.xml
@@ -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>