Correction of the input event coming fro android ==> event generation work coreectly ...

This commit is contained in:
Edouard Dupin 2011-12-10 11:02:00 +01:00
parent fb6f1e0703
commit dc102185db
5 changed files with 147 additions and 64 deletions

View File

@ -48,7 +48,7 @@ class Plop :public ewol::Windows
ewol::SizerHori * mySizer = new ewol::SizerHori();
SetSubWidget(mySizer);
ewol::Button * myButton = new ewol::Button("Mon Labell 1");
ewol::Button * myButton = new ewol::Button("LB");
mySizer->SubWidgetAdd(myButton);
ewol::SizerVert * mySizerVert = new ewol::SizerVert();
@ -62,11 +62,11 @@ class Plop :public ewol::Windows
ewol::Test * myTest = new ewol::Test();
mySizerVert->SubWidgetAdd(myTest);
ewol::CheckBox * myCheckBox = new ewol::CheckBox("mon label d'exemple de test");
ewol::CheckBox * myCheckBox = new ewol::CheckBox("mon label d'eK");
mySizerVert->SubWidgetAdd(myCheckBox);
myCheckBox = new ewol::CheckBox("Exemple 2");
mySizerVert->SubWidgetAdd(myCheckBox);
myCheckBox = new ewol::CheckBox("Exemple 3 et plus si afinité");
myCheckBox = new ewol::CheckBox("Exemple 3 et éà$");
mySizerVert->SubWidgetAdd(myCheckBox);
myTest = new ewol::Test();
@ -102,7 +102,8 @@ void APP_Init(int argc, char *argv[])
*/
ewol::SetFontFolder("dataTest/Font");
//ewol::SetDefaultFont("freefont/FreeMono", 14);
ewol::SetDefaultFont("ebtfont/Monospace", 14);
//ewol::SetDefaultFont("ebtfont/Monospace", 14);
ewol::SetDefaultFont("ebtfont/Monospace", 33);
//ewol::theme::LoadDefault("dataTest/exemple.eol");
etk::File fileTmp("dataTest/exemple.eol", etk::FILE_TYPE_DATA);
ewol::theme::LoadDefault(fileTmp);

View File

@ -49,4 +49,7 @@ namespace guiAbstraction
void APP_Init(int argc, char *argv[]);
void APP_UnInit(void);
#define NB_MAX_INPUT (20)
#define SEPARATED_CLICK_TIME (30)
#endif

View File

