• Stars
    star
    134
  • Rank 262,016 (Top 6 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AndroidGestureRecognizer is an Android implementation of the Apple's UIGestureRecognizer framework

Android UIGestureRecognizer

Travis CI buils status:
Build Status

Code Coverage:
Coverage Status

Latest Version:
Download

Android Arsenal


AndroidGestureRecognizer is an Android implementation of the Apple's UIGestureRecognizer framework (Reverse engineered). https://developer.apple.com/reference/uikit/uigesturerecognizer

For more info about the ui gesture recognizers look this WWDC video https://developer.apple.com/videos/play/wwdc2012/233/

From Apple API reference:

UIGestureRecognizer is an abstract base class for concrete gesture-recognizer classes. A gesture-recognizer object—or, simply, a gesture recognizer—decouples the logic for recognizing a gesture and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.

Available Recognizers

UIGestureRecognizer that looks for single or multiple taps. For the gesture to be recognized, the specified number of fingers must tap the view a specified number of times.

Pinching is a continuous gesture. The gesture begins (began) when the two touches have moved enough to be considered a pinch gesture. The gesture changes (changed) when a finger moves (with both fingers remaining pressed). The gesture ends (ended) when both fingers lift from the view.

Rotation is a continuous gesture. It begins when two touches have moved enough to be considered a rotation. The gesture changes when a finger moves while the two fingers are down. It ends when both fingers have lifted. At each stage in the gesture, the gesture recognizer sends its action message.

UISwipeGestureRecognizer recognizes a swipe when the specified number of touches (numberOfTouchesRequired) have moved mostly in an allowable direction (direction) far enough to be considered a swipe. Swipes can be slow or fast. A slow swipe requires high directional precision but a small distance; a fast swipe requires low directional precision but a large distance.

A panning gesture is continuous. It begins (began) when the minimum number of fingers allowed (minimumNumberOfTouches) has moved enough to be considered a pan. It changes (changed) when a finger moves while at least the minimum number of fingers are pressed down. It ends (ended) when all fingers are lifted.

A gesture recognizer that looks for panning (dragging) gestures that starts near the edge of the screen.
The maximum distance between the screen edge can be changed overriding the resource dimension of gestures_screen_edge_limit.

Long-press gestures are continuous. The gesture begins (began) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (ended) when any of the fingers are lifted.

Discrete vs Continuous

The gesture interpreted by a gesture recognizer can be either discrete or continuous. A discrete gesture, such as a double tap, occurs but once in a multi-touch sequence and results in a single action sent. However, when a gesture recognizer interprets a continuous gesture such as a rotation gesture, it sends an action message for each incremental change until the multi-touch sequence concludes. (from https://developer.apple.com/reference/uikit/uigesturerecognizer)

There are 2 types of UI GestureRecognizers: UIContinuousRecognizer and UIDiscreteGestureRecognizer

UIDiscreteGestureRecognizer

Gesture Recognizers that implement this interface will only fire the Ended state change. Internally they will switch between Possible, Ended, Failed or Cancelled state.

UIContinuousRecognizer

A continuous gesture which will dispatch Began, Changed and Ended state changed events (for instance a pinch gesture, or a rotate gesture).


Demo

Single Tap Double Tap Double Tap 2 Fingers

Logn Press Long Press Double Tap

Pan 1 Finger Pan 2 Fingers

Pinch

Rotate Rotate min angle

Screen Edge 1 Finger Screen Edge 2 Fingers

Swipe Left 1 Finger Swipe Left 2 Fingers

Installation

Maven

Add the library dependency:

implementation 'it.sephiroth.android.library.uigestures:uigesture-recognizer-kotlin:**version**'

JitPack

Step 1. Add the JitPack repository to your build file:

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

Step 2. Add the dependency to your project's build.gradle file:

dependencies {
        implementation 'com.github.sephiroth74:AndroidUIGestureRecognizer:Tag'
}

To See the last release version: https://jitpack.io/#sephiroth74/AndroidUIGestureRecognizer/


Example

    class MainActivity : AppCompatActivity() {

        override fun onCreate(savedInstanceState: Bundle?) {
            ...

            val delegate = UIGestureRecognizerDelegate();

            // single tap gesture
            val recognizer1 = new UITapGestureRecognizer(this)
            recognizer1.tapsRequired = 1
            recognizer1.touchesRequired = 1
            recognizer1.tag = "single-tap";
            recognizer1.actionListener = actionListener

            // double tap gesture
            val recognizer2 = UITapGestureRecognizer(this)
            recognizer2.tag = "double-tap"
            recognizer2.tapsRequired = 2
            recognizer2.touchesRequired = 1
            recognizer2.actionListener = actionListener

            // We want to recognize a single tap and a double tap separately. Normally, when the user
            // performs a double tap, the single tap would be triggered twice.
            // In this way, however, the single tap will wait until the double tap will fail. So a single tap
            // and a double tap will be triggered separately.
            recognizer1.requireFailureOf = recognizer2

            // add both gestures to the delegate
            delegate.addGestureRecognizer(recognizer)
            delegate.addGestureRecognizer(recognizer2)

            // forward the touch events to the delegate
            val rootView = findViewById(R.id.root)
            rootView.setGestureDelegate(delegate)

            // optional delegate methods
            delegate.shouldReceiveTouch = { recognizer -> true }
            delegate.shouldBegin = { recognizer -> true }
            delegate.shouldRecognizeSimultaneouslyWithGestureRecognizer = { recognizer, other -> true }
        }

        // gesture recognizer actionlistener
        private val actionListener = { recognizer: UIGestureRecognizer ->
            // gesture recognized
        }

JavaDoc

https://github.com/sephiroth74/AndroidUIGestureRecognizer/blob/master/docs/it.sephiroth.android.library.uigestures/index.md

More Repositories

1

ImageViewZoom

Android ImageView widget with zoom and pan capabilities
Java
1,893
star
2

android-target-tooltip

Create Toast like tooltips, but targets can be specified, plus custom properties and features
Kotlin
1,467
star
3

Material-BottomNavigation

Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html
Kotlin
1,461
star
4

HorizontalVariableListView

Horizontal list view for Android which allows variable items widths
Java
859
star
5

AndroidWheel

Custom wheel widget for android
Java
385
star
6

NumberSlidingPicker

Android Number Picker with gestures
Kotlin
352
star
7

ViewRevealAnimator

ViewAnimator view with a lollipop style reveal effect
Java
338
star
8

android-floating-action-menu

Floating Action Menu for Android. Inspired by the Google Plus floating menu
Java
239
star
9

purePDF

A complete actionscript PDF library
ActionScript
141
star
10

Android-Exif-Extended

Exif extended library for Android, based on jhead c library (http://www.sentex.net/~mwandel/jhead/)
Java
134
star
11

OverlayMenu

Android Overlay Menu
Java
120
star
12

Android-Easing

Ligh weight android easing
Java
105
star
13

RangeSeekBar

A Range Slider for Android.
Java
99
star
14

Tri-State-Checkbox

3 State Checkbox for android in pure Material Style
Java
59
star
15

RxBroadcast

Reactive Broadcast for Android
Java
12
star
16

ABTest

Simple library for ab testing in android
Java
11
star
17

vignette_demo

Simple demo on how to create a "Vignette" effect in Android
Java
10
star
18

SubtleRater

Discreet AppRater for Android
Java
10
star
19

HListViewAnimations

Based on ListViewAnimations, but target to the HListView instead
Java
10
star
20

Android-MultiSharing

Example on how to do multiple sharing in Android
Java
9
star
21

Appunti

Source code for the Note app available at https://play.google.com/store/apps/details?id=it.sephiroth.android.app.appunti
Kotlin
8
star
22

AlertDialogCustomStyleDemo

Demonstrate how to effectively customize the Android AlertDialog
Java
8
star
23

SBB-Tactile

SBB Tactile Demo App
Kotlin
7
star
24

TwitterAndroidSDK

Twitter SDK for Android, using Twitter4j
Java
7
star
25

python-adb-client

Pure python adb client
Python
5
star
26

android-disk-multi-cache

Multi Cache purpose based on DiskLruCache
Java
5
star
27

radb_client

adb client written in rust
Rust
4
star
28

DiskLruImageCache

Simple file based image cache
Java
4
star
29

ascii_generator

simple python script to print and convert images to ascii art
Python
4
star
30

material_drawable

Provides material background drawables to views
Kotlin
4
star
31

go_adb_client

Go adb client
Go
3
star
32

SimpleLogger

Simple Android logger
Java
2
star
33

git-owners

Simple python utility to generate a report about owners of files inside a git repository
Python
2
star
34

SimpleLruCache

Simple LruCache
Kotlin
2
star
35

kotlin_extensions

Misc Kotlin Extensions for Android
Kotlin
2
star
36

lollipop-transitions

Generic Transitions to be used with the Android 5.0 Transition Framework
1
star
37

Intellij-Settings

1
star
38

AndroidStudio-Settings

Java
1
star
39

JavaCheckStyle

java checkstyle
1
star