diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java index 6071edd3b3a..0049fe94475 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java @@ -649,8 +649,9 @@ public static void onActivityResult(int requestCode, int resultCode,Intent inten public static native void onTouchUp(int id,float x,float y,float pressure); public static native void onTouchMoved(int id,float x,float y,float pressure); public static native void onTouchCancelled(int id,float x,float y); - - public static native void onSwipe(int id, int swipeDir); + public static native void onTouchDragged(int id, int dragDir, float x,float y); + public static native void onSwipe(int id, int swipeDir, float velocityX, float velocityY); + public static native void onKeyDown(int keyCode); public static native void onKeyUp(int keyCode); diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java index 8a6dea53329..d6ead66040a 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java @@ -99,16 +99,16 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve if(velocityX > OFGestureListener.swipe_Min_Velocity && xDistance > OFGestureListener.swipe_Min_Distance){ if(e1.getX() > e2.getX()) // right to left - OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_LEFT); + OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_LEFT, velocityX, velocityY); else - OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_RIGHT); + OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_RIGHT, velocityX, velocityY); result = true; }else if(velocityY > OFGestureListener.swipe_Min_Velocity && yDistance > OFGestureListener.swipe_Min_Distance){ if(e1.getY() > e2.getY()) // bottom to up - OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_UP); + OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_UP, velocityX, velocityY); else - OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_DOWN); + OFAndroid.onSwipe(e1.getPointerId(0),SWIPE_DOWN, velocityX, velocityY); result = true; } @@ -116,15 +116,53 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve return result; } + + @Override public void onLongPress(MotionEvent arg0) { } @Override - public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) { - return super.onScroll(arg0, arg1, arg2, arg3); + public boolean onScroll(MotionEvent eventStart, MotionEvent event, + float distanceX, float distanceY) { + + final int action = event.getAction(); + final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; + final int pointerId = event.getPointerId(pointerIndex); + boolean result = false; + + float absDX = Math.abs(distanceX); + float absDY = Math.abs(distanceY); + switch ((action & MotionEvent.ACTION_MASK)) { + case MotionEvent.ACTION_MOVE: { + if (absDY > absDX) { + + if (distanceY > 0) // bottom to up + OFAndroid.onTouchDragged(pointerId, DRAG_UP, + distanceX, distanceY); + else + OFAndroid.onTouchDragged(pointerId, DRAG_DOWN, + distanceX, distanceY); + + result = true; + + } else { + if (distanceX > 0) // right to left + OFAndroid.onTouchDragged(pointerId, DRAG_LEFT, + distanceX, distanceY); + else + OFAndroid.onTouchDragged(pointerId, DRAG_RIGHT, + distanceX, distanceY); + + result = true; + } + break; + } + } + return result; } + @Override public void onShowPress(MotionEvent arg0) { } @@ -137,10 +175,14 @@ public boolean onSingleTapUp(MotionEvent event) { private GestureDetector gestureDetector; View.OnTouchListener touchListener; public static int swipe_Min_Distance = 100; - public static int swipe_Max_Distance = 350; - public static int swipe_Min_Velocity = 100; + public static int swipe_Max_Distance = 2560; + public static int swipe_Min_Velocity = 50; public final static int SWIPE_UP = 1; public final static int SWIPE_DOWN = 2; public final static int SWIPE_LEFT = 3; public final static int SWIPE_RIGHT = 4; + public final static int DRAG_UP = 5; + public final static int DRAG_DOWN = 6; + public final static int DRAG_LEFT = 7; + public final static int DRAG_RIGHT = 8; } diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index 9913f4a70b8..386dcec4ed7 100644 --- a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp +++ b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp @@ -514,9 +514,9 @@ Java_cc_openframeworks_OFAndroid_onTouchDoubleTap(JNIEnv* env, jclass thiz, ji } void -Java_cc_openframeworks_OFAndroid_onSwipe(JNIEnv* env, jclass thiz, jint id, jint swipeDir){ +Java_cc_openframeworks_OFAndroid_onSwipe(JNIEnv* env, jclass thiz, jint id, jint swipeDir, jfloat vX, jfloat vY){ if(androidApp){ - androidApp->swipe((ofxAndroidSwipeDir)swipeDir,id); + androidApp->swipe((ofxAndroidSwipeDir)swipeDir,id, vX, vY); } } @@ -530,6 +530,15 @@ Java_cc_openframeworks_OFAndroid_onKeyUp(JNIEnv* env, jobject thiz, jint keyC ofNotifyKeyReleased(keyCode); } +void +Java_cc_openframeworks_OFAndroid_onTouchDragged(JNIEnv* env, jclass thiz, + jint id, jint dragDir, jfloat x, jfloat y) { + if (androidApp) { + androidApp->touchDragged((ofxAndroidDragDir) dragDir, id, x, y); + } +} + + jboolean Java_cc_openframeworks_OFAndroid_onBackPressed(){ ofLogVerbose("ofAppAndroidWindow") << "back pressed"; diff --git a/addons/ofxAndroid/src/ofxAndroidApp.h b/addons/ofxAndroid/src/ofxAndroidApp.h index 88551f09e52..a1c7e3950cb 100644 --- a/addons/ofxAndroid/src/ofxAndroidApp.h +++ b/addons/ofxAndroid/src/ofxAndroidApp.h @@ -19,6 +19,14 @@ enum ofxAndroidSwipeDir{ OFX_ANDROID_SWIPE_RIGHT = 4 }; +enum ofxAndroidDragDir{ + OFX_ANDROID_DRAG_UP = 5, + OFX_ANDROID_DRAG_DOWN = 6, + OFX_ANDROID_DRAG_LEFT = 7, + OFX_ANDROID_DRAG_RIGHT = 8 +}; + + class ofxAndroidApp: public ofBaseApp{ public: virtual void pause(){}; @@ -32,26 +40,36 @@ class ofxAndroidApp: public ofBaseApp{ virtual void touchUp(int x, int y, int id) {}; virtual void touchDoubleTap(int x, int y, int id) {}; virtual void touchCancelled(int x, int y, int id) {}; + OF_DEPRECATED_MSG("swipe(ofxAndroidSwipeDir swipeDir, int id) is deprecated, please update to swipe(ofxAndroidSwipeDir swipeDir, int id, float velocityX, float velocityY)",virtual void swipe(ofxAndroidSwipeDir swipeDir, int id){};) virtual void touchDown(ofTouchEventArgs & touch) { touchDown(touch.x, touch.y, touch.id); }; + virtual void touchMoved(ofTouchEventArgs & touch) { touchMoved(touch.x, touch.y, touch.id); }; + virtual void touchUp(ofTouchEventArgs & touch) { touchUp(touch.x, touch.y, touch.id); }; + virtual void touchDoubleTap(ofTouchEventArgs & touch) { touchDoubleTap(touch.x, touch.y, touch.id); }; + virtual void touchCancelled(ofTouchEventArgs & touch){ touchCancelled(touch.x, touch.y, touch.id); - } - virtual void swipe(ofxAndroidSwipeDir swipeDir, int id){ - - } + }; + + virtual void swipe(ofxAndroidSwipeDir swipeDir, int id, float velocityX, float velocityY){ + swipe(swipeDir, id); + }; + + virtual void touchDragged(ofxAndroidDragDir swipeDir, int id, float dx, float dy) { + }; + virtual bool backPressed(){ return false; }