changeset 4714:0f05f2f16fad

- Modified build system - Initial support for touch and key events
author Paul Hunkin <paul@bieh.net>
date Tue, 27 Jul 2010 09:58:17 +0200
parents ba38983b10c2
children 9bb98766eed0
files Makefile.android android/scripts/acc.sh android/scripts/ald.sh android/testproject/jni/app-android.cpp android/testproject/src/org/libsdl/android/SDLActivity.java build-scripts/acc.sh build-scripts/ald.sh
diffstat 7 files changed, 68 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.android	Wed Jul 07 00:43:23 2010 +1200
+++ b/Makefile.android	Tue Jul 27 09:58:17 2010 +0200
@@ -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 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/scripts/acc.sh	Tue Jul 27 09:58:17 2010 +0200
@@ -0,0 +1,15 @@
+#!/bin/bash
+ANDROID_NDK="/home/paul/Projects/gsoc/sdk/android-ndk-r4"
+TOOLS_PATH="$ANDROID_NDK/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin"
+
+export PATH=$TOOLS_PATH:$PATH
+
+CC="arm-eabi-gcc"
+
+#cflags
+ACC_C="	-I$ANDROID_NDK/build/platforms/android-8/common/include \
+		-I$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/include \
+		-DANDROID -DANDROID_NDK -c"
+		
+		
+$CC $CFLAGS $ACC_C $@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/scripts/ald.sh	Tue Jul 27 09:58:17 2010 +0200
@@ -0,0 +1,20 @@
+#!/bin/bash
+ANDROID_NDK="/home/paul/Projects/gsoc/sdk/android-ndk-r4"
+TOOLS_PATH="$ANDROID_NDK/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin"
+ADDITIONAL_LIBS=`dirname "$0"`/android_libs/
+
+export PATH=$TOOLS_PATH:$PATH
+
+LD="arm-eabi-ld"
+
+#ldflags
+ACC_L="	-rpath-link=$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/lib/ \
+		-dynamic-linker=/system/bin/linker \
+		-lc -nostdlib \
+ 		$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/lib/crtbegin_static.o \
+ 		-L$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/lib/ \
+ 		-L$ANDROID_NDK/build/prebuilt/linux-x86/arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1 \
+ 		-L$ADDITIONAL_LIBS "
+		
+$LD $ACC_L $LDFLAGS $@ -lgcc
+
--- a/android/testproject/jni/app-android.cpp	Wed Jul 07 00:43:23 2010 +1200
+++ b/android/testproject/jni/app-android.cpp	Tue Jul 27 09:58:17 2010 +0200
@@ -83,14 +83,23 @@
                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);
 }
 
 
--- a/android/testproject/src/org/libsdl/android/SDLActivity.java	Wed Jul 07 00:43:23 2010 +1200
+++ b/android/testproject/src/org/libsdl/android/SDLActivity.java	Tue Jul 27 09:58:17 2010 +0200
@@ -63,7 +63,8 @@
     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 @@
 
     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 @@
         setFocusable(true);
         setFocusableInTouchMode(true);
         requestFocus();
-        setOnKeyListener(this);      
+        setOnKeyListener(this); 
+        setOnTouchListener(this);     
     }
 
     //Called when we have a valid drawing surface
@@ -219,7 +222,7 @@
 
 
   
-
+    //Key events
     public boolean onKey(View  v, int keyCode, KeyEvent event){
 
         if(event.getAction() == KeyEvent.ACTION_DOWN){
@@ -235,6 +238,19 @@
         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;
+    }
+
 
 }
 
--- a/build-scripts/acc.sh	Wed Jul 07 00:43:23 2010 +1200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#!/bin/bash
-ANDROID_NDK="/home/paul/Projects/gsoc/sdk/android-ndk-r4"
-TOOLS_PATH="$ANDROID_NDK/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin"
-
-export PATH=$TOOLS_PATH:$PATH
-
-CC="arm-eabi-gcc"
-
-#cflags
-ACC_C="	-I$ANDROID_NDK/build/platforms/android-8/common/include \
-		-I$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/include \
-		-DANDROID -DANDROID_NDK -c"
-		
-		
-$CC $CFLAGS $ACC_C $@
--- a/build-scripts/ald.sh	Wed Jul 07 00:43:23 2010 +1200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#!/bin/bash
-ANDROID_NDK="/home/paul/Projects/gsoc/sdk/android-ndk-r4"
-TOOLS_PATH="$ANDROID_NDK/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin"
-ADDITIONAL_LIBS=`dirname "$0"`/android_libs/
-
-export PATH=$TOOLS_PATH:$PATH
-
-LD="arm-eabi-ld"
-
-#ldflags
-ACC_L="	-rpath-link=$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/lib/ \
-		-dynamic-linker=/system/bin/linker \
-		-lc -nostdlib \
- 		$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/lib/crtbegin_static.o \
- 		-L$ANDROID_NDK/build/platforms/android-8/arch-arm/usr/lib/ \
- 		-L$ANDROID_NDK/build/prebuilt/linux-x86/arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1 \
- 		-L$ADDITIONAL_LIBS "
-		
-$LD $ACC_L $LDFLAGS $@ -lgcc
-