├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── app-kotlin ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── kotlin │ └── com │ │ └── github │ │ └── pwittchen │ │ └── swipe │ │ └── kotlinapp │ │ ├── SwipeActivity.kt │ │ └── SwipeRxActivity.kt │ └── res │ ├── layout │ └── activity_main.xml │ ├── menu │ └── main_menu.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── pwittchen │ │ └── swipe │ │ └── app │ │ ├── SwipeActivity.java │ │ └── SwipeRxActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ ├── menu │ └── main_menu.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── art ├── swipe-animation.gif └── swipe.png ├── build.gradle ├── config ├── quality.gradle └── quality │ ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml │ ├── findbugs │ └── findbugs-filter.xml │ ├── lint │ └── lint.xml │ └── pmd │ └── pmd-ruleset.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── github │ │ └── pwittchen │ │ └── swipe │ │ └── library │ │ └── rx2 │ │ ├── SimpleSwipeListener.java │ │ ├── Swipe.java │ │ ├── SwipeEvent.java │ │ └── SwipeListener.java │ └── test │ └── java │ └── com │ └── github │ └── pwittchen │ └── swipe │ └── library │ └── rx2 │ └── SwipeTest.java ├── maven_push.gradle └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [pwittchen] 2 | custom: ['https://paypal.me/pwittchen'] 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # IntelliJ IDEA/Android Studio files 29 | *.iml 30 | .idea 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | android: 4 | components: 5 | - tools 6 | - platform-tools 7 | - build-tools-28 8 | - android-28 9 | - extra-android-support 10 | - extra-android-m2repository 11 | licenses: 12 | - android-sdk-license-5be876d5 13 | - android-sdk-license-c81a61d9 14 | - 'android-sdk-preview-license-.+' 15 | - 'android-sdk-license-.+' 16 | - 'google-gdk-license-.+' 17 | 18 | jdk: oraclejdk8 19 | 20 | before_install: 21 | - yes | sdkmanager "platforms;android-27" 22 | 23 | install: 24 | - true 25 | 26 | script: 27 | - ./gradlew clean build test check 28 | 29 | cache: 30 | directories: 31 | - $HOME/.m2 32 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | v. 0.3.0 5 | -------- 6 | *30 Jan 2018* 7 | 8 | - added possibility to consume touch events -> issue #27 -> PR #28 9 | - added abstract class `SimpleSwipeListener` implementing `SwipeListener` interface, which allows to implement several touch events without being forced to implement all of them -> PR #28 10 | - bumped RxJava2.x -> 2.1.9 11 | - bumped Truth -> 0.39 12 | - bumped Kotlin version -> 1.2.20 13 | 14 | v. 0.2.0 15 | -------- 16 | *04 Jan 2018* 17 | 18 | - migrated library to RxJava2.x as a separate artifact on a separate Git branch 19 | - removed `master` branch from the repo 20 | - updated project dependencies 21 | - updated Gradle to 3.x 22 | - added Retrolambda to sample Java app 23 | 24 | v. 0.1.0 25 | -------- 26 | *04 May 2017* 27 | 28 | - updated project dependencies 29 | - updated Gradle configuration 30 | - updated sample apps 31 | - renamed `com.github.pwittchen.swipe.library.Swipe#addListener` to `com.github.pwittchen.swipe.library.Swipe#setListener` - issue #14 32 | - added `Swipe(int swipingThreshold, int swipedThreshold)` constructor, which allows to configure swiping and swiped threshold/sensitivity - fixes #17 33 | 34 | v. 0.0.1 35 | -------- 36 | *06 Mar 2015* 37 | 38 | First release of the library. 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | swipe [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Swipe-brightgreen.svg?style=flat-square)](http://android-arsenal.com/details/1/3323) 2 | ===== 3 | 4 | detects swipe events on Android with listener and RxJava Observable 5 | 6 | ![swipe gestures](art/swipe.png) 7 | 8 | Check out an exemplary **[animation](#example)**! 9 | 10 | JavaDoc is available at: http://pwittchen.github.io/swipe/RxJava2.x 11 | 12 | | Current Branch | Branch | Artifact Id | Build Status | Maven Central | 13 | |:--------------:|:-------:|:-----------:|:-------------:|:-------------:| 14 | | | [`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) | 15 | | :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) | 16 | 17 | Contents 18 | -------- 19 | - [Usage](#usage) 20 | - [Imperative way - Listener](#imperative-way---listener) 21 | - [Reactive way - RxJava](#reactive-way---rxjava) 22 | - [Configuring swipe threshold](#configuring-swipe-threshold) 23 | - [Listening to several events](#listening-to-several-events) 24 | - [Example](#example) 25 | - [Download](#download) 26 | - [Tests](#tests) 27 | - [Code style](#code-style) 28 | - [Static code analysis](#static-code-analysis) 29 | - [References](#references) 30 | - [License](#license) 31 | 32 | Usage 33 | ----- 34 | 35 | ### Imperative way - Listener 36 | 37 | **Step 1**: Create `Swipe` attribute in the `Activity`: 38 | 39 | ```java 40 | private Swipe swipe; 41 | ``` 42 | 43 | **Step 2**: Initialize `Swipe` object and set listener: 44 | 45 | ```java 46 | @Override protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | 49 | setContentView(R.layout.activity_main); 50 | info = (TextView) findViewById(R.id.info); 51 | 52 | swipe = new Swipe(); 53 | swipe.setListener(new SwipeListener() { 54 | @Override public void onSwipingLeft(final MotionEvent event) { 55 | info.setText("SWIPING_LEFT"); 56 | } 57 | 58 | @Override public void onSwipedLeft(final MotionEvent event) { 59 | info.setText("SWIPED_LEFT"); 60 | } 61 | 62 | @Override public void onSwipingRight(final MotionEvent event) { 63 | info.setText("SWIPING_RIGHT"); 64 | } 65 | 66 | @Override public void onSwipedRight(final MotionEvent event) { 67 | info.setText("SWIPED_RIGHT"); 68 | } 69 | 70 | @Override public void onSwipingUp(final MotionEvent event) { 71 | info.setText("SWIPING_UP"); 72 | } 73 | 74 | @Override public void onSwipedUp(final MotionEvent event) { 75 | info.setText("SWIPED_UP"); 76 | } 77 | 78 | @Override public void onSwipingDown(final MotionEvent event) { 79 | info.setText("SWIPING_DOWN"); 80 | } 81 | 82 | @Override public void onSwipedDown(final MotionEvent event) { 83 | info.setText("SWIPED_DOWN"); 84 | } 85 | }); 86 | } 87 | ``` 88 | 89 | **Step 3**: override `dispatchTouchEvent(MotionEvent event)`: 90 | 91 | ```java 92 | @Override public boolean dispatchTouchEvent(MotionEvent event) { 93 | swipe.dispatchTouchEvent(event); 94 | return super.dispatchTouchEvent(event); 95 | } 96 | ``` 97 | 98 | ### Reactive way - RxJava 99 | 100 | **Step 1**: Create `Swipe` attribute and `Subscription` in the `Activity`: 101 | 102 | ```java 103 | private Swipe swipe; 104 | private Disposable disposable; 105 | ``` 106 | 107 | **Step 2**: Initialize `Swipe` object and subscribe `Observable`: 108 | 109 | ```java 110 | @Override protected void onCreate(Bundle savedInstanceState) { 111 | super.onCreate(savedInstanceState); 112 | setContentView(R.layout.activity_main); 113 | info = (TextView) findViewById(R.id.info); 114 | 115 | swipe = new Swipe(); 116 | 117 | disposable = swipe.observe() 118 | .subscribeOn(Schedulers.computation()) 119 | .observeOn(AndroidSchedulers.mainThread()) 120 | .subscribe(swipeEvent -> info.setText(swipeEvent.toString())); 121 | } 122 | ``` 123 | 124 | `SwipeEvent` is an enum with the following values: 125 | 126 | ```java 127 | public enum SwipeEvent { 128 | SWIPING_LEFT, 129 | SWIPED_LEFT, 130 | SWIPING_RIGHT, 131 | SWIPED_RIGHT, 132 | SWIPING_UP, 133 | SWIPED_UP, 134 | SWIPING_DOWN, 135 | SWIPED_DOWN 136 | } 137 | ``` 138 | 139 | **Step 3**: override `dispatchTouchEvent(MotionEvent event)`: 140 | 141 | ```java 142 | @Override public boolean dispatchTouchEvent(MotionEvent event) { 143 | swipe.dispatchTouchEvent(event); 144 | return super.dispatchTouchEvent(event); 145 | } 146 | ``` 147 | 148 | **Step 4**: dispose previously created `Disposable` when it's no longer needed: 149 | 150 | ```java 151 | @Override protected void onPause() { 152 | super.onPause(); 153 | if (disposable != null && !disposable.isDisposed()) { 154 | disposable.dispose(); 155 | } 156 | } 157 | ``` 158 | 159 | Configuring swipe threshold 160 | --------------------------- 161 | 162 | If you want to configure swipe threshold to adjust swipe sensitivity, you can use the following constructor: 163 | 164 | ```java 165 | Swipe(int swipingThreshold, int swipedThreshold) 166 | ``` 167 | 168 | Default `swipingThreshold` is equal to `20` and default `swipedThreshold` is equal to `100`. 169 | In the case of using `Swipe()` constructor, these values are set. 170 | Decreasing these values will increase swiping and swiped events sensitivity. 171 | We can adjust them manually for our needs. 172 | 173 | Listening to several events 174 | --------------------------- 175 | 176 | If 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. 177 | 178 | Example 179 | ------- 180 | 181 | Exemplary application is located in `app` directory of this repository. 182 | 183 | If you would like to know, how to use this library with Kotlin, check `app-kotlin` directory in this repository. 184 | 185 | Below, you can see an animation presenting how sample application works. 186 | 187 | ![swipe gestures](art/swipe-animation.gif) 188 | 189 | Download 190 | -------- 191 | 192 | You can depend on the library through Maven: 193 | 194 | ```xml 195 | 196 | com.github.pwittchen 197 | swipe-rx2 198 | 0.3.0 199 | 200 | ``` 201 | 202 | or through Gradle: 203 | 204 | ```groovy 205 | dependencies { 206 | compile 'com.github.pwittchen:swipe-rx2:0.3.0' 207 | } 208 | ``` 209 | 210 | Tests 211 | ----- 212 | 213 | To execute unit tests run: 214 | 215 | ``` 216 | ./gradlew test 217 | ``` 218 | 219 | Code style 220 | ---------- 221 | 222 | 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. 223 | 224 | Static code analysis 225 | -------------------- 226 | 227 | Static code analysis runs Checkstyle, PMD and Lint. It can be executed with command: 228 | 229 | ``` 230 | ./gradlew check 231 | ``` 232 | 233 | Reports from analysis are generated in `library/build/reports/` directory. 234 | 235 | References 236 | ---------- 237 | 238 | - [better gesture detector project](https://github.com/Polidea/better-gesture-detector) 239 | - [detecting swipe gesture in mobile application](http://wittchen.io/detecting-swipe-gesture-in-mobile-application/) 240 | - [dispatchTouchEvent(event) method in documentation](http://developer.android.com/reference/android/view/ViewGroup.html#dispatchTouchEvent(android.view.MotionEvent)) 241 | - [MotionEvent class in documentation](http://developer.android.com/reference/android/view/MotionEvent.html) 242 | 243 | License 244 | ------- 245 | 246 | Copyright 2016 Piotr Wittchen 247 | 248 | Licensed under the Apache License, Version 2.0 (the "License"); 249 | you may not use this file except in compliance with the License. 250 | You may obtain a copy of the License at 251 | 252 | http://www.apache.org/licenses/LICENSE-2.0 253 | 254 | Unless required by applicable law or agreed to in writing, software 255 | distributed under the License is distributed on an "AS IS" BASIS, 256 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 257 | See the License for the specific language governing permissions and 258 | limitations under the License. 259 | -------------------------------------------------------------------------------- /app-kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app-kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion rootProject.ext.compileSdkVersion 7 | buildToolsVersion rootProject.ext.buildToolsVersion 8 | 9 | defaultConfig { 10 | multiDexEnabled true 11 | minSdkVersion rootProject.ext.minSdkVersion 12 | targetSdkVersion rootProject.ext.compileSdkVersion 13 | applicationId "com.github.pwittchen.swipe.kotlinapp" 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | sourceSets { 26 | main.java.srcDirs += 'src/main/kotlin' 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation project(':library') 32 | implementation deps.rxjava2 33 | implementation deps.rxandroid2 34 | implementation deps.appcompat 35 | implementation deps.kotlinstdlib 36 | } 37 | 38 | repositories { 39 | mavenCentral() 40 | } 41 | 42 | buildscript { 43 | repositories { 44 | mavenCentral() 45 | } 46 | 47 | dependencies { 48 | classpath deps.kotlingradleplugin 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app-kotlin/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/piotr/Development/android/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app-kotlin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app-kotlin/src/main/kotlin/com/github/pwittchen/swipe/kotlinapp/SwipeActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.kotlinapp 17 | 18 | import android.content.Intent 19 | import android.os.Bundle 20 | import android.view.Menu 21 | import android.view.MenuItem 22 | import android.view.MotionEvent 23 | import androidx.appcompat.app.AppCompatActivity 24 | import com.github.pwittchen.swipe.library.rx2.Swipe 25 | import com.github.pwittchen.swipe.library.rx2.SwipeListener 26 | import kotlinx.android.synthetic.main.activity_main.info 27 | 28 | class SwipeActivity : AppCompatActivity() { 29 | 30 | private var swipe: Swipe? = null 31 | 32 | override fun onCreate(savedInstanceState: Bundle?) { 33 | super.onCreate(savedInstanceState) 34 | setContentView(R.layout.activity_main) 35 | swipe = Swipe() 36 | (swipe as Swipe).setListener(object : SwipeListener { 37 | override fun onSwipingLeft(event: MotionEvent) { 38 | info.text = "SWIPING_LEFT" 39 | } 40 | 41 | override fun onSwipedLeft(event: MotionEvent): Boolean { 42 | info.text = "SWIPED_LEFT" 43 | return false 44 | } 45 | 46 | override fun onSwipingRight(event: MotionEvent) { 47 | info.text = "SWIPING_RIGHT" 48 | } 49 | 50 | override fun onSwipedRight(event: MotionEvent): Boolean { 51 | info.text = "SWIPED_RIGHT" 52 | return false 53 | } 54 | 55 | override fun onSwipingUp(event: MotionEvent) { 56 | info.text = "SWIPING_UP" 57 | } 58 | 59 | override fun onSwipedUp(event: MotionEvent): Boolean { 60 | info.text = "SWIPED_UP" 61 | return false 62 | } 63 | 64 | override fun onSwipingDown(event: MotionEvent) { 65 | info.text = "SWIPING_DOWN" 66 | } 67 | 68 | override fun onSwipedDown(event: MotionEvent): Boolean { 69 | info.text = "SWIPED_DOWN" 70 | return false 71 | } 72 | }) 73 | } 74 | 75 | override fun dispatchTouchEvent(event: MotionEvent): Boolean { 76 | (swipe as Swipe).dispatchTouchEvent(event) 77 | return super.dispatchTouchEvent(event) 78 | } 79 | 80 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 81 | menuInflater.inflate(R.menu.main_menu, menu) 82 | return true 83 | } 84 | 85 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 86 | when (item.itemId) { 87 | R.id.listener -> { 88 | } 89 | R.id.rx -> { 90 | val intent = Intent(this, SwipeRxActivity::class.java) 91 | startActivity(intent) 92 | } 93 | } 94 | return true 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app-kotlin/src/main/kotlin/com/github/pwittchen/swipe/kotlinapp/SwipeRxActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.kotlinapp 17 | 18 | import android.os.Bundle 19 | import android.view.Menu 20 | import android.view.MenuItem 21 | import android.view.MotionEvent 22 | import androidx.appcompat.app.AppCompatActivity 23 | import com.github.pwittchen.swipe.library.rx2.Swipe 24 | import io.reactivex.android.schedulers.AndroidSchedulers 25 | import io.reactivex.disposables.Disposable 26 | import io.reactivex.schedulers.Schedulers.computation 27 | import kotlinx.android.synthetic.main.activity_main.info 28 | 29 | class SwipeRxActivity : AppCompatActivity() { 30 | 31 | private var swipe: Swipe? = null 32 | private var subscription: Disposable? = null 33 | 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | setContentView(R.layout.activity_main) 37 | swipe = Swipe() 38 | subscription = (swipe as Swipe).observe() 39 | .subscribeOn(computation()) 40 | .observeOn(AndroidSchedulers.mainThread()) 41 | .subscribe { swipeEvent -> 42 | info.text = swipeEvent.toString() 43 | } 44 | } 45 | 46 | override fun dispatchTouchEvent(event: MotionEvent): Boolean { 47 | return (swipe as Swipe).dispatchTouchEvent(event) || super.dispatchTouchEvent(event) 48 | } 49 | 50 | override fun onPause() { 51 | super.onPause() 52 | safelyUnsubscribe(subscription as Disposable) 53 | } 54 | 55 | fun safelyUnsubscribe(disposable: Disposable) { 56 | if (disposable != null && !disposable.isDisposed) { 57 | disposable.dispose() 58 | } 59 | } 60 | 61 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 62 | menuInflater.inflate(R.menu.main_menu, menu) 63 | return true 64 | } 65 | 66 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 67 | when (item.itemId) { 68 | R.id.listener -> onBackPressed() 69 | R.id.rx -> { 70 | } 71 | } 72 | return true 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app-kotlin/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app-kotlin/src/main/res/menu/main_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | -------------------------------------------------------------------------------- /app-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app-kotlin/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app-kotlin/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 25sp 6 | 7 | -------------------------------------------------------------------------------- /app-kotlin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Swipe app 4 | Listener 5 | Rx 6 | Swipe on the screen! 7 | 8 | -------------------------------------------------------------------------------- /app-kotlin/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | buildToolsVersion rootProject.ext.buildToolsVersion 6 | 7 | defaultConfig { 8 | multiDexEnabled true 9 | minSdkVersion rootProject.ext.minSdkVersion 10 | targetSdkVersion rootProject.ext.compileSdkVersion 11 | applicationId "pwittchen.com.swipedetector" 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | compileOptions { 24 | sourceCompatibility JavaVersion.VERSION_1_8 25 | targetCompatibility JavaVersion.VERSION_1_8 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation project(':library') 31 | implementation deps.rxjava2 32 | implementation deps.rxandroid2 33 | implementation deps.appcompat 34 | } 35 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/piotr/Development/android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/swipe/app/SwipeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.app; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import android.view.Menu; 21 | import android.view.MenuItem; 22 | import android.view.MotionEvent; 23 | import android.widget.TextView; 24 | import androidx.appcompat.app.AppCompatActivity; 25 | import com.github.pwittchen.swipe.library.rx2.Swipe; 26 | import com.github.pwittchen.swipe.library.rx2.SwipeListener; 27 | import pwittchen.com.swipedetector.R; 28 | 29 | public class SwipeActivity extends AppCompatActivity { 30 | 31 | protected TextView info; 32 | private Swipe swipe; 33 | 34 | @Override protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_main); 37 | info = (TextView) findViewById(R.id.info); 38 | swipe = new Swipe(); 39 | swipe.setListener(new SwipeListener() { 40 | @Override public void onSwipingLeft(final MotionEvent event) { 41 | info.setText("SWIPING_LEFT"); 42 | } 43 | 44 | @Override public boolean onSwipedLeft(final MotionEvent event) { 45 | info.setText("SWIPED_LEFT"); 46 | return false; 47 | } 48 | 49 | @Override public void onSwipingRight(final MotionEvent event) { 50 | info.setText("SWIPING_RIGHT"); 51 | } 52 | 53 | @Override public boolean onSwipedRight(final MotionEvent event) { 54 | info.setText("SWIPED_RIGHT"); 55 | return false; 56 | } 57 | 58 | @Override public void onSwipingUp(final MotionEvent event) { 59 | info.setText("SWIPING_UP"); 60 | } 61 | 62 | @Override public boolean onSwipedUp(final MotionEvent event) { 63 | info.setText("SWIPED_UP"); 64 | return false; 65 | } 66 | 67 | @Override public void onSwipingDown(final MotionEvent event) { 68 | info.setText("SWIPING_DOWN"); 69 | } 70 | 71 | @Override public boolean onSwipedDown(final MotionEvent event) { 72 | info.setText("SWIPED_DOWN"); 73 | return false; 74 | } 75 | }); 76 | } 77 | 78 | @Override public boolean dispatchTouchEvent(MotionEvent event) { 79 | return swipe.dispatchTouchEvent(event) || super.dispatchTouchEvent(event); 80 | } 81 | 82 | @Override public boolean onCreateOptionsMenu(Menu menu) { 83 | getMenuInflater().inflate(R.menu.main_menu, menu); 84 | return true; 85 | } 86 | 87 | @Override public boolean onOptionsItemSelected(MenuItem item) { 88 | switch (item.getItemId()) { 89 | case R.id.listener: 90 | break; 91 | case R.id.rx: 92 | final Intent intent = new Intent(this, SwipeRxActivity.class); 93 | startActivity(intent); 94 | break; 95 | } 96 | return true; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/swipe/app/SwipeRxActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.app; 17 | 18 | import android.os.Bundle; 19 | import android.view.Menu; 20 | import android.view.MenuItem; 21 | import android.view.MotionEvent; 22 | import android.widget.TextView; 23 | import androidx.appcompat.app.AppCompatActivity; 24 | import com.github.pwittchen.swipe.library.rx2.Swipe; 25 | import io.reactivex.android.schedulers.AndroidSchedulers; 26 | import io.reactivex.disposables.Disposable; 27 | import io.reactivex.schedulers.Schedulers; 28 | import pwittchen.com.swipedetector.R; 29 | 30 | public class SwipeRxActivity extends AppCompatActivity { 31 | protected TextView info; 32 | private Swipe swipe; 33 | private Disposable disposable; 34 | 35 | @Override protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | info = (TextView) findViewById(R.id.info); 39 | swipe = new Swipe(); 40 | disposable = swipe.observe() 41 | .subscribeOn(Schedulers.computation()) 42 | .observeOn(AndroidSchedulers.mainThread()) 43 | .subscribe(swipeEvent -> info.setText(swipeEvent.toString())); 44 | } 45 | 46 | @Override public boolean dispatchTouchEvent(MotionEvent event) { 47 | return swipe.dispatchTouchEvent(event) || super.dispatchTouchEvent(event); 48 | } 49 | 50 | @Override protected void onPause() { 51 | super.onPause(); 52 | safelyUnsubscribe(disposable); 53 | } 54 | 55 | private void safelyUnsubscribe(Disposable disposable) { 56 | if (disposable != null && !disposable.isDisposed()) { 57 | disposable.dispose(); 58 | } 59 | } 60 | 61 | @Override public boolean onCreateOptionsMenu(Menu menu) { 62 | getMenuInflater().inflate(R.menu.main_menu, menu); 63 | return true; 64 | } 65 | 66 | @Override public boolean onOptionsItemSelected(MenuItem item) { 67 | switch (item.getItemId()) { 68 | case R.id.listener: 69 | onBackPressed(); 70 | break; 71 | case R.id.rx: 72 | break; 73 | } 74 | return true; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 25sp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Swipe app 4 | Listener 5 | Rx 6 | Swipe on the screen! 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /art/swipe-animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/art/swipe-animation.gif -------------------------------------------------------------------------------- /art/swipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/art/swipe.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | ext { 4 | minSdkVersion = 23 5 | compileSdkVersion = 28 6 | buildToolsVersion = '28.0.3' 7 | gradleVersion = '3.0.1' 8 | kotlinVersion = '1.4.0' 9 | } 10 | 11 | ext.deps = [rxjava2 : 'io.reactivex.rxjava2:rxjava:2.2.19', 12 | rxandroid2 : 'io.reactivex.rxjava2:rxandroid:2.1.1', 13 | appcompat : 'androidx.appcompat:appcompat:1.2.0', 14 | junit : 'junit:junit:4.13', 15 | truth : 'com.google.truth:truth:1.0.1', 16 | mockitocore : 'org.mockito:mockito-core:3.5.2', 17 | kotlinstdlib : "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", 18 | kotlingradleplugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"] 19 | 20 | buildscript { 21 | repositories { 22 | jcenter() 23 | google() 24 | maven { 25 | url 'https://plugins.gradle.org/m2/' 26 | } 27 | } 28 | dependencies { 29 | classpath 'com.android.tools.build:gradle:3.6.3' 30 | // NOTE: Do not place your application dependencies here; they belong 31 | // in the individual module build.gradle files 32 | } 33 | } 34 | 35 | allprojects { 36 | repositories { 37 | jcenter() 38 | google() 39 | maven { 40 | url 'https://plugins.gradle.org/m2/' 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /config/quality.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'checkstyle' 2 | apply plugin: 'pmd' 3 | 4 | // Add checkstyle, findbugs, pmd and lint to the check task. 5 | check.dependsOn 'checkstyle', 'pmd', 'lint' 6 | 7 | checkstyle { 8 | toolVersion = "6.0" 9 | } 10 | 11 | task checkstyle(type: Checkstyle) { 12 | configFile file("${project.rootDir}/config/quality/checkstyle/checkstyle.xml") 13 | configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath 14 | source 'src' 15 | include '**/*.java' 16 | exclude '**/gen/**' 17 | classpath = files() 18 | } 19 | 20 | task pmd(type: Pmd) { 21 | ignoreFailures = false 22 | ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml") 23 | ruleSets = [] 24 | 25 | source 'src' 26 | include '**/*.java' 27 | exclude '**/gen/**' 28 | 29 | reports { 30 | xml.enabled = false 31 | html.enabled = true 32 | xml { 33 | destination file("$project.buildDir/reports/pmd/pmd.xml") 34 | } 35 | html { 36 | destination file("$project.buildDir/reports/pmd/pmd.html") 37 | } 38 | } 39 | } 40 | 41 | android { 42 | lintOptions { 43 | abortOnError false 44 | xmlReport false 45 | htmlReport true 46 | lintConfig file("${project.rootDir}/config/quality/lint/lint.xml") 47 | htmlOutput file("$project.buildDir/reports/lint/lint-result.html") 48 | xmlOutput file("$project.buildDir/reports/lint/lint-result.xml") 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /config/quality/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /config/quality/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /config/quality/findbugs/findbugs-filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /config/quality/lint/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /config/quality/pmd/pmd-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Custom ruleset for Android application 8 | 9 | .*/R.java 10 | .*/gen/.* 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=0.3.0 2 | VERSION_CODE=4 3 | GROUP=com.github.pwittchen 4 | 5 | POM_DESCRIPTION=detects swipe events on Android with listener and RxJava Observable 6 | POM_URL=https://github.com/pwittchen/swipe 7 | POM_SCM_URL=https://github.com/pwittchen/swipe 8 | POM_SCM_CONNECTION=scm:git@github.com:pwittchen/swipe.git 9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:pwittchen/swipe.git 10 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 11 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 12 | POM_LICENCE_DIST=repo 13 | POM_DEVELOPER_ID=pwittchen 14 | POM_DEVELOPER_NAME=Piotr Wittchen 15 | 16 | org.gradle.daemon=true 17 | org.gradle.jvmargs=-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx4048m -XX:MaxHeapSize=4048 18 | 19 | android.useAndroidX=true 20 | android.enableJetifier=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pwittchen/swipe/10c1e1501fa927aa020cc165ded139a37607ec86/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 11 15:04:35 CET 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | @rem Execute Gradle 88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 89 | 90 | :end 91 | @rem End local scope for the variables with windows NT shell 92 | if "%ERRORLEVEL%"=="0" goto mainEnd 93 | 94 | :fail 95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 96 | rem the _cmd.exe /c_ return code! 97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 98 | exit /b 1 99 | 100 | :mainEnd 101 | if "%OS%"=="Windows_NT" endlocal 102 | 103 | :omega 104 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply from: '../config/quality.gradle' 3 | apply from: '../maven_push.gradle' 4 | 5 | android { 6 | compileSdkVersion rootProject.ext.compileSdkVersion 7 | buildToolsVersion rootProject.ext.buildToolsVersion 8 | 9 | defaultConfig { 10 | multiDexEnabled true 11 | minSdkVersion rootProject.ext.minSdkVersion 12 | targetSdkVersion rootProject.ext.compileSdkVersion 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | } 29 | 30 | dependencies { 31 | api deps.rxjava2 32 | testImplementation deps.junit 33 | testImplementation deps.truth 34 | testImplementation deps.mockitocore 35 | } 36 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=swipe 2 | POM_ARTIFACT_ID=swipe-rx2 3 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/piotr/Development/android/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /library/src/main/java/com/github/pwittchen/swipe/library/rx2/SimpleSwipeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.library.rx2; 17 | 18 | import android.view.MotionEvent; 19 | 20 | public abstract class SimpleSwipeListener implements SwipeListener { 21 | @Override public void onSwipingLeft(MotionEvent event) { 22 | } 23 | 24 | @Override public boolean onSwipedLeft(MotionEvent event) { 25 | return false; 26 | } 27 | 28 | @Override public void onSwipingRight(MotionEvent event) { 29 | } 30 | 31 | @Override public boolean onSwipedRight(MotionEvent event) { 32 | return false; 33 | } 34 | 35 | @Override public void onSwipingUp(MotionEvent event) { 36 | } 37 | 38 | @Override public boolean onSwipedUp(MotionEvent event) { 39 | return false; 40 | } 41 | 42 | @Override public void onSwipingDown(MotionEvent event) { 43 | } 44 | 45 | @Override public boolean onSwipedDown(MotionEvent event) { 46 | return false; 47 | } 48 | } -------------------------------------------------------------------------------- /library/src/main/java/com/github/pwittchen/swipe/library/rx2/Swipe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.library.rx2; 17 | 18 | import android.view.MotionEvent; 19 | import io.reactivex.Observable; 20 | import io.reactivex.ObservableEmitter; 21 | import io.reactivex.ObservableOnSubscribe; 22 | 23 | /** 24 | * Allows to detect swipe events through listener or with RxJava Observables 25 | */ 26 | public class Swipe { 27 | 28 | /** 29 | * Swiping threshold is added for neglecting swiping 30 | * when differences between changed x or y coordinates are too small 31 | */ 32 | public final static int DEFAULT_SWIPING_THRESHOLD = 20; 33 | /** 34 | * Swiped threshold is added for neglecting swiping 35 | * when differences between changed x or y coordinates are too small 36 | */ 37 | public final static int DEFAULT_SWIPED_THRESHOLD = 100; 38 | 39 | private final int swipingThreshold; 40 | private final int swipedThreshold; 41 | 42 | private SwipeListener swipeListener; 43 | private ObservableEmitter emitter; 44 | private float xDown, xUp; 45 | private float yDown, yUp; 46 | private float xMove, yMove; 47 | 48 | public Swipe() { 49 | this(DEFAULT_SWIPING_THRESHOLD, DEFAULT_SWIPED_THRESHOLD); 50 | } 51 | 52 | public Swipe(int swipingThreshold, int swipedThreshold) { 53 | this.swipingThreshold = swipingThreshold; 54 | this.swipedThreshold = swipedThreshold; 55 | } 56 | 57 | /** 58 | * Adds listener for swipe events. 59 | * Remember to call {@link #dispatchTouchEvent(MotionEvent) dispatchTouchEvent} method as well. 60 | * 61 | * @param swipeListener listener 62 | */ 63 | public void setListener(SwipeListener swipeListener) { 64 | checkNotNull(swipeListener, "swipeListener == null"); 65 | this.swipeListener = swipeListener; 66 | } 67 | 68 | /** 69 | * Observes swipe events with RxJava Observable. 70 | * Remember to call {@link #dispatchTouchEvent(MotionEvent) dispatchTouchEvent} method as well. 71 | * 72 | * @return Observable observable with stream of swipe events 73 | */ 74 | public Observable observe() { 75 | this.swipeListener = createReactiveSwipeListener(); 76 | return Observable.create(new ObservableOnSubscribe() { 77 | @Override public void subscribe(ObservableEmitter emitter) throws Exception { 78 | Swipe.this.emitter = emitter; 79 | } 80 | }); 81 | } 82 | 83 | /** 84 | * Called to process touch screen events. 85 | * 86 | * @param event MotionEvent 87 | */ 88 | public boolean dispatchTouchEvent(final MotionEvent event) { 89 | checkNotNull(event, "event == null"); 90 | boolean isEventConsumed = false; 91 | 92 | switch (event.getAction()) { 93 | case MotionEvent.ACTION_DOWN: // user started touching the screen 94 | onActionDown(event); 95 | break; 96 | case MotionEvent.ACTION_UP: // user stopped touching the screen 97 | isEventConsumed = onActionUp(event); 98 | break; 99 | case MotionEvent.ACTION_MOVE: // user is moving finger on the screen 100 | onActionMove(event); 101 | break; 102 | default: 103 | break; 104 | } 105 | 106 | return isEventConsumed; 107 | } 108 | 109 | private void onActionDown(final MotionEvent event) { 110 | xDown = event.getX(); 111 | yDown = event.getY(); 112 | } 113 | 114 | private boolean onActionUp(final MotionEvent event) { 115 | xUp = event.getX(); 116 | yUp = event.getY(); 117 | final boolean swipedHorizontally = Math.abs(xUp - xDown) > getSwipedThreshold(); 118 | final boolean swipedVertically = Math.abs(yUp - yDown) > getSwipedThreshold(); 119 | boolean isEventConsumed = false; 120 | 121 | if (swipedHorizontally) { 122 | final boolean swipedRight = xUp > xDown; 123 | final boolean swipedLeft = xUp < xDown; 124 | 125 | if (swipedRight) { 126 | isEventConsumed = swipeListener.onSwipedRight(event); 127 | } 128 | if (swipedLeft) { 129 | isEventConsumed |= swipeListener.onSwipedLeft(event); 130 | } 131 | } 132 | 133 | if (swipedVertically) { 134 | final boolean swipedDown = yDown < yUp; 135 | final boolean swipedUp = yDown > yUp; 136 | if (swipedDown) { 137 | isEventConsumed |= swipeListener.onSwipedDown(event); 138 | } 139 | if (swipedUp) { 140 | isEventConsumed |= swipeListener.onSwipedUp(event); 141 | } 142 | } 143 | 144 | return isEventConsumed; 145 | } 146 | 147 | private void onActionMove(final MotionEvent event) { 148 | xMove = event.getX(); 149 | yMove = event.getY(); 150 | final boolean isSwipingHorizontally = Math.abs(xMove - xDown) > getSwipingThreshold(); 151 | final boolean isSwipingVertically = Math.abs(yMove - yDown) > getSwipingThreshold(); 152 | 153 | if (isSwipingHorizontally) { 154 | final boolean isSwipingRight = xMove > xDown; 155 | final boolean isSwipingLeft = xMove < xDown; 156 | 157 | if (isSwipingRight) { 158 | swipeListener.onSwipingRight(event); 159 | } 160 | if (isSwipingLeft) { 161 | swipeListener.onSwipingLeft(event); 162 | } 163 | } 164 | 165 | if (isSwipingVertically) { 166 | final boolean isSwipingDown = yDown < yMove; 167 | final boolean isSwipingUp = yDown > yMove; 168 | 169 | if (isSwipingDown) { 170 | swipeListener.onSwipingDown(event); 171 | } 172 | if (isSwipingUp) { 173 | swipeListener.onSwipingUp(event); 174 | } 175 | } 176 | } 177 | 178 | private SwipeListener createReactiveSwipeListener() { 179 | return new SwipeListener() { 180 | @Override public void onSwipingLeft(MotionEvent event) { 181 | onNextSafely(SwipeEvent.SWIPING_LEFT); 182 | } 183 | 184 | @Override public boolean onSwipedLeft(MotionEvent event) { 185 | onNextSafely(SwipeEvent.SWIPED_LEFT); 186 | return false; 187 | } 188 | 189 | @Override public void onSwipingRight(MotionEvent event) { 190 | onNextSafely(SwipeEvent.SWIPING_RIGHT); 191 | } 192 | 193 | @Override public boolean onSwipedRight(MotionEvent event) { 194 | onNextSafely(SwipeEvent.SWIPED_RIGHT); 195 | return false; 196 | } 197 | 198 | @Override public void onSwipingUp(MotionEvent event) { 199 | onNextSafely(SwipeEvent.SWIPING_UP); 200 | } 201 | 202 | @Override public boolean onSwipedUp(MotionEvent event) { 203 | onNextSafely(SwipeEvent.SWIPED_UP); 204 | return false; 205 | } 206 | 207 | @Override public void onSwipingDown(MotionEvent event) { 208 | onNextSafely(SwipeEvent.SWIPING_DOWN); 209 | } 210 | 211 | @Override public boolean onSwipedDown(MotionEvent event) { 212 | onNextSafely(SwipeEvent.SWIPED_DOWN); 213 | return false; 214 | } 215 | }; 216 | } 217 | 218 | private void onNextSafely(final SwipeEvent swipingLeft) { 219 | if (emitter != null) { 220 | emitter.onNext(swipingLeft); 221 | } 222 | } 223 | 224 | private void checkNotNull(final Object object, final String message) { 225 | if (object == null) { 226 | throw new IllegalArgumentException(message); 227 | } 228 | } 229 | 230 | public int getSwipingThreshold() { 231 | return swipingThreshold; 232 | } 233 | 234 | public int getSwipedThreshold() { 235 | return swipedThreshold; 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /library/src/main/java/com/github/pwittchen/swipe/library/rx2/SwipeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.library.rx2; 17 | 18 | public enum SwipeEvent { 19 | SWIPING_LEFT, 20 | SWIPED_LEFT, 21 | SWIPING_RIGHT, 22 | SWIPED_RIGHT, 23 | SWIPING_UP, 24 | SWIPED_UP, 25 | SWIPING_DOWN, 26 | SWIPED_DOWN 27 | } 28 | -------------------------------------------------------------------------------- /library/src/main/java/com/github/pwittchen/swipe/library/rx2/SwipeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.library.rx2; 17 | 18 | import android.view.MotionEvent; 19 | 20 | public interface SwipeListener { 21 | void onSwipingLeft(final MotionEvent event); 22 | 23 | boolean onSwipedLeft(final MotionEvent event); 24 | 25 | void onSwipingRight(final MotionEvent event); 26 | 27 | boolean onSwipedRight(final MotionEvent event); 28 | 29 | void onSwipingUp(final MotionEvent event); 30 | 31 | boolean onSwipedUp(final MotionEvent event); 32 | 33 | void onSwipingDown(final MotionEvent event); 34 | 35 | boolean onSwipedDown(final MotionEvent event); 36 | } 37 | -------------------------------------------------------------------------------- /library/src/test/java/com/github/pwittchen/swipe/library/rx2/SwipeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Piotr Wittchen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.pwittchen.swipe.library.rx2; 17 | 18 | import android.view.MotionEvent; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.mockito.Mock; 23 | import org.mockito.junit.MockitoJUnitRunner; 24 | import io.reactivex.internal.fuseable.ScalarCallable; 25 | 26 | import static com.google.common.truth.Truth.assertThat; 27 | import static org.mockito.Mockito.when; 28 | 29 | @RunWith(MockitoJUnitRunner.class) public class SwipeTest { 30 | 31 | private static final float MIN_MOTION_CHANGE = 1.0f; 32 | private Swipe swipe; 33 | private SwipeEvent swipeEvent; 34 | @Mock private MotionEvent motionEventDown; 35 | @Mock private MotionEvent motionEventMove; 36 | @Mock private MotionEvent motionEventUp; 37 | @Mock private ScalarCallable swipeEventTarget; 38 | 39 | private Boolean isEventDownConsumed; 40 | private Boolean isEventMoveConsumed; 41 | private Boolean isEventUpConsumed; 42 | 43 | @Before public void setUp() { 44 | swipe = new Swipe(); 45 | swipe.setListener(new SwipeListener() { 46 | @Override public void onSwipingLeft(MotionEvent event) { 47 | swipeEvent = SwipeEvent.SWIPING_LEFT; 48 | } 49 | 50 | @Override public boolean onSwipedLeft(MotionEvent event) { 51 | swipeEvent = SwipeEvent.SWIPED_LEFT; 52 | return swipeEventTarget.call(); 53 | } 54 | 55 | @Override public void onSwipingRight(MotionEvent event) { 56 | swipeEvent = SwipeEvent.SWIPING_RIGHT; 57 | } 58 | 59 | @Override public boolean onSwipedRight(MotionEvent event) { 60 | swipeEvent = SwipeEvent.SWIPED_RIGHT; 61 | return swipeEventTarget.call(); 62 | } 63 | 64 | @Override public void onSwipingUp(MotionEvent event) { 65 | swipeEvent = SwipeEvent.SWIPING_UP; 66 | } 67 | 68 | @Override public boolean onSwipedUp(MotionEvent event) { 69 | swipeEvent = SwipeEvent.SWIPED_UP; 70 | return swipeEventTarget.call(); 71 | } 72 | 73 | @Override public void onSwipingDown(MotionEvent event) { 74 | swipeEvent = SwipeEvent.SWIPING_DOWN; 75 | } 76 | 77 | @Override public boolean onSwipedDown(MotionEvent event) { 78 | swipeEvent = SwipeEvent.SWIPED_DOWN; 79 | return swipeEventTarget.call(); 80 | } 81 | }); 82 | } 83 | 84 | @Test(expected = IllegalArgumentException.class) 85 | public void shouldThrowAnExceptionWhenListenerIsNull() { 86 | swipe.setListener(null); 87 | } 88 | 89 | @Test(expected = IllegalArgumentException.class) 90 | public void shouldThrowAnExceptionWhenMotionEventIsNull() { 91 | swipe.dispatchTouchEvent(null); 92 | } 93 | 94 | @Test public void shouldSwipingRight() throws Exception { 95 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE); 96 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPING_RIGHT); 97 | } 98 | 99 | @Test public void shouldSwipingLeft() throws Exception { 100 | simulateSwipingHorizontally(-swipe.getSwipingThreshold() - MIN_MOTION_CHANGE); 101 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPING_LEFT); 102 | } 103 | 104 | private void simulateSwipingHorizontally(float xMoveIncrement) { 105 | simulateSwipingHorizontally(xMoveIncrement, false); 106 | } 107 | 108 | private void simulateSwipingHorizontally(float xMoveIncrement, boolean isEventConsumed) { 109 | // given 110 | final float xDown = 1.0f; 111 | final float yDown = 1.0f; 112 | when(motionEventDown.getAction()).thenReturn(MotionEvent.ACTION_DOWN); 113 | when(motionEventDown.getX()).thenReturn(xDown); 114 | when(motionEventDown.getY()).thenReturn(yDown); 115 | 116 | final float xMove = xDown + xMoveIncrement; 117 | final float yMove = 1.0f; 118 | when(motionEventMove.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 119 | when(motionEventMove.getX()).thenReturn(xMove); 120 | when(motionEventMove.getY()).thenReturn(yMove); 121 | 122 | when(swipeEventTarget.call()).thenReturn(isEventConsumed); 123 | 124 | // when 125 | 126 | // simulate beginning of touching the screen 127 | isEventDownConsumed = swipe.dispatchTouchEvent(motionEventDown); 128 | // simulate finger move on the screen 129 | isEventMoveConsumed = swipe.dispatchTouchEvent(motionEventMove); 130 | 131 | // then perform assertion in a concrete test 132 | } 133 | 134 | @Test public void shouldSwipingDown() throws Exception { 135 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE); 136 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPING_DOWN); 137 | } 138 | 139 | @Test public void shouldSwipingUp() throws Exception { 140 | simulateSwipingVertically(-swipe.getSwipingThreshold() - MIN_MOTION_CHANGE); 141 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPING_UP); 142 | } 143 | 144 | private void simulateSwipingVertically(float yMoveIncrement) { 145 | simulateSwipingVertically(yMoveIncrement, false); 146 | } 147 | 148 | private void simulateSwipingVertically(float yMoveIncrement, boolean isEventConsumed) { 149 | // given 150 | final float xDown = 1.0f; 151 | final float yDown = 1.0f; 152 | when(motionEventDown.getAction()).thenReturn(MotionEvent.ACTION_DOWN); 153 | when(motionEventDown.getX()).thenReturn(xDown); 154 | when(motionEventDown.getY()).thenReturn(yDown); 155 | 156 | final float xMove = 1.0f; 157 | final float yMove = yDown + yMoveIncrement; 158 | when(motionEventMove.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 159 | when(motionEventMove.getX()).thenReturn(xMove); 160 | when(motionEventMove.getY()).thenReturn(yMove); 161 | 162 | when(swipeEventTarget.call()).thenReturn(isEventConsumed); 163 | 164 | // when 165 | 166 | // simulate beginning of touching the screen 167 | isEventDownConsumed = swipe.dispatchTouchEvent(motionEventDown); 168 | // simulate finger move on the screen 169 | isEventMoveConsumed = swipe.dispatchTouchEvent(motionEventMove); 170 | 171 | // then perform assertion in a concrete test 172 | } 173 | 174 | @Test public void shouldSwipedRight() { 175 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE); 176 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPED_RIGHT); 177 | } 178 | 179 | @Test public void shouldSwipedLeft() { 180 | simulateSwipedHorizontally(-swipe.getSwipedThreshold() - MIN_MOTION_CHANGE); 181 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPED_LEFT); 182 | } 183 | 184 | private void simulateSwipedHorizontally(float xUpIncrement) { 185 | simulateSwipedHorizontally(xUpIncrement, false); 186 | } 187 | 188 | private void simulateSwipedHorizontally(float xUpIncrement, boolean isEventConsumed) { 189 | // given 190 | final float xDown = 1.0f; 191 | final float yDown = 1.0f; 192 | when(motionEventDown.getAction()).thenReturn(MotionEvent.ACTION_DOWN); 193 | when(motionEventDown.getX()).thenReturn(xDown); 194 | when(motionEventDown.getY()).thenReturn(yDown); 195 | 196 | final float xUp = xDown + xUpIncrement; 197 | final float yUp = 1.0f; 198 | when(motionEventUp.getAction()).thenReturn(MotionEvent.ACTION_UP); 199 | when(motionEventUp.getX()).thenReturn(xUp); 200 | when(motionEventUp.getY()).thenReturn(yUp); 201 | 202 | when(swipeEventTarget.call()).thenReturn(isEventConsumed); 203 | 204 | // when 205 | 206 | // simulate beginning of touching the screen 207 | isEventDownConsumed = swipe.dispatchTouchEvent(motionEventDown); 208 | // simulate finger moved and stopped touching screen 209 | isEventUpConsumed = swipe.dispatchTouchEvent(motionEventUp); 210 | 211 | // then perform assertion in a concrete test 212 | } 213 | 214 | @Test public void shouldSwipedDown() { 215 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE); 216 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPED_DOWN); 217 | } 218 | 219 | @Test public void shouldSwipedUp() { 220 | simulateSwipedVertically(-swipe.getSwipedThreshold() - MIN_MOTION_CHANGE); 221 | assertThat(swipeEvent).isEqualTo(SwipeEvent.SWIPED_UP); 222 | } 223 | 224 | private void simulateSwipedVertically(float yUpIncrement) { 225 | simulateSwipedVertically(yUpIncrement, false); 226 | } 227 | 228 | private void simulateSwipedVertically(float yUpIncrement, boolean isEventConsumed) { 229 | // given 230 | final float xDown = 1.0f; 231 | final float yDown = 1.0f; 232 | when(motionEventDown.getAction()).thenReturn(MotionEvent.ACTION_DOWN); 233 | when(motionEventDown.getX()).thenReturn(xDown); 234 | when(motionEventDown.getY()).thenReturn(yDown); 235 | 236 | final float xUp = 1.0f; 237 | final float yUp = yDown + yUpIncrement; 238 | when(motionEventUp.getAction()).thenReturn(MotionEvent.ACTION_UP); 239 | when(motionEventUp.getX()).thenReturn(xUp); 240 | when(motionEventUp.getY()).thenReturn(yUp); 241 | 242 | when(swipeEventTarget.call()).thenReturn(isEventConsumed); 243 | 244 | // when 245 | 246 | // simulate beginning of touching the screen 247 | isEventDownConsumed = swipe.dispatchTouchEvent(motionEventDown); 248 | // simulate finger moved and stopped touching screen 249 | isEventUpConsumed = swipe.dispatchTouchEvent(motionEventUp); 250 | 251 | // then perform assertion in a concrete test 252 | } 253 | 254 | @Test public void shouldNotConsumeSwipingHorizontallyMotionEventDown() { 255 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, false); 256 | assertThat(isEventDownConsumed).isFalse(); 257 | 258 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, true); 259 | assertThat(isEventDownConsumed).isFalse(); 260 | } 261 | 262 | @Test public void shouldNotConsumeSwipingVerticallyMotionEventDown() { 263 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, false); 264 | assertThat(isEventDownConsumed).isFalse(); 265 | 266 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, true); 267 | assertThat(isEventDownConsumed).isFalse(); 268 | } 269 | 270 | @Test public void shouldNotConsumeSwipingHorizontallyMotionEventMove() { 271 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, false); 272 | assertThat(isEventMoveConsumed).isFalse(); 273 | 274 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, true); 275 | assertThat(isEventMoveConsumed).isFalse(); 276 | } 277 | 278 | @Test public void shouldNotConsumeSwipingVerticallyMotionEventMove() { 279 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, false); 280 | assertThat(isEventMoveConsumed).isFalse(); 281 | 282 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, true); 283 | assertThat(isEventMoveConsumed).isFalse(); 284 | } 285 | 286 | @Test public void shouldIgnoreSwipingHorizontallyMotionEventUp() { 287 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, false); 288 | //MotionEvent.ACTION_UP is not used in simulation, assuming result should be null 289 | assertThat(isEventUpConsumed).isNull(); 290 | 291 | simulateSwipingHorizontally(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, true); 292 | //MotionEvent.ACTION_UP is not used in simulation, assuming result should be null 293 | assertThat(isEventUpConsumed).isNull(); 294 | } 295 | 296 | @Test public void shouldIgnoreSwipingVerticallyMotionEventUp() { 297 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, false); 298 | //MotionEvent.ACTION_UP is not used in simulation, assuming result should be null 299 | assertThat(isEventUpConsumed).isNull(); 300 | 301 | simulateSwipingVertically(swipe.getSwipingThreshold() + MIN_MOTION_CHANGE, true); 302 | //MotionEvent.ACTION_UP is not used in simulation, assuming result should be null 303 | assertThat(isEventUpConsumed).isNull(); 304 | } 305 | 306 | @Test public void shouldNotConsumeSwipedHorizontallyMotionEventDown() { 307 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, false); 308 | assertThat(isEventDownConsumed).isFalse(); 309 | 310 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, true); 311 | assertThat(isEventDownConsumed).isFalse(); 312 | } 313 | 314 | @Test public void shouldNotConsumeSwipedVerticallyMotionEventDown() { 315 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, false); 316 | assertThat(isEventDownConsumed).isFalse(); 317 | 318 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, true); 319 | assertThat(isEventDownConsumed).isFalse(); 320 | } 321 | 322 | @Test public void shouldConsumeSwipedHorizontallyMotionEventUp() { 323 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, false); 324 | assertThat(isEventUpConsumed).isFalse(); 325 | 326 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, true); 327 | assertThat(isEventUpConsumed).isTrue(); 328 | } 329 | 330 | @Test public void shouldConsumeSwipedVerticallyMotionEventUp() { 331 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, false); 332 | assertThat(isEventUpConsumed).isFalse(); 333 | 334 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, true); 335 | assertThat(isEventUpConsumed).isTrue(); 336 | } 337 | 338 | @Test public void shouldIgnoreSwipedHorizontallyMotionEventMove() { 339 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, false); 340 | //MotionEvent.ACTION_MOVE is not used in simulation, assuming result should be null 341 | assertThat(isEventMoveConsumed).isNull(); 342 | 343 | simulateSwipedHorizontally(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, true); 344 | //MotionEvent.ACTION_MOVE is not used in simulation, assuming result should be null 345 | assertThat(isEventMoveConsumed).isNull(); 346 | } 347 | 348 | @Test public void shouldIgnoreSwipedVerticallyMotionEventMove() { 349 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, false); 350 | //MotionEvent.ACTION_MOVE is not used in simulation, assuming result should be null 351 | assertThat(isEventMoveConsumed).isNull(); 352 | 353 | simulateSwipedVertically(swipe.getSwipedThreshold() + MIN_MOTION_CHANGE, true); 354 | //MotionEvent.ACTION_MOVE is not used in simulation, assuming result should be null 355 | assertThat(isEventMoveConsumed).isNull(); 356 | } 357 | } -------------------------------------------------------------------------------- /maven_push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Chris Banes 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'maven' 18 | apply plugin: 'signing' 19 | 20 | def isReleaseBuild() { 21 | return VERSION_NAME.contains("SNAPSHOT") == false 22 | } 23 | 24 | def getReleaseRepositoryUrl() { 25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 27 | } 28 | 29 | def getSnapshotRepositoryUrl() { 30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 31 | : "https://oss.sonatype.org/content/repositories/snapshots/" 32 | } 33 | 34 | def getRepositoryUsername() { 35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 36 | } 37 | 38 | def getRepositoryPassword() { 39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 40 | } 41 | 42 | afterEvaluate { project -> 43 | uploadArchives { 44 | repositories { 45 | mavenDeployer { 46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 47 | 48 | pom.groupId = GROUP 49 | pom.artifactId = POM_ARTIFACT_ID 50 | pom.version = VERSION_NAME 51 | 52 | repository(url: getReleaseRepositoryUrl()) { 53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 54 | } 55 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 57 | } 58 | 59 | pom.project { 60 | name POM_NAME 61 | packaging POM_PACKAGING 62 | description POM_DESCRIPTION 63 | url POM_URL 64 | 65 | scm { 66 | url POM_SCM_URL 67 | connection POM_SCM_CONNECTION 68 | developerConnection POM_SCM_DEV_CONNECTION 69 | } 70 | 71 | licenses { 72 | license { 73 | name POM_LICENCE_NAME 74 | url POM_LICENCE_URL 75 | distribution POM_LICENCE_DIST 76 | } 77 | } 78 | 79 | developers { 80 | developer { 81 | id POM_DEVELOPER_ID 82 | name POM_DEVELOPER_NAME 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | signing { 91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 92 | sign configurations.archives 93 | } 94 | 95 | task androidJavadocs(type: Javadoc) { 96 | source = android.sourceSets.main.java.srcDirs 97 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 98 | failOnError = false 99 | } 100 | 101 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 102 | classifier = 'javadoc' 103 | from androidJavadocs.destinationDir 104 | } 105 | 106 | task androidSourcesJar(type: Jar) { 107 | classifier = 'sources' 108 | from android.sourceSets.main.java.sourceFiles 109 | } 110 | 111 | artifacts { 112 | archives androidSourcesJar 113 | archives androidJavadocsJar 114 | } 115 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library', ':app-kotlin' 2 | --------------------------------------------------------------------------------