summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2022-01-01 18:31:50 +0100
committerJosJuice <josjuice@gmail.com>2023-03-03 22:28:23 +0100
commitca508e45033c022dbef558a11d170ab7f41c7bf9 (patch)
treecc916c031647ec8d5cadd0120c7d81b3022cccf4 /Source/Android/app/src/main/java
parent792cb6219533bd9ce5154da9a87f6eabddfaa977 (diff)
ControllerInterface/Android: Handle input events
Android doesn't let us poll inputs whenever we want. Instead, we listen to input events (activities will have to forward them to the input backend), and store the received values in atomic variables in the Input classes. This is similar in concept to how ButtonManager worked, but without its homegrown second input mapping system.
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java23
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.java31
2 files changed, 44 insertions, 10 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 a90209b264..699e28a9e8 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
@@ -11,7 +11,6 @@ import android.os.Build;
import android.os.Bundle;
import android.util.Pair;
import android.util.SparseIntArray;
-import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -42,6 +41,7 @@ import org.dolphinemu.dolphinemu.databinding.ActivityEmulationBinding;
import org.dolphinemu.dolphinemu.databinding.DialogInputAdjustBinding;
import org.dolphinemu.dolphinemu.databinding.DialogIrSensitivityBinding;
import org.dolphinemu.dolphinemu.databinding.DialogSkylandersManagerBinding;
+import org.dolphinemu.dolphinemu.features.input.model.ControllerInterface;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
@@ -61,7 +61,6 @@ import org.dolphinemu.dolphinemu.overlay.InputOverlayPointer;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.main.ThemeProvider;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
-import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.IniFile;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;
@@ -855,13 +854,15 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
- if (mMenuVisible || event.getKeyCode() == KeyEvent.KEYCODE_BACK)
+ if (!mMenuVisible)
{
- return super.dispatchKeyEvent(event);
+ if (ControllerInterface.dispatchKeyEvent(event))
+ {
+ return true;
+ }
}
- // TODO
- return false;
+ return super.dispatchKeyEvent(event);
}
private void toggleControls()
@@ -1217,13 +1218,15 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event)
{
- if (mMenuVisible)
+ if (!mMenuVisible)
{
- return false;
+ if (ControllerInterface.dispatchGenericMotionEvent(event))
+ {
+ return true;
+ }
}
- // TODO
- return false;
+ return super.dispatchGenericMotionEvent(event);
}
private void showSubMenu(SaveLoadStateFragment.SaveOrLoad saveOrLoad)
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.java
new file mode 100644
index 0000000000..80d21eeb57
--- /dev/null
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.java
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package org.dolphinemu.dolphinemu.features.input.model;
+
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+/**
+ * This class interfaces with the native ControllerInterface,
+ * which is where the emulator core gets inputs from.
+ */
+public final class ControllerInterface
+{
+ /**
+ * Activities which want to pass on inputs to native code
+ * should call this in their own dispatchKeyEvent method.
+ *
+ * @return true if the emulator core seems to be interested in this event.
+ * false if the event should be passed on to the default dispatchKeyEvent.
+ */
+ public static native boolean dispatchKeyEvent(KeyEvent event);
+
+ /**
+ * Activities which want to pass on inputs to native code
+ * should call this in their own dispatchGenericMotionEvent method.
+ *
+ * @return true if the emulator core seems to be interested in this event.
+ * false if the event should be passed on to the default dispatchGenericMotionEvent.
+ */
+ public static native boolean dispatchGenericMotionEvent(MotionEvent event);
+}