https://github.com/pwittchen/touch
Android library, which allows to monitor raw touch events on the screen of the device with RxJava
https://github.com/pwittchen/touch
android rxjava screen touch touchscreen
Last synced: 10 months ago
JSON representation
Android library, which allows to monitor raw touch events on the screen of the device with RxJava
- Host: GitHub
- URL: https://github.com/pwittchen/touch
- Owner: pwittchen
- License: apache-2.0
- Created: 2020-02-28T20:36:06.000Z (over 6 years ago)
- Default Branch: RxJava2.x
- Last Pushed: 2020-04-06T13:03:45.000Z (about 6 years ago)
- Last Synced: 2025-05-21T09:11:24.828Z (about 1 year ago)
- Topics: android, rxjava, screen, touch, touchscreen
- Language: Java
- Homepage:
- Size: 172 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# touch
Android library, which allows to monitor raw touch events on the screen of the device with RxJava
Current Branch | Branch | Artifact Id | Maven Central | CI build |
|:--------------:|:-------:|:-----------:|:-------------:|:--------:|
| :ballot_box_with_check: | [`RxJava2.x`](https://github.com/pwittchen/touch/tree/RxJava2.x) | `touch-rx2` |  |  |
Contents
--------
- [Usage](#usage)
- [Example](#example)
- [Download](#download)
- [Tests](#tests)
- [Code style](#code-style)
- [Static code analysis](#static-code-analysis)
- [Release](#release)
- [References](#references)
- [License](#license)
Usage
-----
**Step 1**: Create `Touch` attribute and `Disposable` in the `Activity`:
```java
private Touch touch;
private Disposable disposable;
```
**Step 2**: Initialize `Touch` object and subscribe `Flowable`:
```java
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);
touch = new Touch();
disposable = touch.observe()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(touchEvent -> info.setText(touchEvent.toString()));
}
```
`TouchEvent` is a class with the following values:
```java
public enum TouchEvent {
public float x() {}
public float y() {}
public TouchType type() {}
}
```
`TouchType` is an enum with the following values:
```java
public enum TouchType {
UP, DOWN, MOVE
}
```
**Step 3**: override `dispatchTouchEvent(MotionEvent event)`:
```java
@Override public boolean dispatchTouchEvent(MotionEvent event) {
touch.dispatchTouchEvent(event);
return super.dispatchTouchEvent(event);
}
```
**Step 4**: dispose previously created `Disposable` when it's no longer needed:
```java
@Override protected void onPause() {
super.onPause();
if (disposable != null && !disposable.isDisposed()) {
disposable.dispose();
}
}
```
Example
-------
Exemplary application is located in `app` directory of this repository.
Download
--------
latest version: 
replace `x.y.z` with the latest version of the library
You can depend on the library through Maven:
```xml
com.github.pwittchen
touch-rx2
x.y.z
```
or through Gradle:
```groovy
dependencies {
compile 'com.github.pwittchen:touch-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, PMD and Lint. It can be executed with command:
```
./gradlew check
```
Reports from analysis are generated in `library/build/reports/` directory.
Release
-------
To release the library, bump its version and call the following command:
```
./gradlew uploadArchives closeAndReleaseRepository
```
References
----------
- [better gesture detector project](https://github.com/Polidea/better-gesture-detector)
- [gesture project](https://github.com/pwittchen/gesture)
- [swipe project](https://github.com/pwittchen/swipe)
- [detecting swipe gesture in mobile application](http://wittchen.io/detecting-swipe-gesture-in-mobile-application/)
- [dispatchTouchEvent(event) method in documentation](http://developer.android.com/reference/android/view/ViewGroup.html#dispatchTouchEvent(android.view.MotionEvent))
- [MotionEvent class in documentation](http://developer.android.com/reference/android/view/MotionEvent.html)
License
-------
Copyright 2020 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
limitations under the License.