Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector

Overview

Android Gesture Detectors Framework

Introduction

Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as a RotateGestureDetector I decided to create this class myself. In the process I decided to create a small extendable framework for GestureDetectors in general.

Tutorials

Blog on using gesture detectors

If you want to use the ScaleGestureDetector and/or the gesture detectors from this project, please read my tutorial: code.almeros.com/android-multitouch-gesture-detectors

Example application

If you like to just dive into a working example, please check out the example app (GitHub).

Dependencies / Downloads

You can always just download a zip from GitHub and add its contents to your project. But dependency
management might be easier for you using Gradle and jitpack.io. Include the following in your project:

build.gradle root

buildscript {       
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
    ...
}

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

build.gradle app

dependencies {
    // Note: Change 'v1.0' to whatever release you need or 'master-SNAPSHOT' for a snapshot of 
    // the latest version on the master-branch.
    compile 'com.github.Almeros:android-gesture-detectors:v1.0'
}

Extending / Contributing

If you want to extend this framework with new gesture detectors please check out the existing classes and read the comments/javadocs.

I hope you'll send a pull request with your FingerTwistGestureDetector or something ;)

If you help maintaining this framework, first of all thank you, and second, please consider also updating the example app (GitHub) to make use of your awesome new functionality/bugfixes!

Containments

RotateGestureDetector

Helps finding out the rotation angle between the line of two fingers (with the normal or previous finger positions)

MoveGestureDetector

Convenience gesture detector to keep it easy moving an object around with one ore more fingers without losing the clean usage of the gesture detector pattern.

ShoveGestureDetector

Detects a vertical two-finger shove. (If you place two fingers on screen with less than a 20 degree angle between them, this will detact movement on the Y-axis.)

ScaleGestureDetector (default Android)

This one is NOT in this framework, but is gesture detector that resides in the Android API since API level 8 (2.2).

BaseGestureDetector (abstract)

Abstract class that every new gesture detector class should extend.

TwoFingerGestureDetector (abstract)

Abstract class that extends the BaseGestureDetector and that every new gesture detector class for two finger operations should extend.

License

This project is licensed with the 2-clause BSD license.

