Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
- Modified build system
Browse files Browse the repository at this point in the history
- Initial support for touch and key events
  • Loading branch information
bieh committed Jul 27, 2010
1 parent b839e97 commit 0c36b9b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion 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
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 11 additions & 2 deletions android/testproject/jni/app-android.cpp
Expand Up @@ -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);
}


Expand Down
24 changes: 20 additions & 4 deletions android/testproject/src/org/libsdl/android/SDLActivity.java
Expand Up @@ -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);



Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -219,7 +222,7 @@ public void flipEGL(){




//Key events
public boolean onKey(View v, int keyCode, KeyEvent event){

if(event.getAction() == KeyEvent.ACTION_DOWN){
Expand All @@ -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;
}


}

Expand Down

0 comments on commit 0c36b9b

Please sign in to comment.