From 0c36b9bb164e688bd89dbd3aa06a98986b11502b Mon Sep 17 00:00:00 2001 From: Paul Hunkin Date: Tue, 27 Jul 2010 09:58:17 +0200 Subject: [PATCH] - Modified build system - Initial support for touch and key events --- Makefile.android | 3 ++- {build-scripts => android/scripts}/acc.sh | 0 {build-scripts => android/scripts}/ald.sh | 0 android/testproject/jni/app-android.cpp | 13 ++++++++-- .../src/org/libsdl/android/SDLActivity.java | 24 +++++++++++++++---- 5 files changed, 33 insertions(+), 7 deletions(-) rename {build-scripts => android/scripts}/acc.sh (100%) rename {build-scripts => android/scripts}/ald.sh (100%) diff --git a/Makefile.android b/Makefile.android index bf6b2838e..7959f76de 100755 --- a/Makefile.android +++ b/Makefile.android @@ -1,6 +1,7 @@ # Makefile to build the SDL library -ANDROID_NDK=/home/paul/Projects/gsoc/sdk/android-ndk-r4 +include ./android/config.cfg #get ANDROID_NDK + TOOLS_PATH=$(ANDROID_NDK)/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin ANDROID_INCLUDES = -I$(ANDROID_NDK)/build/platforms/android-4/common/include \ -I$(ANDROID_NDK)/build/platforms/android-4/arch-arm/usr/include diff --git a/build-scripts/acc.sh b/android/scripts/acc.sh similarity index 100% rename from build-scripts/acc.sh rename to android/scripts/acc.sh diff --git a/build-scripts/ald.sh b/android/scripts/ald.sh similarity index 100% rename from build-scripts/ald.sh rename to android/scripts/ald.sh diff --git a/android/testproject/jni/app-android.cpp b/android/testproject/jni/app-android.cpp index 85e869156..2b7451aa0 100644 --- a/android/testproject/jni/app-android.cpp +++ b/android/testproject/jni/app-android.cpp @@ -83,14 +83,23 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env jobject obj, jint keycode){ int r = Android_OnKeyDown(keycode); - __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: native key down %d, %d\n", keycode, r); + __android_log_print(ANDROID_LOG_INFO, "SDL", + "SDL: native key down %d, %d\n", keycode, r); } extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env, jobject obj, jint keycode){ int r = Android_OnKeyUp(keycode); - __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: native key up %d, %d\n", keycode, r); + __android_log_print(ANDROID_LOG_INFO, "SDL", + "SDL: native key up %d, %d\n", keycode, r); +} + +extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env, + jobject obj, jint action, jfloat x, jfloat y, jfloat p){ + __android_log_print(ANDROID_LOG_INFO, "SDL", + "SDL: native touch event %d @ %f/%f, pressure %f\n", + action, x, y, p); } diff --git a/android/testproject/src/org/libsdl/android/SDLActivity.java b/android/testproject/src/org/libsdl/android/SDLActivity.java index c1a1ec5b0..d94e9bd9e 100644 --- a/android/testproject/src/org/libsdl/android/SDLActivity.java +++ b/android/testproject/src/org/libsdl/android/SDLActivity.java @@ -63,7 +63,8 @@ protected void onResume() { public static native void nativeInit(); public static native void onNativeKeyDown(int keycode); public static native void onNativeKeyUp(int keycode); - + public static native void onNativeTouch(int action, float x, + float y, float p); @@ -104,7 +105,8 @@ public void run(){ Because of this, that's where we set up the SDL thread */ -class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, View.OnKeyListener { +class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, + View.OnKeyListener, View.OnTouchListener { //This is what SDL runs in. It invokes SDL_main(), eventually private Thread mSDLThread; @@ -122,7 +124,8 @@ public SDLSurface(Context context) { setFocusable(true); setFocusableInTouchMode(true); requestFocus(); - setOnKeyListener(this); + setOnKeyListener(this); + setOnTouchListener(this); } //Called when we have a valid drawing surface @@ -219,7 +222,7 @@ public void flipEGL(){ - + //Key events public boolean onKey(View v, int keyCode, KeyEvent event){ if(event.getAction() == KeyEvent.ACTION_DOWN){ @@ -235,6 +238,19 @@ else if(event.getAction() == KeyEvent.ACTION_UP){ return false; } + //Touch events + public boolean onTouch(View v, MotionEvent event){ + + int action = event.getAction(); + float x = event.getX(); + float y = event.getY(); + float p = event.getPressure(); + + //TODO: Anything else we need to pass? + SDLActivity.onNativeTouch(action, x, y, p); + return true; + } + }