gesture

detects gestures on Android with listener and RxJava Observable.

License

License

GroupId

GroupId

com.github.pwittchen
ArtifactId

ArtifactId

gesture-rx2
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

aar
Description

Description

gesture
detects gestures on Android with listener and RxJava Observable.
Project URL

Project URL

https://github.com/pwittchen/gesture
Source Code Management

Source Code Management

https://github.com/pwittchen/gesture

Download gesture-rx2

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.pwittchen/gesture-rx2/ -->
<dependency>
    <groupId>com.github.pwittchen</groupId>
    <artifactId>gesture-rx2</artifactId>
    <version>0.1.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.pwittchen/gesture-rx2/
implementation 'com.github.pwittchen:gesture-rx2:0.1.1'
// https://jarcasting.com/artifacts/com.github.pwittchen/gesture-rx2/
implementation ("com.github.pwittchen:gesture-rx2:0.1.1")
'com.github.pwittchen:gesture-rx2:aar:0.1.1'
<dependency org="com.github.pwittchen" name="gesture-rx2" rev="0.1.1">
  <artifact name="gesture-rx2" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.pwittchen', module='gesture-rx2', version='0.1.1')
)
libraryDependencies += "com.github.pwittchen" % "gesture-rx2" % "0.1.1"
[com.github.pwittchen/gesture-rx2 "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
io.reactivex.rxjava2 : rxjava jar 2.2.18
com.android.support » multidex jar 1.0.2

Project Modules

There are no modules declared in this project.

gesture Android Arsenal

detects gestures on Android with listener and RxJava Observable.

This project is a fork of better-gesture-detector by Polidea.

JavaDoc: http://pwittchen.github.io/gesture/RxJava2.x

Current Branch Branch Artifact Id Build Status Maven Central
RxJava1.x gesture Build Status for RxJava1.x Maven Central
☑️ RxJava2.x gesture-rx2 Build Status for RxJava2.x Maven Central

Contents

Usage

Imperative way - Listener

Step 1: Create Gesture attribute in the Activity:

private Gesture gesture;

Step 2: Initialize Gesture object and add GestureListner:

gesture = new Gesture();

gesture.addListener(new GestureListener() {
  @Override public void onPress(MotionEvent motionEvent) {
    textView.setText("press");
  }

  @Override public void onTap(MotionEvent motionEvent) {
    textView.setText("tap");
  }

  @Override public void onDrag(MotionEvent motionEvent) {
    textView.setText("drag");
  }

  @Override public void onMove(MotionEvent motionEvent) {
    textView.setText("move");
  }

  @Override public void onRelease(MotionEvent motionEvent) {
    textView.setText("release");
  }

  @Override public void onLongPress(MotionEvent motionEvent) {
    textView.setText("longpress");
  }

  @Override public void onMultiTap(MotionEvent motionEvent, int clicks) {
    textView.setText("multitap [" + clicks + "]");
  }
});

Step 3: Override dispatchTouchEvent(MotionEvent) method:

@Override public boolean dispatchTouchEvent(MotionEvent event) {
  gesture.dispatchTouchEvent(event);
  return super.dispatchTouchEvent(event);
}

Reactive way - RxJava

Step 1: Create Gesture attribute and Subscription in the Activity:

private Gesture gesture;
private Disposable subscription;

Step 2: Initialize Gesture object and subscribe RxJava Observable:

gesture = new Gesture();

subscription = gesture.observe()
  .subscribeOn(Schedulers.computation())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(event -> {
    textView.setText(event.toString());
  });

GestureEvent is an enum with the following API:

public enum GestureEvent {
  ON_PRESS,
  ON_TAP,
  ON_DRAG,
  ON_MOVE,
  ON_RELEASE,
  ON_LONG_PRESS,
  ON_MULTI_TAP;

  int getClicks();
  GestureEvent withClicks(int clicks);
}

Step 3: Override dispatchTouchEvent(MotionEvent) method:

@Override public boolean dispatchTouchEvent(MotionEvent event) {
  gesture.dispatchTouchEvent(event);
  return super.dispatchTouchEvent(event);
}

Step 4: Don't forget to dispose subscription when it's no longer needed:

@Override protected void onPause() {
  super.onPause();
  if (subscription != null && !subscription.isDisposed()) {
    subscription.dispose();
  }
}

Examples

Exemplary application is located in app directory of this repository.

If you would like to see sample app in Kotlin, check app-kotlin directory.

Download

latest version: Maven Central

replace x.y.z with the latest version

You can depend on library through Maven:

<dependency>
    <groupId>com.github.pwittchen</groupId>
    <artifactId>gesture-rx2</artifactId>
    <version>x.y.z</version>
</dependency>

or through Gradle:

dependencies {
  compile 'com.github.pwittchen:gesture-rx2:x.y.z'
}

Tests

To execute unit tests run:

./gradlew test

Code style

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

Static code analysis

Static code analysis runs Checkstyle, FindBugs, PMD and Lint. It can be executed with command:

./gradlew check

Reports from analysis are generated in library/build/reports/ directory.

Credits

Initial code base for this project is provided by Polidea.

License

Copyright 2012 Polidea
Copyright 2016 Piotr Wittchen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and

Versions

Version
0.1.1
0.1.0