Add Soft keyboard and wrapper of the key event (first step ==> can really be better)

This commit is contained in:
Edouard Dupin 2012-04-20 17:56:23 +02:00
parent 751a0712d8
commit 7cc9076ab8
7 changed files with 449 additions and 253 deletions

View File

@ -2,6 +2,7 @@
PROJECT_PACKAGE=$(PROJECT_NAME)package
JAVA_FOLDER=src/com/$(PROJECT_VENDOR)/$(PROJECT_NAME)
EWOL_JAVA_FOLDER=src/org/ewol
all:
@ -16,19 +17,22 @@ all:
@echo " (sh) Clear previous sources "
@rm -rf src jni/ewolAndroidAbstraction.cpp
@echo " (sh) Create folder : $(JAVA_FOLDER)/ "
@echo " (sh) Create folder : $(JAVA_FOLDER)/ & $(EWOL_JAVA_FOLDER)"
@mkdir -p $(JAVA_FOLDER)/
@mkdir -p $(EWOL_JAVA_FOLDER)/
@echo " (sh) copy the java File : "
@echo " (sh) copy the java Files & Replace __XXX__ element with project properties"
@cp $(EWOL_FOLDER)/Java/PROJECT_NAME.java $(JAVA_FOLDER)/$(PROJECT_NAME).java
@echo " (sh) Replace __PROJECT_VENDOR__, __PROJECT_NAME__ and __PROJECT_PACKAGE__ with the correct intance "
@sed -i "s|__PROJECT_VENDOR__|$(PROJECT_VENDOR)|" $(JAVA_FOLDER)/$(PROJECT_NAME).java
@sed -i "s|__PROJECT_NAME__|$(PROJECT_NAME)|" $(JAVA_FOLDER)/$(PROJECT_NAME).java
@sed -i "s|__PROJECT_PACKAGE__|$(PROJECT_PACKAGE)|" $(JAVA_FOLDER)/$(PROJECT_NAME).java
# copy the Ewol java files :
@cp $(EWOL_FOLDER)/Java/interfaceJNI.java $(EWOL_JAVA_FOLDER)/
@cp $(EWOL_FOLDER)/Java/interfaceOpenGL.java $(EWOL_JAVA_FOLDER)/
@cp $(EWOL_FOLDER)/Java/interfaceSurfaceView.java $(EWOL_JAVA_FOLDER)/
@echo " (sh) copy the cpp for jni File : $(EWOL_FOLDER)/SourcesJava/ewolAndroidAbstraction.cpp"
@cp $(EWOL_FOLDER)/Java/ewolAndroidAbstraction.cpp jni/
@echo " (sh) Replace __PROJECT_VENDOR__, __PROJECT_NAME__ and __PROJECT_PACKAGE__ with the correct intance "
@sed -i "s|__PROJECT_VENDOR__|$(PROJECT_VENDOR)|" jni/ewolAndroidAbstraction.cpp
@sed -i "s|__PROJECT_NAME__|$(PROJECT_NAME)|" jni/ewolAndroidAbstraction.cpp
@sed -i "s|__PROJECT_PACKAGE__|$(PROJECT_PACKAGE)|" jni/ewolAndroidAbstraction.cpp

View File