Comments
  • BSD 2-clause license?

    BSD 2-clause license?

    I'm not sure what it means. Can anyone please help with this? I've found this one: https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)

    As English isn't my main language, I couldn't understand its meaning, even though I've read in multiple websites (including Wikipedia).

    1. What does "Hold Liable" mean? that the original creator of the library won't be charged for damages?
    2. What does " Include Copyright" mean? that the app must show the description of the license somewhere within (like the "about" screen or something) ? or just the code should have it ? If just the code, what's the difference between it and Apache2 license ?

    3.What about derivatives? What if I wish to fork the library? should it also be BSD 2-clause licensed ?

    What should and what shouldn't I do?

    opened by AndroidDeveloperLB 10
  • Bug: very rare crash

    Bug: very rare crash

    Not sure what I've done to do it, other than playing with it.

    This is what I got in the logs:

    java.lang.IllegalArgumentException: pointerIndex out of range at android.view.MotionEvent.nativeGetAxisValue(Native Method) at android.view.MotionEvent.getX(MotionEvent.java:1983) at com.almeros.android.multitouch.TwoFingerGestureDetector.updateStateByEvent(TwoFingerGestureDetector.java:77) at com.almeros.android.multitouch.RotateGestureDetector.handleInProgressEvent(RotateGestureDetector.java:136) at com.almeros.android.multitouch.BaseGestureDetector.onTouchEvent(BaseGestureDetector.java:66)

    opened by AndroidDeveloperLB 8
  • cant compile with gradle

    cant compile with gradle

    Hello,

    I use: compile 'com.almeros.android-gesture-detectors:library:1.0' in gradle and get "failed to resolve"

    can you please help me fix that?

    Thank you

    opened by Watsonibm 5
  • Mistake in detecting sloppy gestures

    Mistake in detecting sloppy gestures

    It seems there is a mistake in calculating raw coordinates of motion events, please see TwoFingerGestureDetector.getRawX(MotionEvent, int) (line 122) and TwoFingerGestureDetector.getRawY(MotionEvent, int) (line 136).

    You should actually calculate offset like float offset = event.getRawX() - event.getX(); and float offset = event.getRawY() - event.getY();

    opened by es-andreev 3
  • Gradlified the build and prepared it for Maven Central deployment.

    Gradlified the build and prepared it for Maven Central deployment.

    I've updated this project to support Gradle based builds and set it up for Maven Central deployment. I needed it for a project so set it up to deploy with my group id, so that I could get it deployed immediately for use, but I'd like to be a good citizen and send these changes back.

    Please feel free to update the deployment information with your own group id, if you'd like, so there is a single point of contact for this. I'm also happy to keep it in mine since the Sonatype setup is a pain, but since you wrote this I'd like you to be able to get credit for it.

    opened by rharter 2
  • Still : Pointer Index out of range

    Still : Pointer Index out of range

    Rare but often bug which is crash app

    Fatal Exception: java.lang.IllegalArgumentException: pointerIndex out of range at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java) at android.view.MotionEvent.getX(MotionEvent.java:2136) at com.rahul.mystickers.multitouch.TwoFingerGestureDetector.updateStateByEvent(TwoFingerGestureDetector.java:76) at com.rahul.mystickers.multitouch.RotateGestureDetector.handleInProgressEvent(RotateGestureDetector.java:138) at com.rahul.mystickers.multitouch.BaseGestureDetector.handleInProgressEvent(BaseGestureDetector.java:4) at com.rahul.mystickers.multitouch.BaseGestureDetector.onTouchEvent(BaseGestureDetector.java:66)

    opened by imandaliya 1
  • inability to delete entity

    inability to delete entity

    deletedSelectedEntity() removes the entity from the List entities and even recycles the bitmap but the layer of the entity (to be deleted) still retains on the MotionView and we keep on getting a warning Called getWidth() on a recycle()'d bitmap! This is undefined behaviour! 2019-03-07 02-21-36

    opened by aQwus 1
  • Prevent crash when mPrevEvent is null

    Prevent crash when mPrevEvent is null

    I came across the same issue as mentioned here during the development of one of my apps : https://github.com/mapbox/mapbox-gl-native/issues/5047

    After investigation, it appears that the GestureDetector didn't receive ACTION_DOWN (user has finger down before the view is fully loaded and listeners attached), and starts directly processing ACTION_MOVE.

    In that instance, mPrevEvent is null.

    My solution will simply ignore any processing that can happen during the ACTION_MOVE. The rest of the logic stays in place (especially ACTION_UP and ACTION_CANCEL), so that the state is clean when a new gesture happens.

    opened by NicolasSimon 1
  • Getting in touch

    Getting in touch

    Hey @Almeros, thanks for your work here, we're big fans of this library and we use it extensively as part of our SDK https://github.com/mapbox/mapbox-gl-native. I'd love to chat with you about a few ideas we have for the project. Any chance, you can drop me a line to [email protected]?

    Thanks and cc'ing @rharter whom I've also been in touch with.

    (Feel free to close this ticket, I just didn't know the best way to reach out.)

    opened by zugaldia 1
  • Handle imageView without matrix technic

    Handle imageView without matrix technic

    Hello,

    I would like to use this library and handle and resize, rotate, and scale multiple imageviews but without matrix technic. Instead, I would like to user setX, setY, setRotation for example. Problem is that I'm unable to combine the gestures together. Do you have an example for this case ? Thanks

    David

    opened by dupuisdavid 1
  • Two-finger pinch-zoom about the center of the two pointers

    Two-finger pinch-zoom about the center of the two pointers

    This gesture detector example is very helpful, but it appears to always zoom relative to the center of the image, which may be well outside the currently displayed area. Would it be possible to zoom about the center of the two touch positions instead? If so, how? Thanks.

    opened by TedJackson 1
  • TwoFingerGestureDetector : IllegalArgumentException: pointerIndex out of range

    TwoFingerGestureDetector : IllegalArgumentException: pointerIndex out of range

    We are getting this crash in the TwoFingerGestureDetector.

    Fatal Exception: java.lang.IllegalArgumentException: pointerIndex out of range
           at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java)
           at android.view.MotionEvent.getX(MotionEvent.java:2379)
           at com.almeros.android.multitouch.TwoFingerGestureDetector.updateStateByEvent(TwoFingerGestureDetector.java:77)
           at com.almeros.android.multitouch.RotateGestureDetector.handleInProgressEvent(RotateGestureDetector.java:136)
           at com.almeros.android.multitouch.BaseGestureDetector.onTouchEvent(BaseGestureDetector.java:66)
    
    opened by riggaroo 1
  • Added Code

    Added Code

    hi Almeros, I wondered if i could contact you about working on a project related to your code here, is that possible, i dont see any contact info for you on github. Regards David

    opened by thomad99 0
  • RotateGestureDetector getRotationDegreesDelta returns values close to 360 on small angle change

    RotateGestureDetector getRotationDegreesDelta returns values close to 360 on small angle change

    Performing minuscule rotations while having rotation line between fingers horizontal causes to getRotationDegreesDelta to output values close to 360, e.g. -359.4 or 359.2.

    This is caused by Math.atan2 used to calculate diff angle having ambiguity around +-180*. All is fine and well when performed rotation is shown 1:1 on screen, but I'm scaling it to get more precise moment with small values, so when the received values are 0.015, 0.020, 0.017, -359.4, 0.021... it causes a sudden jerk.

    IMO it's a bug because nobody expects sudden 360 for minuscule finger motion when calling getRotationDegreesDelta. The real change of angle is certainly NOT a 360 degree.

    My workaround was:

    val raw = detector.rotationDegreesDelta
    val diffRotation = if (abs(raw) > 300) {   // or some other arbitrary value above 180*
        if (raw < 0) {
            360 + raw
        } else {
            raw - 360
        }
    } else raw
    

    I think better fix (without arbitrary 300* value) can be done on library side by checking if one angle falls close to 180* and other close to -180*, so it's passing through discontinous part of Math.atan2 and can be accounted for.

    opened by stanleyguevara 0
  • FloatMath.sqrt has been removed from Android SDK 23

    FloatMath.sqrt has been removed from Android SDK 23

    The deprecated class has been removed.

    "Historically these methods were faster than the equivalent double-based Math methods. On versions of Android with a JIT they became slower and have since been re-implemented to wrap calls to Math. Math should be used in preference. All methods were removed from the public API in version 23."

    http://developer.android.com/reference/android/util/FloatMath.html

    The library now needs to use eg. (float) Math.sqrt(pvx_pvx + pvy_pvy);

    opened by dominicthomas 2
