{"id":18784478,"url":"https://github.com/pwittchen/swipe","last_synced_at":"2025-04-06T02:09:20.868Z","repository":{"id":25031295,"uuid":"28450866","full_name":"pwittchen/swipe","owner":"pwittchen","description":"👉 detects swipe events on Android","archived":false,"fork":false,"pushed_at":"2020-08-19T08:51:34.000Z","size":617,"stargazers_count":328,"open_issues_count":4,"forks_count":43,"subscribers_count":12,"default_branch":"RxJava2.x","last_synced_at":"2025-03-30T01:08:21.363Z","etag":null,"topics":["android","gesture-detection","rxandroid","rxandroid2","rxjava","rxjava2","swipe"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwittchen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["pwittchen"],"custom":["https://paypal.me/pwittchen"]}},"created_at":"2014-12-24T14:13:05.000Z","updated_at":"2024-11-13T10:14:59.000Z","dependencies_parsed_at":"2022-08-23T11:31:20.979Z","dependency_job_id":null,"html_url":"https://github.com/pwittchen/swipe","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2Fswipe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2Fswipe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2Fswipe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2Fswipe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwittchen","download_url":"https://codeload.github.com/pwittchen/swipe/tar.gz/refs/heads/RxJava2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","gesture-detection","rxandroid","rxandroid2","rxjava","rxjava2","swipe"],"created_at":"2024-11-07T20:43:09.112Z","updated_at":"2025-04-06T02:09:20.841Z","avatar_url":"https://github.com/pwittchen.png","language":"Java","funding_links":["https://github.com/sponsors/pwittchen","https://paypal.me/pwittchen"],"categories":[],"sub_categories":[],"readme":"swipe [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Swipe-brightgreen.svg?style=flat-square)](http://android-arsenal.com/details/1/3323)\n=====\n\ndetects swipe events on Android with listener and RxJava Observable\n\n![swipe gestures](art/swipe.png)\n\nCheck out an exemplary **[animation](#example)**!\n\nJavaDoc is available at: http://pwittchen.github.io/swipe/RxJava2.x\n\n| Current Branch | Branch  | Artifact Id | Build Status  | Maven Central |\n|:--------------:|:-------:|:-----------:|:-------------:|:-------------:|\n| | [`RxJava1.x`](https://github.com/pwittchen/swipe/tree/RxJava1.x) | `swipe` | ![Build Status for RxJava1.x](https://img.shields.io/travis/pwittchen/swipe/RxJava1.x.svg?style=flat-square) | ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/swipe.svg?style=flat-square) |\n| :ballot_box_with_check: | [`RxJava2.x`](https://github.com/pwittchen/swipe/tree/RxJava2.x) | `swipe-rx2` | ![Build Status for RxJava2.x](https://img.shields.io/travis/pwittchen/swipe/RxJava2.x.svg?style=flat-square) | ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/swipe-rx2.svg?style=flat-square) |\n\nContents\n--------\n- [Usage](#usage)\n  - [Imperative way - Listener](#imperative-way---listener)\n  - [Reactive way - RxJava](#reactive-way---rxjava)\n- [Configuring swipe threshold](#configuring-swipe-threshold)\n- [Listening to several events](#listening-to-several-events)\n- [Example](#example)\n- [Download](#download)\n- [Tests](#tests)\n- [Code style](#code-style)\n- [Static code analysis](#static-code-analysis)\n- [References](#references)\n- [License](#license)\n\nUsage\n-----\n\n### Imperative way - Listener\n\n**Step 1**: Create `Swipe` attribute in the `Activity`:\n\n```java\nprivate Swipe swipe;\n```\n\n**Step 2**: Initialize `Swipe` object and set listener:\n\n```java\n@Override protected void onCreate(Bundle savedInstanceState) {\n  super.onCreate(savedInstanceState);\n\n  setContentView(R.layout.activity_main);\n  info = (TextView) findViewById(R.id.info);\n\n  swipe = new Swipe();\n  swipe.setListener(new SwipeListener() {\n    @Override public void onSwipingLeft(final MotionEvent event) {\n      info.setText(\"SWIPING_LEFT\");\n    }\n\n    @Override public void onSwipedLeft(final MotionEvent event) {\n      info.setText(\"SWIPED_LEFT\");\n    }\n\n    @Override public void onSwipingRight(final MotionEvent event) {\n      info.setText(\"SWIPING_RIGHT\");\n    }\n\n    @Override public void onSwipedRight(final MotionEvent event) {\n      info.setText(\"SWIPED_RIGHT\");\n    }\n\n    @Override public void onSwipingUp(final MotionEvent event) {\n      info.setText(\"SWIPING_UP\");\n    }\n\n    @Override public void onSwipedUp(final MotionEvent event) {\n      info.setText(\"SWIPED_UP\");\n    }\n\n    @Override public void onSwipingDown(final MotionEvent event) {\n      info.setText(\"SWIPING_DOWN\");\n    }\n\n    @Override public void onSwipedDown(final MotionEvent event) {\n      info.setText(\"SWIPED_DOWN\");\n    }\n  });\n}\n```\n\n**Step 3**: override `dispatchTouchEvent(MotionEvent event)`:\n\n```java\n@Override public boolean dispatchTouchEvent(MotionEvent event) {\n  swipe.dispatchTouchEvent(event);\n  return super.dispatchTouchEvent(event);\n}\n```\n\n### Reactive way - RxJava\n\n**Step 1**: Create `Swipe` attribute and `Subscription` in the `Activity`:\n\n```java\nprivate Swipe swipe;\nprivate Disposable disposable;\n```\n\n**Step 2**: Initialize `Swipe` object and subscribe `Observable`:\n\n```java\n@Override protected void onCreate(Bundle savedInstanceState) {\n  super.onCreate(savedInstanceState);\n  setContentView(R.layout.activity_main);\n  info = (TextView) findViewById(R.id.info);\n\n  swipe = new Swipe();\n\n  disposable = swipe.observe()\n      .subscribeOn(Schedulers.computation())\n      .observeOn(AndroidSchedulers.mainThread())\n      .subscribe(swipeEvent -\u003e info.setText(swipeEvent.toString()));\n}\n```\n\n`SwipeEvent` is an enum with the following values:\n\n```java\npublic enum SwipeEvent {\n  SWIPING_LEFT,\n  SWIPED_LEFT,\n  SWIPING_RIGHT,\n  SWIPED_RIGHT,\n  SWIPING_UP,\n  SWIPED_UP,\n  SWIPING_DOWN,\n  SWIPED_DOWN\n}\n```\n\n**Step 3**: override `dispatchTouchEvent(MotionEvent event)`:\n\n```java\n@Override public boolean dispatchTouchEvent(MotionEvent event) {\n  swipe.dispatchTouchEvent(event);\n  return super.dispatchTouchEvent(event);\n}\n```\n\n**Step 4**: dispose previously created `Disposable` when it's no longer needed:\n\n```java\n@Override protected void onPause() {\n  super.onPause();\n  if (disposable != null \u0026\u0026 !disposable.isDisposed()) {\n    disposable.dispose();\n  }\n}\n```\n\nConfiguring swipe threshold\n---------------------------\n\nIf you want to configure swipe threshold to adjust swipe sensitivity, you can use the following constructor:\n\n```java\nSwipe(int swipingThreshold, int swipedThreshold)\n```\n\nDefault `swipingThreshold` is equal to `20` and default `swipedThreshold` is equal to `100`.\nIn the case of using `Swipe()` constructor, these values are set.\nDecreasing these values will increase swiping and swiped events sensitivity.\nWe can adjust them manually for our needs.\n\nListening to several events\n---------------------------\n\nIf you want to react only on one event or several events in imperative way, use abstract class `SimpleSwipeListener` instead of `SwipeListener` interface and implement methods, which you need.\n\nExample\n-------\n\nExemplary application is located in `app` directory of this repository.\n\nIf you would like to know, how to use this library with Kotlin, check `app-kotlin` directory in this repository.\n\nBelow, you can see an animation presenting how sample application works.\n\n![swipe gestures](art/swipe-animation.gif)\n\nDownload\n--------\n\nYou can depend on the library through Maven:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.pwittchen\u003c/groupId\u003e\n    \u003cartifactId\u003eswipe-rx2\u003c/artifactId\u003e\n    \u003cversion\u003e0.3.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nor through Gradle:\n\n```groovy\ndependencies {\n  compile 'com.github.pwittchen:swipe-rx2:0.3.0'\n}\n```\n\nTests\n-----\n\nTo execute unit tests run:\n\n```\n./gradlew test\n```\n\nCode style\n----------\n\nCode style used in the project is called `SquareAndroid` from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.\n\nStatic code analysis\n--------------------\n\nStatic code analysis runs Checkstyle, PMD and Lint. It can be executed with command:\n\n ```\n ./gradlew check\n ```\n\nReports from analysis are generated in `library/build/reports/` directory.\n\nReferences\n----------\n\n- [better gesture detector project](https://github.com/Polidea/better-gesture-detector)\n- [detecting swipe gesture in mobile application](http://wittchen.io/detecting-swipe-gesture-in-mobile-application/)\n- [dispatchTouchEvent(event) method in documentation](http://developer.android.com/reference/android/view/ViewGroup.html#dispatchTouchEvent(android.view.MotionEvent))\n- [MotionEvent class in documentation](http://developer.android.com/reference/android/view/MotionEvent.html)\n\nLicense\n-------\n\n    Copyright 2016 Piotr Wittchen\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwittchen%2Fswipe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwittchen%2Fswipe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwittchen%2Fswipe/lists"}