@ -55,7 +55,7 @@ static etkFloat_t m_height = 480;
ewol::Windows* m_uniqueWindows = NULL;
static long _getTime(void)
static int32_t times(char* tmpVar)
{
struct timeval now;
gettimeofday(&now, NULL);
@ -64,12 +64,17 @@ static long _getTime(void)
void Draw(void);
#define MAX_INPUT (3)
etkFloat_t inputX[MAX_INPUT] = {0.0, 0.0, 0.0}
etkFloat_t inputY[MAX_INPUT] = {0.0, 0.0, 0.0}
bool inputIsPressed[MAX_INPUT] = {false, false, false};
#define OFFSET_MOVE_CLICKED (20)
#define OFFSET_MOVE_CLICKED_DOUBLE (40)
bool inputIsPressed[NB_MAX_INPUT];// = {false, false, false};
int32_t m_previousBouttonId = -1;
int32_t m_previousDown_x = -1;
int32_t m_previousDown_y = -1;
int32_t m_previous_x = -1;
int32_t m_previous_y = -1;
int64_t m_previousTime = 0;
bool m_previousDouble = false;
extern "C"
{
@ -105,44 +110,128 @@ extern "C"
ewol::TextureOGLContext(false);
}
/* This is called to indicate to the render loop that it should
* stop as soon as possible.
*/
void Java_com_example_ewolAbstraction_EwolGLSurfaceView_nativePause( JNIEnv* env )
{
sDemoStopped = !sDemoStopped;
if (sDemoStopped) {
/* we paused the animation, so store the current
* time in sTimeStopped for future nativeRender calls */
sTimeStopped = _getTime();
} else {
/* we resumed the animation, so adjust the time offset
* to take care of the pause interval. */
sTimeOffset -= _getTime() - sTimeStopped;
}
}
void Java_com_example_ewolAbstraction_EwolGLSurfaceView_nativeEventInputMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y )
{
EWOL_INFO("Event : Input Motion ID=" << pointerID << " x=" << x << " y=" << y);
if (0 == pointerID) {
//appMove(x,y);
if(NULL != m_uniqueWindows) {
m_uniqueWindows->GenEventInput(ewol::FLAG_EVENT_INPUT_1, ewol::EVENT_INPUT_TYPE_DOWN, (etkFloat_t)x, (etkFloat_t)y);
m_uniqueWindows->GenEventInput(ewol::FLAG_EVENT_INPUT_1, ewol::EVENT_INPUT_TYPE_UP, (etkFloat_t)x, (etkFloat_t)y);
m_uniqueWindows->GenEventInput(ewol::FLAG_EVENT_INPUT_1 | ewol::FLAG_EVENT_INPUT_CLICKED, ewol::EVENT_INPUT_TYPE_SINGLE, (etkFloat_t)x, (etkFloat_t)y);
//m_uniqueWindows->CalculateSize((etkFloat_t)m_width, (etkFloat_t)m_height);
//EWOL_INFO("Event : Input Motion ID=" << pointerID << " x=" << x << " y=" << y);
if(0<=pointerID && pointerID < NB_MAX_INPUT ) {
if (true == inputIsPressed[pointerID]) {
if(NULL != m_uniqueWindows) {
//EWOL_DEBUG("ANDROID event: bt=" << pointerID+1 << " ** = \"MotionNotify\" (" << (etkFloat_t)x << "," << (etkFloat_t)y << ")");
m_uniqueWindows->GenEventInput(pointerID+1, ewol::EVENT_INPUT_TYPE_MOVE, (etkFloat_t)x, (etkFloat_t)y);
}
}
}
}
void Java_com_example_ewolAbstraction_EwolGLSurfaceView_nativeEventInputState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp)
void Java_com_example_ewolAbstraction_EwolGLSurfaceView_nativeEventInputState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y )
{
if (isUp) {
EWOL_INFO("Event : Input ID=" << pointerID << " [DOWN]");
//EWOL_INFO("Event : Input ID=" << pointerID << " [DOWN] x=" << x << " y=" << y);
if(0<=pointerID && pointerID < NB_MAX_INPUT ) {
// Send Down message
if (NULL != m_uniqueWindows) {
//EWOL_DEBUG("ANDROID bt=" << pointerID+1 << " event : **=\"ButtonPress\" (" << (etkFloat_t)x << "," << (etkFloat_t)y << ")");
m_uniqueWindows->GenEventInput(pointerID+1, ewol::EVENT_INPUT_TYPE_DOWN, (etkFloat_t)x, (etkFloat_t)y);
}
// Check double or triple click event ...
m_previousDown_x = x;
m_previousDown_y = y;
if (m_previousBouttonId != pointerID+1) {
m_previousBouttonId = pointerID+1;
m_previous_x = -1;
m_previous_y = -1;
m_previousTime = 0;
m_previousDouble = false;
} else {
if( abs(m_previous_x - x) < OFFSET_MOVE_CLICKED
&& abs(m_previous_y - y) < OFFSET_MOVE_CLICKED )
{
// nothink to do ... wait up ...
} else {
m_previous_x = -1;
m_previous_y = -1;
m_previousTime = 0;
m_previousDouble = false;
}
}
}
} else {
EWOL_INFO("Event : Input ID=" << pointerID << " [UP]");
//EWOL_INFO("Event : Input ID=" << pointerID << " [UP] x=" << x << " y=" << y);
if(0<=pointerID && pointerID < NB_MAX_INPUT ) {
// Send Down message
if (NULL != m_uniqueWindows) {
//EWOL_DEBUG("ANDROID bt=" << pointerID+1 << " event : **=\"ButtonRelease\" (" << (etkFloat_t)x << "," << (etkFloat_t)y << ")");
m_uniqueWindows->GenEventInput(pointerID+1, ewol::EVENT_INPUT_TYPE_UP, (etkFloat_t)x, (etkFloat_t)y);
}
if (m_previousBouttonId != pointerID+1) {
m_previousDown_x = -1;
m_previousDown_y = -1;
m_previousBouttonId = 0;
m_previous_x = -1;
m_previous_y = -1;
m_previousTime = 0;
m_previousDouble = false;
} else {
int64_t currentTime = times(NULL); // return the tic in 10ms
//EWOL_DEBUG("time is : " << currentTime << " "<< currentTime/100 <<"s " << (currentTime%100)*10 << "ms");
if (currentTime - m_previousTime >= SEPARATED_CLICK_TIME) {
//check if the same area click :
if( abs(m_previousDown_x - x) < OFFSET_MOVE_CLICKED
&& abs(m_previousDown_y - y) < OFFSET_MOVE_CLICKED )
{
// might generate an sigle event :
//EWOL_DEBUG("ANDROID event : ** = \"ButtonClickedSingle\" (" << (etkFloat_t)x << "," << (etkFloat_t)y << ")");
m_uniqueWindows->GenEventInput(pointerID+1, ewol::EVENT_INPUT_TYPE_SINGLE, (etkFloat_t)x, (etkFloat_t)y);
m_previous_x = m_previousDown_x;
m_previous_y = m_previousDown_y;
m_previousTime = currentTime;
} else {
// reset values ...
m_previousDown_x = -1;
m_previousDown_y = -1;
m_previousBouttonId = 0;
m_previous_x = -1;
m_previous_y = -1;
m_previousTime = 0;
}
m_previousDouble = false;
} else {
// TODO : the double ckick does not work, I need to check this later ... if needed
//check if the same area click :
if( abs(m_previous_x - x) < OFFSET_MOVE_CLICKED_DOUBLE
&& abs(m_previous_y - y) < OFFSET_MOVE_CLICKED_DOUBLE )
{
// might generate an sigle event :
if (false == m_previousDouble) {
//EWOL_DEBUG("ANDROID event : ** = \"ButtonClickedDouble\" (" << (etkFloat_t)x << "," << (etkFloat_t)y << ")");
m_uniqueWindows->GenEventInput(pointerID+1, ewol::EVENT_INPUT_TYPE_DOUBLE, (etkFloat_t)x, (etkFloat_t)y);
m_previousTime = currentTime;
m_previousDouble = true;
} else {
//EWOL_DEBUG("ANDROID event : ** = \"ButtonClickedTriple\" (" << (etkFloat_t)x << "," << (etkFloat_t)y << ")");
m_uniqueWindows->GenEventInput(pointerID+1, ewol::EVENT_INPUT_TYPE_TRIPLE, (etkFloat_t)x, (etkFloat_t)y);
// reset values ...
m_previousDown_x = -1;
m_previousDown_y = -1;
m_previousBouttonId = 0;
m_previous_x = -1;
m_previous_y = -1;
m_previousTime = 0;
m_previousDouble = false;
}
} else {
// reset values ...
m_previousDown_x = -1;
m_previousDown_y = -1;
m_previousBouttonId = 0;
m_previous_x = -1;
m_previous_y = -1;
m_previousTime = 0;
m_previousDouble = false;
}
}
}
}
}
}
@ -210,7 +299,7 @@ extern "C"
if (sDemoStopped) {
curTime = sTimeStopped + sTimeOffset;
} else {
curTime = _getTime() + sTimeOffset;
curTime =times(NULL) + sTimeOffset;
if (sTimeOffsetInit == 0) {
sTimeOffsetInit = 1;
sTimeOffset = -curTime;

View File

@ -88,8 +88,6 @@ static int VisualData[] = {
};
#endif
#define NB_MAX_INPUT (20)
#define SEPARATED_CLICK_TIME (30)
namespace guiAbstraction {
extern "C" {
@ -553,7 +551,7 @@ namespace guiAbstraction {
&& abs(m_previousDown_y - event.xbutton.y) < 5 )
{
// might generate an sigle event :
//EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonClockedSingle\" (" << (etkFloat_t)event.xbutton.x << "," << (etkFloat_t)event.xbutton.y << ")");
//EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonClickedSingle\" (" << (etkFloat_t)event.xbutton.x << "," << (etkFloat_t)event.xbutton.y << ")");
m_uniqueWindows->GenEventInput(btId, ewol::EVENT_INPUT_TYPE_SINGLE, (etkFloat_t)event.xbutton.x, (etkFloat_t)event.xbutton.y);
m_previous_x = m_previousDown_x;
m_previous_y = m_previousDown_y;
@ -575,12 +573,12 @@ namespace guiAbstraction {
{
// might generate an sigle event :
if (false == m_previousDouble) {
//EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonClockedDouble\" (" << (etkFloat_t)event.xbutton.x << "," << (etkFloat_t)event.xbutton.y << ")");
//EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonClickedDouble\" (" << (etkFloat_t)event.xbutton.x << "," << (etkFloat_t)event.xbutton.y << ")");
m_uniqueWindows->GenEventInput(btId, ewol::EVENT_INPUT_TYPE_DOUBLE, (etkFloat_t)event.xbutton.x, (etkFloat_t)event.xbutton.y);
m_previousTime = currentTime;
m_previousDouble = true;
} else {
//EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonClockedTriple\" (" << (etkFloat_t)event.xbutton.x << "," << (etkFloat_t)event.xbutton.y << ")");
//EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonClickedTriple\" (" << (etkFloat_t)event.xbutton.x << "," << (etkFloat_t)event.xbutton.y << ")");
m_uniqueWindows->GenEventInput(btId, ewol::EVENT_INPUT_TYPE_TRIPLE, (etkFloat_t)event.xbutton.x, (etkFloat_t)event.xbutton.y);
// reset values ...
m_previousDown_x = -1;

View File

@ -20,10 +20,9 @@ import android.content.Context;
*/
class EwolGLSurfaceView extends GLSurfaceView {
private static native void nativeApplicationInit();
private static native void nativePause();
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);
private static native void nativeEventInputState(int pointerID, boolean isDown, float x, float y);
private static native void nativeEventUnknow(int eventID);
private static native void nativeParamSetArchiveDir(int mode, String myString);
@ -41,16 +40,12 @@ class EwolGLSurfaceView extends GLSurfaceView {
setRenderer(mRenderer);
nativeApplicationInit();
}
private boolean InputDown1 = false;
private boolean InputDown2 = false;
private boolean InputDown3 = false;
public boolean onTouchEvent(final MotionEvent event) {
// TODO : unneed code :
if (event.getAction() == MotionEvent.ACTION_DOWN) {
nativePause();
}
// Wrapper on input events :
int tmpActionType = event.getAction();
@ -61,35 +56,32 @@ class EwolGLSurfaceView extends GLSurfaceView {
}
} else if( tmpActionType == MotionEvent.ACTION_POINTER_1_DOWN
|| tmpActionType == MotionEvent.ACTION_DOWN) {
nativeEventInputState(0, true);
nativeEventInputState(0, true, (float)event.getX(0), (float)event.getY(0));
InputDown1 = true;
nativeEventInputMotion(event.getPointerId(0), event.getX(0), event.getY(0));
} else if(tmpActionType == MotionEvent.ACTION_POINTER_1_UP) {
nativeEventInputState(0, false);
nativeEventInputState(0, false, (float)event.getX(0), (float)event.getY(0));
InputDown1 = false;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_2_DOWN) {
nativeEventInputState(1, true);
nativeEventInputState(1, true, (float)event.getX(1), (float)event.getY(1));
InputDown2 = true;
nativeEventInputMotion(event.getPointerId(1), event.getX(1), event.getY(1));
} else if (tmpActionType == MotionEvent.ACTION_POINTER_2_UP) {
nativeEventInputState(1, false);
nativeEventInputState(1, false, (float)event.getX(1), (float)event.getY(1));
InputDown2 = false;
} else if (tmpActionType == MotionEvent.ACTION_POINTER_3_DOWN) {
nativeEventInputState(2, true);
nativeEventInputState(2, true, (float)event.getX(2), (float)event.getY(2));
InputDown3 = true;
nativeEventInputMotion(event.getPointerId(2), event.getX(2), event.getY(2));
} else if (tmpActionType == MotionEvent.ACTION_POINTER_3_UP) {
nativeEventInputState(2, false);
nativeEventInputState(2, false, (float)event.getX(2), (float)event.getY(2));
InputDown3 = false;
} else if(tmpActionType == MotionEvent.ACTION_UP){
if (InputDown1) {
nativeEventInputState(0, false);
nativeEventInputState(0, false, (float)event.getX(0), (float)event.getY(0));
InputDown1 = false;
} else if (InputDown2) {
nativeEventInputState(1, false);
nativeEventInputState(1, false, (float)event.getX(1), (float)event.getY(1));
InputDown2 = false;
} else {
nativeEventInputState(2, false);
nativeEventInputState(2, false, (float)event.getX(2), (float)event.getY(2));
InputDown3 = false;
}
} else {