From b4e016ca210331a273a7ae1b00864d02bee689e8 Mon Sep 17 00:00:00 2001 From: danthemellowman Date: Thu, 21 Aug 2014 11:53:29 -0400 Subject: [PATCH 1/6] adding java calls for onScroll listener --- .../src/cc/openframeworks/OFAndroid.java | 5 +- .../cc/openframeworks/OFGestureListener.java | 58 ++++++++++++++++--- 2 files changed, 53 insertions(+), 10 deletions(-) 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..a218755ee61 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 = true; + + 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; } From 9637ffe26f5d94f8892b9107cfbb7822cbd73628 Mon Sep 17 00:00:00 2001 From: danthemellowman Date: Thu, 21 Aug 2014 11:53:46 -0400 Subject: [PATCH 2/6] adding cpp calls for onScroll listener --- addons/ofxAndroid/src/ofAppAndroidWindow.cpp | 9 +++++++++ addons/ofxAndroid/src/ofxAndroidApp.h | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index 9913f4a70b8..b35ce7177b9 100644 --- a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp +++ b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp @@ -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..641a8350dd6 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(){}; @@ -47,6 +55,10 @@ class ofxAndroidApp: public ofBaseApp{ }; virtual void touchCancelled(ofTouchEventArgs & touch){ touchCancelled(touch.x, touch.y, touch.id); + }; + + virtual void touchDragged(ofxAndroidDragDir swipeDir, int id, float dx, float dy) { + } virtual void swipe(ofxAndroidSwipeDir swipeDir, int id){ From acafba83f8338e365ac006eb86cf04b2703efc9b Mon Sep 17 00:00:00 2001 From: danthemellowman Date: Thu, 21 Aug 2014 11:57:49 -0400 Subject: [PATCH 3/6] adding velocity to Swipe CPP calls --- addons/ofxAndroid/src/ofAppAndroidWindow.cpp | 4 ++-- addons/ofxAndroid/src/ofxAndroidApp.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index b35ce7177b9..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); } } diff --git a/addons/ofxAndroid/src/ofxAndroidApp.h b/addons/ofxAndroid/src/ofxAndroidApp.h index 641a8350dd6..43da23a3325 100644 --- a/addons/ofxAndroid/src/ofxAndroidApp.h +++ b/addons/ofxAndroid/src/ofxAndroidApp.h @@ -60,7 +60,7 @@ class ofxAndroidApp: public ofBaseApp{ virtual void touchDragged(ofxAndroidDragDir swipeDir, int id, float dx, float dy) { } - virtual void swipe(ofxAndroidSwipeDir swipeDir, int id){ + virtual void swipe(ofxAndroidSwipeDir swipeDir, int id, float velocityX, float velocityY){ } From ddfb6b736e12521d5ed01d3d00fff5a55faba089 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Thu, 21 Aug 2014 12:00:18 -0400 Subject: [PATCH 4/6] Update OFGestureListener.java fixing result bool in onScroll --- .../ofAndroidLib/src/cc/openframeworks/OFGestureListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java index a218755ee61..d6ead66040a 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFGestureListener.java @@ -129,7 +129,7 @@ public boolean onScroll(MotionEvent eventStart, MotionEvent event, 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 = true; + boolean result = false; float absDX = Math.abs(distanceX); float absDY = Math.abs(distanceY); From 2f7df09defe3562794608241412a34d7d3523992 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Fri, 22 Aug 2014 11:37:14 -0400 Subject: [PATCH 5/6] Update ofxAndroidApp.h --- addons/ofxAndroid/src/ofxAndroidApp.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/ofxAndroid/src/ofxAndroidApp.h b/addons/ofxAndroid/src/ofxAndroidApp.h index 43da23a3325..7632bdb76d7 100644 --- a/addons/ofxAndroid/src/ofxAndroidApp.h +++ b/addons/ofxAndroid/src/ofxAndroidApp.h @@ -40,30 +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) {}; + 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 touchDragged(ofxAndroidDragDir swipeDir, int id, float dx, float dy) { - - } + 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; } From c1945f1cf8c4c88081c752d0c1825a41d367dea8 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Tue, 26 Aug 2014 08:00:14 -0400 Subject: [PATCH 6/6] Update ofxAndroidApp.h --- addons/ofxAndroid/src/ofxAndroidApp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/ofxAndroid/src/ofxAndroidApp.h b/addons/ofxAndroid/src/ofxAndroidApp.h index 7632bdb76d7..a1c7e3950cb 100644 --- a/addons/ofxAndroid/src/ofxAndroidApp.h +++ b/addons/ofxAndroid/src/ofxAndroidApp.h @@ -40,7 +40,7 @@ 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) {}; - virtual void swipe(ofxAndroidSwipeDir swipeDir, 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);