diff --git a/android/native/jni/Android.mk b/android/native/jni/Android.mk
index 5d5b5f1edf..15cb1952f2 100644
--- a/android/native/jni/Android.mk
+++ b/android/native/jni/Android.mk
@@ -38,6 +38,7 @@ LOCAL_SRC_FILES = $(RARCH_PATH)/retroarch.c \
$(RARCH_PATH)/gfx/fonts/null_fonts.c \
$(RARCH_PATH)/gfx/state_tracker.c \
$(RARCH_PATH)/input/null.c \
+ input_android.c \
$(RARCH_PATH)/screenshot.c \
$(RARCH_PATH)/conf/config_file.c \
$(RARCH_PATH)/autosave.c \
diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c
new file mode 100644
index 0000000000..cc0be2134a
--- /dev/null
+++ b/android/native/jni/input_android.c
@@ -0,0 +1,80 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2012 - Hans-Kristian Arntzen
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include "android-general.h"
+#include "../../../general.h"
+#include "../../../driver.h"
+
+/**
+ * Process the next input event.
+ */
+static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
+{
+ if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
+ {
+ g_android.animating = 1;
+ g_android.state.x = AMotionEvent_getX(event, 0);
+ g_android.state.y = AMotionEvent_getY(event, 0);
+ //RARCH_LOG("AINPUT_EVENT_TYPE_MOTION - x: %d, y: %d.\n");
+ return 1;
+ }
+ return 0;
+}
+
+static void *android_input_init(void)
+{
+ g_android.app->onInputEvent = engine_handle_input;
+ return (void*)-1;
+}
+
+static void android_input_poll(void *data)
+{
+ (void)data;
+}
+
+static int16_t android_input_state(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id)
+{
+ (void)data;
+ (void)retro_keybinds;
+ (void)port;
+ (void)device;
+ (void)index;
+ (void)id;
+
+ return 0;
+}
+
+static bool android_input_key_pressed(void *data, int key)
+{
+ (void)data;
+ (void)key;
+
+ return false;
+}
+
+static void android_input_free(void *data)
+{
+ (void)data;
+}
+
+const input_driver_t input_android = {
+ android_input_init,
+ android_input_poll,
+ android_input_state,
+ android_input_key_pressed,
+ android_input_free,
+ "android_input",
+};
+
diff --git a/android/native/jni/main.c b/android/native/jni/main.c
index 5f16c31f32..c2cc82d0d1 100644
--- a/android/native/jni/main.c
+++ b/android/native/jni/main.c
@@ -18,45 +18,15 @@
#include
#include
-#include /* Requires NDK r5 or newer */
-#include
-
#include "android-general.h"
#include "../../../general.h"
-//forward declarations
-void gfx_ctx_swap_buffers(void);
-void gfx_ctx_clear(void);
-void gfx_ctx_destroy(void);
-bool gfx_ctx_init(void);
-
-
JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt)
{
- RARCH_LOG("JNI_OnLoad.\n" );
-
return JNI_VERSION_1_2;
}
-JNIEXPORT void JNICALL JNI_OnUnLoad( JavaVM *vm, void *pvt)
-{
- RARCH_LOG("JNI_OnUnLoad.\n" );
-}
-
-/**
- * Process the next input event.
- */
-static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
-{
- if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
- {
- g_android.animating = 1;
- g_android.state.x = AMotionEvent_getX(event, 0);
- g_android.state.y = AMotionEvent_getY(event, 0);
- return 1;
- }
- return 0;
-}
+JNIEXPORT void JNICALL JNI_OnUnLoad( JavaVM *vm, void *pvt) { }
/**
* Process the next main command.
@@ -84,17 +54,15 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd)
break;
case APP_CMD_GAINED_FOCUS:
// When our app gains focus, we start monitoring the accelerometer.
- /*
if (g_android.accelerometerSensor != NULL)
{
- */
ASensorEventQueue_enableSensor(g_android.sensorEventQueue,
g_android.accelerometerSensor);
// We'd like to get 60 events per second (in us).
ASensorEventQueue_setEventRate(g_android.sensorEventQueue,
g_android.accelerometerSensor, (1000L/60)*1000);
- //}
+ }
break;
case APP_CMD_LOST_FOCUS:
// When our app loses focus, we stop monitoring the accelerometer.
@@ -169,7 +137,6 @@ void android_main(struct android_app* state)
snprintf(libretro_path, sizeof(libretro_path), "/data/data/com.retroarch/lib/libretro.so");
g_android.app->onAppCmd = engine_handle_cmd;
- g_android.app->onInputEvent = engine_handle_input;
// Prepare to monitor accelerometer
g_android.sensorManager = ASensorManager_getInstance();
diff --git a/config.def.h b/config.def.h
index 17e816b1f6..a35344f6b9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -58,6 +58,7 @@ enum
AUDIO_XDK360,
AUDIO_NULL,
+ INPUT_ANDROID,
INPUT_SDL,
INPUT_X,
INPUT_DINPUT,
@@ -131,6 +132,8 @@ enum
#define INPUT_DEFAULT_DRIVER INPUT_XENON360
#elif defined(_XBOX360) || defined(_XBOX) || defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1)
#define INPUT_DEFAULT_DRIVER INPUT_XINPUT
+#elif defined(ANDROID)
+#define INPUT_DEFAULT_DRIVER INPUT_ANDROID
#elif defined(_WIN32)
#define INPUT_DEFAULT_DRIVER INPUT_DINPUT
#elif defined(HAVE_SDL)
diff --git a/driver.c b/driver.c
index 2275ffbb52..2a193697e4 100644
--- a/driver.c
+++ b/driver.c
@@ -132,6 +132,9 @@ static const input_driver_t *input_drivers[] = {
#ifdef GEKKO
&input_gx,
#endif
+#ifdef ANDROID
+ &input_android,
+#endif
#if defined(__linux__) && !defined(ANDROID)
&input_linuxraw,
#endif
diff --git a/driver.h b/driver.h
index 211c649bba..de1447e193 100644
--- a/driver.h
+++ b/driver.h
@@ -280,6 +280,7 @@ extern const video_driver_t video_sdl;
extern const video_driver_t video_vg;
extern const video_driver_t video_ext;
extern const video_driver_t video_null;
+extern const input_driver_t input_android;
extern const input_driver_t input_sdl;
extern const input_driver_t input_dinput;
extern const input_driver_t input_x;
diff --git a/settings.c b/settings.c
index c3e9f62fcd..034f5eb8c6 100644
--- a/settings.c
+++ b/settings.c
@@ -105,6 +105,8 @@ const char *config_get_default_input(void)
{
switch (INPUT_DEFAULT_DRIVER)
{
+ case INPUT_ANDROID:
+ return "android_input";
case INPUT_PS3:
return "ps3";
case INPUT_SDL: