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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user