Android port: simplify sending touch events from Java->C
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27833 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
934a5a5808
commit
5068891477
2 changed files with 16 additions and 24 deletions
|
@ -80,20 +80,22 @@ public class RockboxFramebuffer extends View
|
||||||
|
|
||||||
public boolean onTouchEvent(MotionEvent me)
|
public boolean onTouchEvent(MotionEvent me)
|
||||||
{
|
{
|
||||||
|
int x = (int) me.getX();
|
||||||
|
int y = (int) me.getY();
|
||||||
|
|
||||||
switch (me.getAction())
|
switch (me.getAction())
|
||||||
{
|
{
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
touchHandler(0);
|
touchHandler(false, x, y);
|
||||||
break;
|
return true;
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
touchHandler(1);
|
touchHandler(true, x, y);
|
||||||
break;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
pixelHandler((int)me.getX(), (int)me.getY());
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
|
@ -118,7 +120,6 @@ public class RockboxFramebuffer extends View
|
||||||
}
|
}
|
||||||
|
|
||||||
public native void set_lcd_active(int active);
|
public native void set_lcd_active(int active);
|
||||||
public native void pixelHandler(int x, int y);
|
public native void touchHandler(boolean down, int x, int y);
|
||||||
public native void touchHandler(int down);
|
|
||||||
public native boolean buttonHandler(int keycode, boolean state);
|
public native boolean buttonHandler(int keycode, boolean state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,32 +38,23 @@ static enum {
|
||||||
STATE_DOWN,
|
STATE_DOWN,
|
||||||
} last_state = STATE_UNKNOWN;
|
} last_state = STATE_UNKNOWN;
|
||||||
|
|
||||||
/*
|
|
||||||
* this writes in an interrupt-like fashion the last pixel coordinates
|
|
||||||
* that the user pressed on the screen */
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_org_rockbox_RockboxFramebuffer_pixelHandler(JNIEnv*env, jobject this,
|
|
||||||
int x, int y)
|
|
||||||
{
|
|
||||||
(void)env;
|
|
||||||
(void)this;
|
|
||||||
last_x = x;
|
|
||||||
last_y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* this notifies us in an interrupt-like fashion whether the user just
|
* this notifies us in an interrupt-like fashion whether the user just
|
||||||
* began or stopped the touch action */
|
* began or stopped the touch action + where (pixel coordinates) */
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this,
|
Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this,
|
||||||
int down)
|
bool down, int x, int y)
|
||||||
{
|
{
|
||||||
(void)env;
|
(void)env;
|
||||||
(void)this;
|
(void)this;
|
||||||
|
|
||||||
if (down)
|
if (down)
|
||||||
last_state = STATE_DOWN;
|
last_state = STATE_DOWN;
|
||||||
else
|
else
|
||||||
last_state = STATE_UP;
|
last_state = STATE_UP;
|
||||||
|
|
||||||
|
last_x = x;
|
||||||
|
last_y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue