Added the concept of a 'flick' gesture. This uses the VelocityTracker object in Android and passes the velocity info down as an SDL joystick trackball event. We can then reinterpret this event in whatever way we like, such as up/down swipes in the deck editor (that was my initial thought, at any rate).

TBD:  right now every up finger generates this event.  We probably want to throttle it to only be an event if the velocity exceeds some arbitrary threshold;  similarly, if we generate a flick event, we probably don't want to simultaneously generate a finger up action (ie JGE_BTN_OK).
This commit is contained in:
wrenczes@gmail.com
2011-06-11 10:30:38 +00:00
parent b2eaa3cb8d
commit 9e6154076b
5 changed files with 57 additions and 1 deletions

View File

@@ -128,6 +128,13 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
Android_OnTouch(index, action, x, y, p);
}
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeFlickGesture(
JNIEnv* env, jclass jcls,
jfloat xVelocity, jfloat yVelocity)
{
Android_OnFlickGesture(xVelocity, yVelocity);
}
// Accelerometer
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
JNIEnv* env, jclass jcls,

View File

@@ -119,4 +119,18 @@ void Android_OnTouch(int index, int action, float x, float y, float p)
}
}
void Android_OnFlickGesture(float xVelocity, float yVelocity)
{
// cheap hack, translate this to a joystick ball event instead of its own proper event
SDL_Event event;
event.jball.type = SDL_JOYBALLMOTION;
event.jball.which = 0;
event.jball.ball = 0;
event.jball.xrel = (int) xVelocity;;
event.jball.yrel = (int) yVelocity;
SDL_PushEvent(&event);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -24,4 +24,6 @@
extern void Android_OnTouch(int index, int action, float x, float y, float p);
extern void Android_OnFlickGesture(float xVelocity, float yVelocity);
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -208,7 +208,11 @@ public:
<< ", dDist " << Event->mgesture.dDist
<< ", numFingers " << Event->mgesture.numFingers);
break;
}
case SDL_JOYBALLMOTION:
DebugTrace("Flick gesture detected");
break;
}
}
void OnUpdate();

View File

@@ -95,6 +95,7 @@ public class SDLActivity extends Activity {
public static native void onNativeKeyUp(int keycode);
public static native void onNativeTouch(int index, int action, float x,
float y, float p);
public static native void onNativeFlickGesture(float xVelocity, float yVelocity);
public static native void onNativeAccel(float x, float y, float z);
public static native void nativeRunAudioThread();
@@ -245,6 +246,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Sensors
private static SensorManager mSensorManager;
private static VelocityTracker mVelocityTracker;
// Startup
public SDLSurface(Context context) {
super(context);
@@ -467,6 +470,32 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
SDLActivity.onNativeTouch(index, action, x, y, p);
}
// account for 'flick' type gestures by monitoring velocity
if (event.getActionIndex() == 0)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.clear();
mVelocityTracker.addMovement(event);
}
else if (event.getAction() == MotionEvent.ACTION_MOVE)
{
mVelocityTracker.addMovement(event);
}
else if (event.getAction() == MotionEvent.ACTION_UP)
{
mVelocityTracker.addMovement(event);
// calc velocity
mVelocityTracker.computeCurrentVelocity(1000);
SDLActivity.onNativeFlickGesture(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
mVelocityTracker.recycle();
}
}
return true;
}