From 2f97d8cc845de269c596aa91e9f2632d01ace515 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Tue, 15 Jan 2019 10:59:39 +0100 Subject: [PATCH 01/10] add get focusx and focusy --- library/src/main/AndroidManifest.xml | 10 ---------- .../multitouch/RotateGestureDetector.java | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 8bef032..1ddd256 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -2,16 +2,6 @@ - - - - - - diff --git a/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java index ba27af1..1dd3ff4 100644 --- a/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java @@ -139,6 +139,7 @@ protected void handleInProgressEvent(int actionCode, MotionEvent event){ // a certain limit. This can help filter shaky data as a // finger is lifted. if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) { + determineFocusPoint(event); final boolean updatePrevious = mListener.onRotate(this); if (updatePrevious) { mPrevEvent.recycle(); @@ -155,6 +156,25 @@ protected void resetState() { mSloppyGesture = false; } + private float mFocusX; + private float mFocusY; + /** + */ + public float getFocusX() { + return mFocusX; + } + + + /** + */ + public float getFocusY() { + return mFocusY; + } + + private void determineFocusPoint(MotionEvent curr) { + mFocusX = (curr.getX(0) + curr.getX(1)) * 0.5f; + mFocusY = (curr.getY(0) + curr.getY(1)) * 0.5f; + } /** * Return the rotation difference from the previous rotate event to the current From 9500bf6e687cecdda6356c2df03ca550c9f8b764 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Tue, 15 Jan 2019 18:07:25 +0100 Subject: [PATCH 02/10] Work after review --- .../almeros/android/multitouch/RotateGestureDetector.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java index 1dd3ff4..46624eb 100644 --- a/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java @@ -60,6 +60,8 @@ public void onRotateEnd(RotateGestureDetector detector) { private final OnRotateGestureListener mListener; private boolean mSloppyGesture; + private float mFocusX; + private float mFocusY; public RotateGestureDetector(Context context, OnRotateGestureListener listener) { super(context); @@ -156,9 +158,8 @@ protected void resetState() { mSloppyGesture = false; } - private float mFocusX; - private float mFocusY; /** + * Get gesture focus X point. */ public float getFocusX() { return mFocusX; @@ -166,6 +167,7 @@ public float getFocusX() { /** + * Get gesture focus Y point. */ public float getFocusY() { return mFocusY; From ccbde7c99b4a0f7e26836024a9613de8ab4dd185 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Tue, 15 Jan 2019 18:09:02 +0100 Subject: [PATCH 03/10] Upgrade gradle, build tool, compilation sdk --- build.gradle | 8 ++++---- gradle.properties | 6 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../android/multitouch/TwoFingerGestureDetector.java | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index b01c392..4505dd2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:3.3.0' } } allprojects { repositories { + google() + jcenter() mavenCentral() } } diff --git a/gradle.properties b/gradle.properties index fb959d0..f7344a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ VERSION_NAME=1.0 -VERSION_CODE=2 +VERSION_CODE=3 GROUP=com.almeros.android-gesture-detectors POM_DESCRIPTION=Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector @@ -15,7 +15,7 @@ POM_DEVELOPER_NAME=Almeros Thies ANDROID_MIN_SDK=8 ANDROID_TARGET_SDK=21 -ANDROID_COMPILE_SDK=21 -ANDROID_BUILD_TOOLS_VERSION=25.0.0 +ANDROID_COMPILE_SDK=28 +ANDROID_BUILD_TOOLS_VERSION=28.0.3 org.gradle.jvmargs=-Xmx1536M diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 123157e..9dc40d5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip diff --git a/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java index 4b031c7..54e4c68 100644 --- a/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java @@ -92,7 +92,7 @@ public float getCurrentSpan() { if (mCurrLen == -1) { final float cvx = mCurrFingerDiffX; final float cvy = mCurrFingerDiffY; - mCurrLen = FloatMath.sqrt(cvx*cvx + cvy*cvy); + mCurrLen = (float) Math.sqrt(cvx*cvx + cvy*cvy); } return mCurrLen; } @@ -107,7 +107,7 @@ public float getPreviousSpan() { if (mPrevLen == -1) { final float pvx = mPrevFingerDiffX; final float pvy = mPrevFingerDiffY; - mPrevLen = FloatMath.sqrt(pvx*pvx + pvy*pvy); + mPrevLen = (float) Math.sqrt(pvx*pvx + pvy*pvy); } return mPrevLen; } From 2be6ce5a6b2f1f6a3779879e575d6de1ffc46b72 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Wed, 16 Jan 2019 11:43:03 +0100 Subject: [PATCH 04/10] Move focus point to TwoFinger Gesture detector --- .../multitouch/RotateGestureDetector.java | 22 ------------ .../multitouch/ShoveGestureDetector.java | 1 + .../multitouch/TwoFingerGestureDetector.java | 35 ++++++++++++++++--- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java index 46624eb..fd98561 100644 --- a/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/RotateGestureDetector.java @@ -60,8 +60,6 @@ public void onRotateEnd(RotateGestureDetector detector) { private final OnRotateGestureListener mListener; private boolean mSloppyGesture; - private float mFocusX; - private float mFocusY; public RotateGestureDetector(Context context, OnRotateGestureListener listener) { super(context); @@ -158,26 +156,6 @@ protected void resetState() { mSloppyGesture = false; } - /** - * Get gesture focus X point. - */ - public float getFocusX() { - return mFocusX; - } - - - /** - * Get gesture focus Y point. - */ - public float getFocusY() { - return mFocusY; - } - - private void determineFocusPoint(MotionEvent curr) { - mFocusX = (curr.getX(0) + curr.getX(1)) * 0.5f; - mFocusY = (curr.getY(0) + curr.getY(1)) * 0.5f; - } - /** * Return the rotation difference from the previous rotate event to the current * event. diff --git a/library/src/main/java/com/almeros/android/multitouch/ShoveGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/ShoveGestureDetector.java index cb8f818..515b7d7 100644 --- a/library/src/main/java/com/almeros/android/multitouch/ShoveGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/ShoveGestureDetector.java @@ -143,6 +143,7 @@ protected void handleInProgressEvent(int actionCode, MotionEvent event){ // finger is lifted. Also check that shove is meaningful. if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD && Math.abs(getShovePixelsDelta()) > 0.5f) { + determineFocusPoint(event); final boolean updatePrevious = mListener.onShove(this); if (updatePrevious) { mPrevEvent.recycle(); diff --git a/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java index 54e4c68..0abffbb 100644 --- a/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java @@ -2,7 +2,6 @@ import android.content.Context; import android.util.DisplayMetrics; -import android.util.FloatMath; import android.view.MotionEvent; import android.view.ViewConfiguration; @@ -36,10 +35,12 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { protected float mPrevFingerDiffY; protected float mCurrFingerDiffX; protected float mCurrFingerDiffY; - + protected float mFocusX; + protected float mFocusY; + private float mCurrLen; private float mPrevLen; - + public TwoFingerGestureDetector(Context context) { super(context); @@ -111,7 +112,33 @@ public float getPreviousSpan() { } return mPrevLen; } - + + /** + * Get gesture focus X point. + * @return focus X point of gesture. + */ + public float getFocusX() { + return mFocusX; + } + + + /** + * Get gesture focus Y point. + * @return focus Y point of gesture. + */ + public float getFocusY() { + return mFocusY; + } + + /** + * Calculate focus point for gesture. + * @param curr current motion event used to calculate focus point. + */ + protected void determineFocusPoint(MotionEvent curr) { + mFocusX = (curr.getX(0) + curr.getX(1)) * 0.5f; + mFocusY = (curr.getY(0) + curr.getY(1)) * 0.5f; + } + /** * MotionEvent has no getRawX(int) method; simulate it pending future API approval. * @param event From 34f686f01f4e8b1058f954f6b0ffef85888ae511 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Wed, 16 Jan 2019 13:54:54 +0100 Subject: [PATCH 05/10] Circle CI check --- .cirrus.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .cirrus.yml diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 0000000..3c503e8 --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,5 @@ +container: + image: cirrusci/android-sdk:28 + +check_android_task: + check_script: ./gradlew build From 69e789d3512341fc297b09ed6585bcc1e725f9f1 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Wed, 16 Jan 2019 14:02:42 +0100 Subject: [PATCH 06/10] conf for circleci --- .circleci/config.yml | 10 ++++++++++ .cirrus.yml | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 .cirrus.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..0270e47 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,10 @@ +version: 2 +jobs: + test: + docker: + - image: circleci/android:api-28-alpha # gcloud is baked into this image + steps: + - run: + name: Build debug APK and release APK + command: | + ./gradlew build diff --git a/.cirrus.yml b/.cirrus.yml deleted file mode 100644 index 3c503e8..0000000 --- a/.cirrus.yml +++ /dev/null @@ -1,5 +0,0 @@ -container: - image: cirrusci/android-sdk:28 - -check_android_task: - check_script: ./gradlew build From 9251077e1f72f683bed09d4108fe6d85d70e155b Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Wed, 16 Jan 2019 14:03:46 +0100 Subject: [PATCH 07/10] Change job name --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0270e47..144cbec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2 jobs: - test: + build: docker: - image: circleci/android:api-28-alpha # gcloud is baked into this image steps: From edb9d5fa87e3f737b6d41d237d3daba38f2c00eb Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Wed, 16 Jan 2019 14:07:51 +0100 Subject: [PATCH 08/10] checout code --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 144cbec..0650135 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,7 @@ jobs: docker: - image: circleci/android:api-28-alpha # gcloud is baked into this image steps: + - checkout - run: name: Build debug APK and release APK command: | From d58143890fd4a1514b5765464dd8a39b494f9d54 Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Wed, 16 Jan 2019 14:13:47 +0100 Subject: [PATCH 09/10] Add status of circle Ci build --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0ed40eb..cea639f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Android Gesture Detectors Framework =================================== +[![CircleCI](https://circleci.com/gh/mariopce/android-gesture-detectors/tree/master.svg?style=svg)](https://circleci.com/gh/mariopce/android-gesture-detectors/tree/master) + Introduction ------------ From 059e67b94b327d1dec5f90d3ce18aa62bee0696b Mon Sep 17 00:00:00 2001 From: Mariusz Saramak Date: Tue, 22 Jan 2019 09:59:22 +0100 Subject: [PATCH 10/10] Fix for double image rotation issue https://github.com/Almeros/android-gesture-detectors/issues/5 --- .../android/multitouch/TwoFingerGestureDetector.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java b/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java index 0abffbb..42c043f 100644 --- a/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java +++ b/library/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java @@ -146,11 +146,7 @@ protected void determineFocusPoint(MotionEvent curr) { * @return */ protected static float getRawX(MotionEvent event, int pointerIndex) { - float offset = event.getX() - event.getRawX(); - if(pointerIndex < event.getPointerCount()){ - return event.getX(pointerIndex) + offset; - } - return 0f; + return event.getRawX(); } /** @@ -160,11 +156,7 @@ protected static float getRawX(MotionEvent event, int pointerIndex) { * @return */ protected static float getRawY(MotionEvent event, int pointerIndex) { - float offset = event.getY() - event.getRawY(); - if(pointerIndex < event.getPointerCount()){ - return event.getY(pointerIndex) + offset; - } - return 0f; + return event.getRawY(); } /**