Releases(v1.0.1)
  • v1.0.1(Dec 12, 2017)

    • The sample app is removed. Please see https://github.com/Almeros/android-gesture-detectors-example for the example app
    • Updated README.md for use of Jitpack.io for Gradle dependency management and some small other changes
    Source code(tar.gz)
    Source code(zip)
  • v1.0(Dec 11, 2017)

Error handling library for Android and Java

ErrorHandler Error handling library for Android and Java Encapsulate error handling logic into objects that adhere to configurable defaults. Then pass

null 237 Dec 29, 2022
Native Kotlin library for time-based TOTP and HMAC-based HOTP one-time passwords

A kotlin implementation of HOTP (RFC-4226) and TOTP (RFC-6238). Supports validation and generation of 2-factor authentication codes, recovery codes and randomly secure secrets.

Robin Ohs 6 Dec 19, 2022
Consumer android from nutrition-framework API

About This Project (work-in-progress ?? ??️ ??‍♀️ ⛏ ) Consumer Dari Nutrition Framework General Framework for Application Development Around Nutrition

Faisal Amir 0 Feb 24, 2022
A tiny framework to execute shell scripts on Android

Skippy A tiny framework to execute shell scripts on Android Why I first sought out to create a basic script manager for Android.

Tyler 4 Jul 31, 2022
Command framework built around Kord, built to be robust and scalable, following Kord's convention and design patterns.

Command framework built around Kord, built to be robust and scalable, following Kord's convention and design patterns.

ZeroTwo Bot 4 Jun 15, 2022
Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

Disk LRU Cache A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key m

Jake Wharton 5.7k Dec 31, 2022
A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Square 2.4k Dec 30, 2022
Multiplaform kotlin library for calculating text differences. Based on java-diff-utils, supports JVM, JS and native targets.

kotlin-multiplatform-diff This is a port of java-diff-utils to kotlin with multiplatform support. All credit for the implementation goes to original a

Peter Trifanov 51 Jan 3, 2023
Perfect replacement for startActivityForResult(), based on the Activity Result API.

ActivityResultLauncher English | 中文 Activity Result API is an official tool used to replace the method of startActivityForResult() and onActivityResul

DylanCai 167 Nov 30, 2022
A Kotlin-based testing/scraping/parsing library providing the ability to analyze and extract data from HTML

A Kotlin-based testing/scraping/parsing library providing the ability to analyze and extract data from HTML (server & client-side rendered). It places particular emphasis on ease of use and a high level of readability by providing an intuitive DSL. It aims to be a testing lib, but can also be used to scrape websites in a convenient fashion.

null 603 Jan 1, 2023
Gitversion - A native console application to calculate a version based on git commits and tags

GitCommit A native console application to calculate a version based on git commi

Solugo 5 Sep 13, 2022
Flow-based programming "language"

________ / ____/ /___ _ __ / /_ / / __ \ | /| / / / __/ / / /_/ / |/ |/ / /_/ /_/\____/|__/|__/ Flow-based programming "language" This

Kevin Ludwig 2 Dec 17, 2022
Flow-based programming "language"

Cran Flow-based programming "language", the aim of this project is not to create an entry-friendly programming language, and more over to create a cap

Kevin Ludwig 3 May 30, 2022
Validator - Notify type based validation for input fields.

Validator - Notify type based validation for input fields.

Mustafa Yiğit 57 Dec 8, 2022
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.

Secure-preferences - Deprecated Please use EncryptedSharedPreferences from androidx.security in preferenced to secure-preference. (There are no active

Scott Alexander-Bown 1.5k Dec 24, 2022
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Rohit Surwase 19 Nov 9, 2021
Use Android as Rubber Ducky against another Android device

Use Android as Rubber Ducky against another Android device

null 1.4k Jan 9, 2023
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Shahid Iqbal 4 Nov 29, 2022
A util for setting status bar style on Android App.

StatusBarUtil A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4). 中文版点我 Sample Download StatusBarUtil-Demo Chang

Jaeger 8.8k Jan 6, 2023