@ -1,10 +1,31 @@
/**
*******************************************************************************
* @file ewol __PROJECT_NAME__.java
* @brief Java __PROJECT_NAME__ code.
* @author Edouard DUPIN
* @date 20/04/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
package com.__PROJECT_VENDOR__.__PROJECT_PACKAGE__;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.content.Context;
@ -32,29 +53,26 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
// inport the ewol package :
import org.ewol.interfaceJNI;
import org.ewol.interfaceSurfaceView;
import java.io.IOException;
/**
* @brief Class :
*
*/
public class __PROJECT_NAME__ extends Activity {
private static native void TouchEvent();
private static native void ActivitySetJavaVortualMachineStart(__PROJECT_NAME__ ActivityInstance);
//private static native void ActivitySetJavaVortualMachineStart();
private static native void ActivitySetJavaVortualMachineStop();
private static native void ActivityOnCreate();
private static native void ActivityOnStart();
private static native void ActivityOnReStart();
private static native void ActivityOnResume();
private static native void ActivityOnPause();
private static native void ActivityOnStop();
private static native void ActivityOnDestroy();
private static native void ActivityParamSetArchiveDir(int mode, String myString);
private GLSurfaceView mGLView;
private interfaceSurfaceView mGLView;
static {
System.loadLibrary("__PROJECT_PACKAGE__");
//ActivitySetInstance(this);
}
@Override protected void onCreate(Bundle savedInstanceState)
@ -64,7 +82,6 @@ public class __PROJECT_NAME__ extends Activity {
// set the java evironement in the C sources :
ActivitySetJavaVortualMachineStart(this);
//ActivitySetJavaVortualMachineStart();
// Load the application directory
ActivityParamSetArchiveDir(1, getFilesDir().toString());
@ -87,7 +104,7 @@ public class __PROJECT_NAME__ extends Activity {
// call C init ...
ActivityOnCreate();
interfaceJNI.ActivityOnCreate();
// Remove the title of the current display :
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -99,8 +116,10 @@ public class __PROJECT_NAME__ extends Activity {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//Force landscape
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// create bsurface system
mGLView = new EwolGLSurfaceView(this);
mGLView = new interfaceSurfaceView(this);
setContentView(mGLView);
}
@ -108,14 +127,14 @@ public class __PROJECT_NAME__ extends Activity {
{
super.onStart();
// call C
ActivityOnStart();
interfaceJNI.ActivityOnStart();
}
@Override protected void onRestart()
{
super.onRestart();
// call C
ActivityOnReStart();
interfaceJNI.ActivityOnReStart();
}
@Override protected void onResume()
@ -123,7 +142,7 @@ public class __PROJECT_NAME__ extends Activity {
super.onResume();
mGLView.onResume();
// call C
ActivityOnResume();
interfaceJNI.ActivityOnResume();
}
@Override protected void onPause()
@ -131,20 +150,20 @@ public class __PROJECT_NAME__ extends Activity {
super.onPause();
mGLView.onPause();
// call C
ActivityOnPause();
interfaceJNI.ActivityOnPause();
}
@Override protected void onStop()
{
super.onStop();
// call C
ActivityOnStop();
interfaceJNI.ActivityOnStop();
}
@Override protected void onDestroy()
{
super.onDestroy();
// call C
ActivityOnDestroy();
interfaceJNI.ActivityOnDestroy();
// Remove the java Virtual machine pointer form the C code
ActivitySetJavaVortualMachineStop();
}
@ -162,120 +181,24 @@ public class __PROJECT_NAME__ extends Activity {
public void CPP_keyboardShow()
{
TouchEvent();
try{
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
} catch (Exception e) {
}
TouchEvent();
interfaceJNI.TouchEvent();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
public void CPP_keyboardHide()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0 ,InputMethodManager.HIDE_IMPLICIT_ONLY + InputMethodManager.HIDE_NOT_ALWAYS);
}
public static void eventFromCPP(String[] args)
{
// just for the test ...
TouchEvent();
interfaceJNI.TouchEvent();
}
}
/**
* @brief Class :
*
*/
class EwolGLSurfaceView extends GLSurfaceView {
private static native void nativeApplicationInit();
private static native void nativeApplicationUnInit();
private static native void nativeEventInputMotion(int pointerID, float x, float y);
private static native void nativeEventInputState(int pointerID, boolean isDown, float x, float y);
private static native void nativeEventUnknow(int eventID);
public EwolGLSurfaceView(Context context) {
// super must be first statement in constructor
super(context);
// je n'ai pas compris ...
mRenderer = new EwolRenderer();
setRenderer(mRenderer);
nativeApplicationInit();
}
private boolean InputDown1 = false;
private boolean InputDown2 = false;
private boolean InputDown3 = false;
public boolean onTouchEvent(final MotionEvent event) {
// Wrapper on input events :
int tmpActionType = event.getAction();
if (tmpActionType == MotionEvent.ACTION_MOVE) {
final int pointerCount = event.getPointerCount();
for (int p = 0; p < pointerCount; p++) {
nativeEventInputMotion(event.getPointerId(p), (float)event.getX(p), (float)event.getY(p));
}
} else if( tmpActionType == MotionEvent.ACTION_POINTER_1_DOWN
|| tmpActionType == MotionEvent.ACTION_DOWN) {
nativeEventInputState(event.getPointerId(0), true, (float)event.getX(0), (float)event.getY(0));
InputDown1 = true;
} else if(tmpActionType == MotionEvent.ACTION_POINTER_1_UP) {
nativeEventInputState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown1 = false;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_2_DOWN) {
nativeEventInputState(event.getPointerId(1), true, (float)event.getX(1), (float)event.getY(1));
InputDown2 = true;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_2_UP) {
nativeEventInputState(event.getPointerId(1), false, (float)event.getX(1), (float)event.getY(1));
InputDown2 = false;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_3_DOWN) {
nativeEventInputState(event.getPointerId(2), true, (float)event.getX(2), (float)event.getY(2));
InputDown3 = true;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_3_UP) {
nativeEventInputState(event.getPointerId(2), false, (float)event.getX(2), (float)event.getY(2));
InputDown3 = false;
} else if(tmpActionType == MotionEvent.ACTION_UP){
if (InputDown1) {
nativeEventInputState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown1 = false;
} else if (InputDown2) {
nativeEventInputState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown2 = false;
} else {
nativeEventInputState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown3 = false;
}
}
return true;
}
public boolean onKeyDown (int keyCode, KeyEvent event){
// TODO ...
return true;
}
EwolRenderer mRenderer;
}
/**
* @brief Class :
*
*/
class EwolRenderer implements GLSurfaceView.Renderer {
private static native void nativeInit();
private static native void nativeResize(int w, int h);
private static native void nativeRender();
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
nativeInit();
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
nativeResize(w, h);
}
public void onDrawFrame(GL10 gl) {
nativeRender();
}
}

View File

@ -48,6 +48,7 @@ static jclass javaClassActivity = 0; // main activity class (andro
static jobject javaObjectActivity = 0;
static jmethodID javaClassActivityEntryPoint = 0; // basic methode to call ...
static jmethodID javaClassActivityEntryPoint__CPP_keyboardShow = 0; // basic methode to call ...
static jmethodID javaClassActivityEntryPoint__CPP_keyboardHide = 0; // basic methode to call ...
// generic classes
static jclass javaDefaultClassString = 0; // default string class
@ -57,84 +58,7 @@ static JavaVM* g_JavaVM = NULL;
// jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include
// for exemple test :
void displayKeyboard(bool pShow) {
// Attaches the current thread to the JVM.
jint lResult;
jint lFlags = 0;
JavaVM* lJavaVM = g_JavaVM;
JNIEnv* lJNIEnv = NULL;
int status = g_JavaVM->GetEnv((void **) &lJNIEnv, JNI_VERSION_1_6);
if (status == JNI_EDETACHED) {
JavaVMAttachArgs lJavaVMAttachArgs;
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
lJavaVMAttachArgs.name = "EwolNativeThread";
lJavaVMAttachArgs.group = NULL;
status = g_JavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
if (status != JNI_OK) {
APPL_DEBUG("C->java : AttachCurrentThread failed : " << status);
return;
}
if (JavaVirtualMachinePointer->ExceptionOccurred()) {
JavaVirtualMachinePointer->ExceptionDescribe();
JavaVirtualMachinePointer->ExceptionClear();
}
}
/*
if (lResult == JNI_ERR) {
return;
}
*/
if (JavaVirtualMachinePointer->ExceptionOccurred()) {
JavaVirtualMachinePointer->ExceptionDescribe();
JavaVirtualMachinePointer->ExceptionClear();
}
// Retrieves NativeActivity.
jobject lNativeActivity = javaClassActivity;
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
// Retrieves Context.INPUT_METHOD_SERVICE.
jclass ClassContext = lJNIEnv->FindClass("android/content/Context");
jfieldID FieldINPUT_METHOD_SERVICE = lJNIEnv->GetStaticFieldID(ClassContext, "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
jobject INPUT_METHOD_SERVICE = lJNIEnv->GetStaticObjectField(ClassContext, FieldINPUT_METHOD_SERVICE);
// TODO : jniCheck(INPUT_METHOD_SERVICE);
// Runs getSystemService(Context.INPUT_METHOD_SERVICE).
jclass ClassInputMethodManager = lJNIEnv->FindClass("android/view/inputmethod/InputMethodManager");
jmethodID MethodGetSystemService = lJNIEnv->GetMethodID(ClassNativeActivity, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
jobject lInputMethodManager = lJNIEnv->CallObjectMethod(lNativeActivity, MethodGetSystemService, INPUT_METHOD_SERVICE);
// Runs getWindow().getDecorView().
jmethodID MethodGetWindow = lJNIEnv->GetMethodID(ClassNativeActivity, "getWindow", "()Landroid/view/Window;");
jobject lWindow = lJNIEnv->CallObjectMethod(lNativeActivity, MethodGetWindow);
jclass ClassWindow = lJNIEnv->FindClass("android/view/Window");
jmethodID MethodGetDecorView = lJNIEnv->GetMethodID(ClassWindow, "getDecorView", "()Landroid/view/View;");
jobject lDecorView = lJNIEnv->CallObjectMethod(lWindow, MethodGetDecorView);
if (pShow) {
// Runs lInputMethodManager.showSoftInput(...).
jmethodID MethodShowSoftInput = lJNIEnv->GetMethodID( ClassInputMethodManager, "showSoftInput", "(Landroid/view/View;I)Z");
jboolean lResult = lJNIEnv->CallBooleanMethod(lInputMethodManager, MethodShowSoftInput, lDecorView, lFlags);
} else {
// Runs lWindow.getViewToken()
jclass ClassView = lJNIEnv->FindClass("android/view/View");
jmethodID MethodGetWindowToken = lJNIEnv->GetMethodID(ClassView, "getWindowToken", "()Landroid/os/IBinder;");
jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView, MethodGetWindowToken);
// lInputMethodManager.hideSoftInput(...).
jmethodID MethodHideSoftInput = lJNIEnv->GetMethodID( ClassInputMethodManager, "hideSoftInputFromWindow", "(Landroid/os/IBinder;I)Z");
jboolean lRes = lJNIEnv->CallBooleanMethod( lInputMethodManager, MethodHideSoftInput, lBinder, lFlags);
}
// Finished with the JVM.
lJavaVM->DetachCurrentThread();
}
void SendJava_KeyboardShow(void)
void SendJava_KeyboardShow(bool showIt)
{
APPL_DEBUG("C->java : call java");
if (NULL == g_JavaVM) {
@ -165,20 +89,18 @@ void SendJava_KeyboardShow(void)
JavaVirtualMachinePointer->ExceptionClear();
}
APPL_DEBUG("C->java : 111");
if (NULL == JavaVirtualMachinePointer) {
APPL_DEBUG("C->java : JVM not initialised");
return;
}
APPL_DEBUG("C->java : 333");
//Call java ...
//JavaVirtualMachinePointer->CallVoidMethod(javaClassActivity, javaClassActivityEntryPoint__CPP_keyboardShow);
//JavaVirtualMachinePointer->CallStaticVoidMethod(javaClassActivity, javaClassActivityEntryPoint__CPP_keyboardShow);
JavaVirtualMachinePointer->CallVoidMethod(javaObjectActivity, javaClassActivityEntryPoint__CPP_keyboardShow);
if (true == showIt) {
JavaVirtualMachinePointer->CallVoidMethod(javaObjectActivity, javaClassActivityEntryPoint__CPP_keyboardShow);
} else {
JavaVirtualMachinePointer->CallVoidMethod(javaObjectActivity, javaClassActivityEntryPoint__CPP_keyboardHide);
}
APPL_DEBUG("C->java : 444");
// manage execption :
if (JavaVirtualMachinePointer->ExceptionOccurred()) {
APPL_DEBUG("C->java : EXEPTION ...");
@ -249,6 +171,9 @@ void SendSystemMessage(const char * dataString)
g_JavaVM->DetachCurrentThread();
}
namespace guiAbstraction {
void SendKeyboardEvent(bool isDown, uniChar_t keyInput);
};
extern "C"
{
@ -308,13 +233,21 @@ extern "C"
return;
}
javaClassActivityEntryPoint__CPP_keyboardShow = JavaVirtualMachinePointer->GetMethodID(javaClassActivity, "CPP_keyboardShow", "()V" );
if (javaClassActivityEntryPoint == 0) {
if (javaClassActivityEntryPoint__CPP_keyboardShow == 0) {
APPL_DEBUG("C->java : Can't find com/__PROJECT_VENDOR__/__PROJECT_PACKAGE__/__PROJECT_NAME__.CPP_keyboardShow" );
// remove access on the virtual machine :
JavaVirtualMachinePointer = NULL;
return;
}
javaObjectActivity = JavaVirtualMachinePointer->NewGlobalRef(obj);
javaClassActivityEntryPoint__CPP_keyboardHide = JavaVirtualMachinePointer->GetMethodID(javaClassActivity, "CPP_keyboardHide", "()V" );
if (javaClassActivityEntryPoint__CPP_keyboardHide == 0) {
APPL_DEBUG("C->java : Can't find com/__PROJECT_VENDOR__/__PROJECT_PACKAGE__/__PROJECT_NAME__.CPP_keyboardHide" );
// remove access on the virtual machine :
JavaVirtualMachinePointer = NULL;
return;
}
//javaObjectActivity = JavaVirtualMachinePointer->NewGlobalRef(obj);
javaObjectActivity = obj;
javaDefaultClassString = JavaVirtualMachinePointer->FindClass("java/lang/String" );
if (javaDefaultClassString == 0) {
@ -332,7 +265,7 @@ extern "C"
APPL_DEBUG("*******************************************");
JavaVirtualMachinePointer = NULL;
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___TouchEvent( JNIEnv* env )
void Java_org_ewol_interfaceJNI_TouchEvent( JNIEnv* env )
{
APPL_DEBUG(" ==> Touch Event");
if (env->ExceptionOccurred()) {
@ -341,33 +274,33 @@ extern "C"
}
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnCreate( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnCreate( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Create **");
APPL_DEBUG("*******************************************");
EWOL_SystemStart();
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnStart( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnStart( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Start **");
APPL_DEBUG("*******************************************");
//SendSystemMessage(" testmessages ... ");
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnReStart( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnReStart( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Re-Start **");
APPL_DEBUG("*******************************************");
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnResume( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnResume( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Resume **");
APPL_DEBUG("*******************************************");
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnPause( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnPause( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Pause **");
@ -376,13 +309,13 @@ extern "C"
// TODO : Mark all the texture to be reloaded ...
EWOL_NativeGLDestroy();
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnStop( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnStop( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Stop **");
APPL_DEBUG("*******************************************");
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE_____PROJECT_NAME___ActivityOnDestroy( JNIEnv* env )
void Java_org_ewol_interfaceJNI_ActivityOnDestroy( JNIEnv* env )
{
APPL_DEBUG("*******************************************");
APPL_DEBUG("** Activity On Destroy **");
@ -391,42 +324,86 @@ extern "C"
}
/* Call to initialize the graphics state */
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolRenderer_nativeInit( JNIEnv* env )
{
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolRenderer_nativeResize( JNIEnv* env, jobject thiz, jint w, jint h )
{
EWOL_ThreadResize(w, h);
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolGLSurfaceView_nativeEventInputMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y )
/* **********************************************************************************************
* ** IO section :
* ********************************************************************************************** */
void Java_org_ewol_interfaceJNI_IOInputEventMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y )
{
EWOL_ThreadEventInputMotion(pointerID+1, x, y);
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolGLSurfaceView_nativeEventInputState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y )
void Java_org_ewol_interfaceJNI_IOInputEventState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y )
{
EWOL_ThreadEventInputState(pointerID+1, isUp, x, y);
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolGLSurfaceView_nativeApplicationInit( JNIEnv* env)
void Java_org_ewol_interfaceJNI_IOInputEventUnknow( JNIEnv* env, jobject thiz, jint pointerID)
{
//ewol::threadMsg::SendMessage(androidJniMsg, JNI_APP_INIT);
//EWOL_NativeApplicationInit();
APPL_DEBUG("Unknown IO event : " << pointerID << " ???");
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolGLSurfaceView_nativeApplicationUnInit( JNIEnv* env)
void Java_org_ewol_interfaceJNI_IOKeyboardEventMove( JNIEnv* env, jobject thiz, jint type, jboolean isdown)
{
//ewol::threadMsg::SendMessage(androidJniMsg, JNI_APP_UN_INIT);
//EWOL_NativeApplicationUnInit();
APPL_DEBUG("IO keyboard Move event : \"" << type << "\" is down=" << isdown);
}
void Java_com___PROJECT_VENDOR_____PROJECT_PACKAGE___EwolRenderer_nativeRender( JNIEnv* env )
void Java_org_ewol_interfaceJNI_IOKeyboardEventKey( JNIEnv* env, jobject thiz, jint uniChar, jboolean isdown)
{
APPL_DEBUG("IO keyboard Key event : \"" << uniChar << "\" is down=" << isdown);
guiAbstraction::SendKeyboardEvent(isdown, uniChar);
}
enum {
SYSTEM_KEY__VOLUME_UP = 1,
SYSTEM_KEY__VOLUME_DOWN,
SYSTEM_KEY__MENU,
SYSTEM_KEY__CAMERA,
SYSTEM_KEY__HOME,
SYSTEM_KEY__POWER,
};
void Java_org_ewol_interfaceJNI_IOKeyboardEventKeySystem( JNIEnv* env, jobject thiz, jint keyVal, jboolean isdown)
{
switch (keyVal)
{
case SYSTEM_KEY__VOLUME_UP:
APPL_DEBUG("IO keyboard Key System \"VOLUME_UP\" is down=" << keyVal);
break;
case SYSTEM_KEY__VOLUME_DOWN:
APPL_DEBUG("IO keyboard Key System \"VOLUME_DOWN\" is down=" << keyVal);
break;
case SYSTEM_KEY__MENU:
APPL_DEBUG("IO keyboard Key System \"MENU\" is down=" << keyVal);
break;
case SYSTEM_KEY__CAMERA:
APPL_DEBUG("IO keyboard Key System \"CAMERA\" is down=" << keyVal);
break;
case SYSTEM_KEY__HOME:
APPL_DEBUG("IO keyboard Key System \"HOME\" is down=" << keyVal);
break;
case SYSTEM_KEY__POWER:
APPL_DEBUG("IO keyboard Key System \"POWER\" is down=" << keyVal);
break;
default:
APPL_DEBUG("IO keyboard Key System event : \"" << keyVal << "\" is down=" << isdown);
break;
}
}
/* **********************************************************************************************
* ** Renderer section :
* ********************************************************************************************** */
void Java_org_ewol_interfaceJNI_RenderInit( JNIEnv* env )
{
}
void Java_org_ewol_interfaceJNI_RenderResize( JNIEnv* env, jobject thiz, jint w, jint h )
{
EWOL_ThreadResize(w, h);
}
void Java_org_ewol_interfaceJNI_RenderDraw( JNIEnv* env )
{
EWOL_NativeRender();
}

56
Java/interfaceJNI.java Normal file
View File

@ -0,0 +1,56 @@
/**
*******************************************************************************
* @file ewol interfaceJNI.java
* @brief Java interface to the CPP code.
* @author Edouard DUPIN
* @date 20/04/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
package org.ewol;
public class interfaceJNI {
public static native void TouchEvent();
// activity status
public static native void ActivityOnCreate();
public static native void ActivityOnStart();
public static native void ActivityOnReStart();
public static native void ActivityOnResume();
public static native void ActivityOnPause();
public static native void ActivityOnStop();
public static native void ActivityOnDestroy();
// IO native function :
public static native void IOInputEventMotion(int pointerID, float x, float y);
public static native void IOInputEventState(int pointerID, boolean isDown, float x, float y);
public static native void IOInputEventUnknow(int eventID);
public static native void IOKeyboardEventMove(int type, boolean isDown);
public static native void IOKeyboardEventKey(int uniChar, boolean isDown);
public static int EWOL_SYSTEM_KEY__VOLUME_UP = 1;
public static int EWOL_SYSTEM_KEY__VOLUME_DOWN = 2;
public static int EWOL_SYSTEM_KEY__MENU = 3;
public static int EWOL_SYSTEM_KEY__CAMERA = 4;
public static int EWOL_SYSTEM_KEY__HOME = 5;
public static int EWOL_SYSTEM_KEY__POWER = 6;
public static native void IOKeyboardEventKeySystem(int keyVal, boolean isDown);
// renderer Event :
public static native void RenderInit();
public static native void RenderResize(int w, int h);
public static native void RenderDraw();
}

52
Java/interfaceOpenGL.java Normal file
View File

@ -0,0 +1,52 @@
/**
*******************************************************************************
* @file ewol interfaceOpenGL.java
* @brief Java openGl interface code.
* @author Edouard DUPIN
* @date 20/04/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
package org.ewol;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
// inport the ewol package :
import org.ewol.interfaceJNI;
/**
* @brief Class :
*
*/
public class interfaceOpenGL implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
interfaceJNI.RenderInit();
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
interfaceJNI.RenderResize(w, h);
}
public void onDrawFrame(GL10 gl) {
interfaceJNI.RenderDraw();
}
}

View File

@ -0,0 +1,184 @@
/**
*******************************************************************************
* @file ewol interfaceSurfaceView.java
* @brief Java interface of the java Surface viewer code.
* @author Edouard DUPIN
* @date 20/04/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
package org.ewol;
// inport the ewol package :
import org.ewol.interfaceJNI;
import org.ewol.interfaceOpenGL;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.KeyEvent;
/**
* @brief Class :
*
*/
public class interfaceSurfaceView extends GLSurfaceView {
private interfaceOpenGL m_ewolDrawer;
public interfaceSurfaceView(Context context) {
// super must be first statement in constructor
super(context);
// je n'ai pas compris ...
m_ewolDrawer = new interfaceOpenGL();
setRenderer(m_ewolDrawer);
// Can get the focus ==> get keyboard from JAVA :
setFocusable(true);
setFocusableInTouchMode(true);
}
private boolean InputDown1 = false;
private boolean InputDown2 = false;
private boolean InputDown3 = false;
public boolean onTouchEvent(final MotionEvent event) {
// Wrapper on input events :
int tmpActionType = event.getAction();
if (tmpActionType == MotionEvent.ACTION_MOVE) {
final int pointerCount = event.getPointerCount();
for (int p = 0; p < pointerCount; p++) {
interfaceJNI.IOInputEventMotion(event.getPointerId(p), (float)event.getX(p), (float)event.getY(p));
}
} else if( tmpActionType == MotionEvent.ACTION_POINTER_1_DOWN
|| tmpActionType == MotionEvent.ACTION_DOWN) {
interfaceJNI.IOInputEventState(event.getPointerId(0), true, (float)event.getX(0), (float)event.getY(0));
InputDown1 = true;
} else if(tmpActionType == MotionEvent.ACTION_POINTER_1_UP) {
interfaceJNI.IOInputEventState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown1 = false;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_2_DOWN) {
interfaceJNI.IOInputEventState(event.getPointerId(1), true, (float)event.getX(1), (float)event.getY(1));
InputDown2 = true;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_2_UP) {
interfaceJNI.IOInputEventState(event.getPointerId(1), false, (float)event.getX(1), (float)event.getY(1));
InputDown2 = false;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_3_DOWN) {
interfaceJNI.IOInputEventState(event.getPointerId(2), true, (float)event.getX(2), (float)event.getY(2));
InputDown3 = true;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_3_UP) {
interfaceJNI.IOInputEventState(event.getPointerId(2), false, (float)event.getX(2), (float)event.getY(2));
InputDown3 = false;
} else if(tmpActionType == MotionEvent.ACTION_UP){
if (InputDown1) {
interfaceJNI.IOInputEventState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown1 = false;
} else if (InputDown2) {
interfaceJNI.IOInputEventState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown2 = false;
} else {
interfaceJNI.IOInputEventState(event.getPointerId(0), false, (float)event.getX(0), (float)event.getY(0));
InputDown3 = false;
}
}
return true;
}
private boolean keyboardEvent(int keyCode, KeyEvent event, boolean isDown)
{
int actionDone = event.getAction();
switch(keyCode)
{
case KeyEvent.KEYCODE_VOLUME_DOWN:
interfaceJNI.IOKeyboardEventKeySystem(interfaceJNI.EWOL_SYSTEM_KEY__VOLUME_DOWN, isDown);
return true;
case KeyEvent.KEYCODE_VOLUME_UP:
interfaceJNI.IOKeyboardEventKeySystem(interfaceJNI.EWOL_SYSTEM_KEY__VOLUME_UP, isDown);
return true;
case KeyEvent.KEYCODE_MENU:
interfaceJNI.IOKeyboardEventKeySystem(interfaceJNI.EWOL_SYSTEM_KEY__MENU, isDown);
return true;
case KeyEvent.KEYCODE_CAMERA:
interfaceJNI.IOKeyboardEventKeySystem(interfaceJNI.EWOL_SYSTEM_KEY__CAMERA, isDown);
return true;
case KeyEvent.KEYCODE_HOME:
interfaceJNI.IOKeyboardEventKeySystem(interfaceJNI.EWOL_SYSTEM_KEY__HOME, isDown);
return true;
case KeyEvent.KEYCODE_POWER:
interfaceJNI.IOKeyboardEventKeySystem(interfaceJNI.EWOL_SYSTEM_KEY__POWER, isDown);
return true;
case KeyEvent.KEYCODE_BACK:
// the back key is wrapped in the <esc> key to simplify PC validation ...
interfaceJNI.IOKeyboardEventKey(0x1B, isDown);
return true;
case KeyEvent.KEYCODE_DEL:
interfaceJNI.IOKeyboardEventKey(0x08, isDown);
return true;
case KeyEvent.KEYCODE_ALT_LEFT:
// TODO : ...
break;
case KeyEvent.KEYCODE_SHIFT_LEFT:
// TODO : ...
break;
case KeyEvent.KEYCODE_ENTER:
// TODO : ...
break;
// Joystick event :
case KeyEvent.KEYCODE_DPAD_UP:
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
break;
default:
break;
}
// key wrapping :
if( (actionDone == KeyEvent.ACTION_DOWN)
|| (actionDone == KeyEvent.ACTION_MULTIPLE)
|| (actionDone == KeyEvent.ACTION_UP))
{
// convert the key in UniChar to prevent errors ...
int uchar = event.getUnicodeChar();
// send it to ewol ...
interfaceJNI.IOKeyboardEventKey(uchar, isDown);
return true;
}
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return keyboardEvent(keyCode, event, true);
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
return keyboardEvent(keyCode, event, false);
}
}

View File

@ -250,18 +250,18 @@ void guiAbstraction::Stop(void)
// java system to send message :
void SendSystemMessage(const char * dataString);
void SendJava_KeyboardShow(void);
void SendJava_KeyboardShow(bool showIt);
void guiAbstraction::KeyboardShow(ewol::keyboardMode_te mode)
{
// send a message at the java :
SendJava_KeyboardShow();
SendJava_KeyboardShow(true);
}
void guiAbstraction::KeyboardHide(void)
{
// send a message at the java :
SendSystemMessage("Keyboard_Hide");
SendJava_KeyboardShow(false);
}
void guiAbstraction::ChangeSize(int32_t w, int32_t h)