├── .github └── workflows │ └── android.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── RELEASING.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── pwittchen │ │ └── reactivesensors │ │ └── app │ │ ├── MainActivity.java │ │ ├── SensorActivity.java │ │ ├── SensorHelper.java │ │ └── samples │ │ ├── AccelerometerActivity.java │ │ ├── AmbientTemperatureActivity.java │ │ ├── GravityActivity.java │ │ ├── GyroscopeActivity.java │ │ ├── LightActivity.java │ │ ├── LinearAccelerationActivity.java │ │ ├── MagneticFieldActivity.java │ │ ├── OrientationActivity.java │ │ ├── PressureActivity.java │ │ ├── ProximityActivity.java │ │ ├── RelativeHumidityActivity.java │ │ ├── RotationVectorActivity.java │ │ └── TemperatureActivity.java │ └── res │ ├── layout │ ├── activity_main.xml │ └── activity_sensor_sample.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── 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 │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── pwittchen │ │ └── reactivesensors │ │ └── library │ │ └── ReactiveSensorsTest.java │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── github │ └── pwittchen │ └── reactivesensors │ └── library │ ├── ReactiveSensorEvent.java │ ├── ReactiveSensors.java │ ├── SensorEventListenerWrapper.java │ ├── SensorNotFoundException.java │ └── SensorsProxy.java ├── maven_push.gradle └── settings.gradle /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - Rxjava1.x 7 | - RxJava2.x 8 | - RxJava3.x 9 | pull_request: 10 | branches: 11 | - RxJava1.x 12 | - RxJava2.x 13 | - RxJava3.x 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: set up JDK 1.8 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 1.8 26 | - name: Gradle Build 27 | run: ./gradlew clean build 28 | - name: Gradle Check 29 | run: ./gradlew check -x test 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # system files 2 | .DS_Store 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | /*/build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # IntelliJ IDEA files 33 | .idea 34 | *.iml 35 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | v. 0.4.5 5 | -------- 6 | *04 Mar 2022* 7 | 8 | - updated Android CI config 9 | - removed FUNDING.yml file 10 | - fix format in README.md 11 | - updated Android CI badge in README.md 12 | - added releasing guidelines 13 | - updated checkout gh action from v2 to v3 14 | - issue #99: bumped project dependencies, updated configuration, removed legacy support annotations dependency from the library 15 | 16 | v. 0.4.4 17 | -------- 18 | *30 Oct 2020* 19 | 20 | - updated RxJava to 3.0.7 21 | - updated Android Gradle Build Tools to 4.0.2 22 | 23 | v. 0.4.3 24 | -------- 25 | *03 May 2020* 26 | 27 | - updated RxJava from 3.0.2 to 3.0.3 28 | 29 | v. 0.4.2 30 | -------- 31 | *27 Apr 2020* 32 | 33 | - made getters of ReactiveSensorEvent consistent: `getAccuracy()` -> `accuracy()` 34 | 35 | v. 0.4.1 36 | -------- 37 | *14 Apr 2020* 38 | 39 | - fixed sonatype artifact release issues 40 | 41 | v. 0.4.0 42 | -------- 43 | *14 Apr 2020* 44 | 45 | - added new methods to `ReactiveSensorEvent` class: `int sensorId()`, `String sensorName()`, `float[] sensorValues()` 46 | 47 | v. 0.3.3 48 | -------- 49 | *14 Apr 2020* 50 | 51 | - added `SensorsProxy` interface implemented by `ReactiveSensors` class to improve library integration and testability in external projects, which depend on it 52 | 53 | v. 0.3.2 54 | -------- 55 | *08 Apr 2020* 56 | 57 | - fixing `Flowable` - moving sensors registration before `Flowable.create(...)` method (without that several RxJava operators could not be applied on the stream) 58 | - making `ReactiveSensorEvent` non-final 59 | - making `SensorEventListener` package-private 60 | - changing `FlowableEmitter` in `SensorEventListener` to `Emitter` 61 | - removing `getEmitter()` method from `SensorEventListenerWrapper` 62 | 63 | v. 0.3.1 64 | -------- 65 | *07 Apr 2020* 66 | 67 | - downgraded min Android SDK version to 16 68 | 69 | v. 0.3.0 70 | -------- 71 | *06 Apr 2020* 72 | 73 | - migrated library to RxJava3 74 | 75 | v. 0.2.0 76 | -------- 77 | *02 Nov 2017* 78 | 79 | - returning error through Rx to make the error handling easier - issue #29 80 | - creating sensor observable with the ability to specify handler - PR #26 81 | - updated project dependencies 82 | - migrated library to RxJava2.x on `RxJava2.x` branch 83 | - kept backward compatibility with RxJava1.x on `RxJava1.x` branch 84 | - removed `master` branch 85 | 86 | v. 0.1.2 87 | -------- 88 | *31 Jul 2016* 89 | 90 | - bumped RxJava dependency to v. 1.1.8 91 | - bumped RxAndroid dependency to v. 1.2.1 92 | - bumped Google Truth test dependency to v. 0.28 93 | - bumped Compile SDK version to v. 23 94 | - bumped Kotlin to v. 1.0.0 95 | - updated sample apps 96 | 97 | 98 | v. 0.1.1 99 | -------- 100 | *13 Dec 2015* 101 | 102 | - bumped RxJava dependency to v. 1.1.0 103 | - bumped RxAndroid dependency to v. 1.1.0 104 | - bumped Google Truth test dependency to v. 0.27 105 | - bumped Gradle Build Tools to v. 1.3.1 106 | 107 | v. 0.1.0 108 | -------- 109 | *06 Dec 2015* 110 | 111 | - removed `filterSensorChanged()` method from `ReactiveSensorEvent` class 112 | - removed `filterAccuracyChanged()` method from `ReactiveSensorEvent` class 113 | - created `ReactiveSensorFilter` class 114 | - added `filterSensorChanged()` method to `ReactiveSensorFilter` class 115 | - added `filterAccuracyChanged()` method to `ReactiveSensorFilter` class 116 | - added sample app in Kotlin 117 | - added code examples with more sensors in sample apps 118 | - improved sample apps 119 | - added Static Code Analysis (CheckStyle, PMD, FindBugs, Android Lint) 120 | - updated documentation in `README.md` file 121 | 122 | v. 0.0.1 123 | -------- 124 | *05 Sep 2015* 125 | 126 | - first release of the library 127 | -------------------------------------------------------------------------------- /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 | # ReactiveSensors 2 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ReactiveSensors-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2451) [![Android CI](https://github.com/pwittchen/ReactiveSensors/actions/workflows/android.yml/badge.svg)](https://github.com/pwittchen/ReactiveSensors/actions/workflows/android.yml) 3 | 4 | Android library monitoring hardware sensors with RxJava. 5 | 6 | | Current Branch | Branch | Artifact Id | Maven Central | 7 | |:--------------:|:-------:|:-----------:|:--------------:| 8 | | | [`RxJava1.x`](https://github.com/pwittchen/ReactiveSensors/tree/RxJava1.x) | `reactivesensors` | ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/reactivesensors.svg?style=flat) | 9 | | | [`RxJava2.x`](https://github.com/pwittchen/ReactiveSensors/tree/RxJava2.x) | `reactivesensors-rx2` | ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/reactivesensors-rx2.svg?style=flat) | 10 | | :ballot_box_with_check: | [`RxJava3.x`](https://github.com/pwittchen/ReactiveSensors/tree/RxJava3.x) | `reactivesensors-rx3` | ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/reactivesensors-rx3.svg?style=flat) | 11 | 12 | 13 | Contents 14 | -------- 15 | - [Usage](#usage) 16 | - [Setting sampling period](#setting-sampling-period) 17 | - [Example](#example) 18 | - [Good practices](#good-practices) 19 | - [Checking whether sensor exists](#checking-whether-sensor-exists) 20 | - [Letting it crash](#letting-it-crash) 21 | - [Subscribing and disposing flowables](#subscribing-and-disposing-flowables) 22 | - [Filtering stream](#filtering-stream) 23 | - [Writing tests](#writing-tests) 24 | - [Other practices](#other-practices) 25 | - [Download](#download) 26 | - [Tests](#tests) 27 | - [Code style](#code-style) 28 | - [Static code analysis](#static-code-analysis) 29 | - [Releasing](#releasing) 30 | - [References](#references) 31 | - [License](#license) 32 | 33 | Usage 34 | ----- 35 | 36 | Code sample below demonstrates how to observe Gyroscope sensor. 37 | 38 | Please note that we are filtering events occurring when sensor readings change with `ReactiveSensorEvent::sensorChanged` method. There's also event describing change of sensor's accuracy, which can be filtered with `ReactiveSensorEvent::accuracyChanged` method. When we don't apply any filter, we will be notified both about sensor readings and accuracy changes. 39 | 40 | ```java 41 | new ReactiveSensors(context).observeSensor(Sensor.TYPE_GYROSCOPE) 42 | .subscribeOn(Schedulers.computation()) 43 | .filter(ReactiveSensorEvent::sensorChanged) 44 | .observeOn(AndroidSchedulers.mainThread()) 45 | .subscribe(new Consumer() { 46 | @Override public void call(ReactiveSensorEvent event) { 47 | 48 | float x = event.sensorValues()[0]; 49 | float y = event.sensorValues()[1]; 50 | float z = event.sensorValues()[2]; 51 | 52 | String message = String.format("x = %f, y = %f, z = %f", x, y, z); 53 | 54 | Log.d("gyroscope readings", message); 55 | } 56 | }); 57 | } 58 | ``` 59 | 60 | We can observe any hardware sensor in the same way. You can check [list of all sensors in official Android documentation](http://developer.android.com/guide/topics/sensors/sensors_overview.html#sensors-intro). To get list of all sensors available on the current device, you can use `getSensors()` method available in `ReactiveSensors` class. 61 | 62 | ### Setting sampling period 63 | 64 | Default sampling period for `Flowable` below is set to `SensorManager.SENSOR_DELAY_NORMAL`. 65 | 66 | ```java 67 | Flowable observeSensor(int sensorType) 68 | ``` 69 | 70 | We can configure sampling period according to our needs with the following flowable: 71 | 72 | ```java 73 | Flowable observeSensor(final int sensorType, final int samplingPeriodInUs) 74 | ``` 75 | 76 | We can use predefined values available in `SensorManager` class from Android SDK: 77 | - `int SENSOR_DELAY_FASTEST` - get sensor data as fast as possible 78 | - `int SENSOR_DELAY_GAME` - rate suitable for games 79 | - `int SENSOR_DELAY_NORMAL` - rate (default) suitable for screen orientation changes 80 | - `int SENSOR_DELAY_UI` - rate suitable for the user interface 81 | 82 | We can also define our own integer value in microseconds, but it's recommended to use predefined values. 83 | 84 | We can customize RxJava Backpressure Strategy for our flowable with method: 85 | 86 | ```java 87 | Flowable observeSensor(final int sensorType, final int samplingPeriodInUs, 88 | final BackpressureStrategy strategy) 89 | ``` 90 | 91 | Default Backpressure Strategy is `BUFFER`. 92 | 93 | Example 94 | ------- 95 | 96 | Exemplary application, which gets readings of various sensors is located in `app` directory of this repository. You can easily change `SENSOR_TYPE` variable to read values from a different sensor in a given samples. 97 | 98 | Good practices 99 | -------------- 100 | 101 | ### Checking whether sensor exists 102 | 103 | We should check whether device has concrete sensor before we start observing it. 104 | 105 | We can do it in the following way: 106 | 107 | ```java 108 | if (reactiveSensors.hasSensor(SENSOR_TYPE)) { 109 | // observe sensor 110 | } else { 111 | // show error message 112 | } 113 | ``` 114 | 115 | ### Letting it crash 116 | 117 | We can let our subscription crash and handle situation when device does not have given sensor e.g. in the `Consumer()` implementation (if we want to return `Disposable`) or in the `onError(throwable)` method implementation of the `Subscriber`. Other types of errors can be handled there as well. 118 | 119 | ```java 120 | new ReactiveSensors(context).observeSensor(Sensor.TYPE_GYROSCOPE) 121 | .subscribeOn(Schedulers.computation()) 122 | .filter(ReactiveSensorEvent::sensorChanged) 123 | .observeOn(AndroidSchedulers.mainThread()) 124 | .subscribe(new Consumer() { 125 | @Override public void accept(ReactiveSensorEvent reactiveSensorEvent) throws Exception { 126 | // handle reactiveSensorEvent 127 | } 128 | }, new Consumer() { 129 | @Override public void accept(Throwable throwable) throws Exception { 130 | if (throwable instanceof SensorNotFoundException) { 131 | textViewForMessage.setText("Sorry, your device doesn't have required sensor."); 132 | } 133 | } 134 | }); 135 | ``` 136 | 137 | ### Subscribing and disposing flowables 138 | 139 | When we are using Disposables in Activity, we should subscribe them in `onResume()` method and dispose them in `onPause()` method. 140 | 141 | ### Filtering stream 142 | 143 | When we want to receive **only sensor updates**, we should use `ReactiveSensorEvent::sensorChanged` method in `filter(...)` method from RxJava. 144 | 145 | When we want to receive **only accuracy updates**, we should use `ReactiveSensorEvent::accuracyChanged` method in `filter(...)` method from RxJava. 146 | 147 | If we don't apply any filter, we will receive both accuracy and sensor readings updates. 148 | 149 | ### Writing tests 150 | 151 | `ReactiveSensors` class implements `SensorsProxy` interface. It allows you to create stubs or mocks for testing behavior of the sensors in your application without need of mocking `SensorManager` class from Android SDK accessing hardware components. Once you instantiate `SensorsProxy`, then you'll be allowed to mock or stub it pretty easily. Moreover, you can mock `ReactiveSensorEvent`, which wraps code from Android API, expose appropriate methods and does not force you to use native code accessing hardware sensors in tests, so you can foucus just on the application logic. 152 | 153 | ### Other practices 154 | 155 | See also [Best Practices for Accessing and Using Sensors](http://developer.android.com/guide/topics/sensors/sensors_overview.html#sensors-practices). 156 | 157 | Download 158 | -------- 159 | 160 | latest version: ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/reactivesensors-rx3.svg?style=flat) 161 | 162 | replace `x.y.z` with the latest version 163 | 164 | You can depend on the library through Maven: 165 | 166 | ```xml 167 | 168 | com.github.pwittchen 169 | reactivesensors-rx3 170 | x.y.z 171 | 172 | ``` 173 | 174 | or through Gradle: 175 | 176 | ```groovy 177 | dependencies { 178 | compile 'com.github.pwittchen:reactivesensors-rx3:x.y.z' 179 | } 180 | ``` 181 | 182 | Tests 183 | ----- 184 | 185 | Tests are available in `library/src/androidTest/java/` directory and can be executed on emulator or Android device from Android Studio or CLI with the following command: 186 | 187 | ``` 188 | ./gradlew connectedCheck 189 | ``` 190 | 191 | Code style 192 | ---------- 193 | 194 | 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. Currently, library doesn't have checkstyle verification attached. It can be done in the future. 195 | 196 | Static code analysis 197 | -------------------- 198 | 199 | Static code analysis runs Checkstyle, FindBugs, PMD and Lint. It can be executed with command: 200 | 201 | ``` 202 | ./gradlew check 203 | ``` 204 | 205 | Reports from analysis are generated in `library/build/reports/` directory. 206 | 207 | Releasing 208 | ---------- 209 | 210 | See [RELEASING.md](https://github.com/pwittchen/ReactiveSensors/blob/RxJava3.x/RELEASING.md) file. 211 | 212 | References 213 | ---------- 214 | - [Sensors Overview](http://developer.android.com/guide/topics/sensors/sensors_overview.html) 215 | - [SensorManager class from Android SDK](http://developer.android.com/reference/android/hardware/SensorManager.html) 216 | 217 | License 218 | ------- 219 | 220 | Copyright 2015 Piotr Wittchen 221 | 222 | Licensed under the Apache License, Version 2.0 (the "License"); 223 | you may not use this file except in compliance with the License. 224 | You may obtain a copy of the License at 225 | 226 | http://www.apache.org/licenses/LICENSE-2.0 227 | 228 | Unless required by applicable law or agreed to in writing, software 229 | distributed under the License is distributed on an "AS IS" BASIS, 230 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 231 | See the License for the specific language governing permissions and 232 | limitations under the License. 233 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | Releasing Guidelines 2 | ==================== 3 | 4 | In order to release new version of the library, we need to perform the following operations: 5 | - create new release issue on GitHub 6 | - prepare release notes and put them to the issue 7 | - verify, commit and push changes to `gh-pages` branch 8 | - checkout to the appropriate branch (`RxJava1.x` or `RxJava2.x` or `RxJava3.x`) 9 | - bump library version (`VERSION_NAME` and `VERSION_CODE`) in `gradle.properties` file 10 | - commit and push the changes 11 | - run command: `./gradlew clean build test check uploadArchives closeAndReleaseRepository` 12 | - wait for the Maven Sync (up to 48 hours) 13 | - when sync is done, checkout to the `RxJava3.x` branch 14 | - update `CHANGELOG.md` file with new release version, current date and release notes 15 | - create new tagged GitHub release with name the same as `VERSION_NAME` from `gradle.properties` and release notes 16 | -------------------------------------------------------------------------------- /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 | applicationId "com.github.pwittchen.reactivesensors" 10 | minSdkVersion rootProject.ext.minSdkVersion 11 | targetSdkVersion rootProject.ext.targetSdkVersion 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 | lintOptions { 24 | abortOnError false 25 | } 26 | 27 | compileOptions { 28 | sourceCompatibility = 1.8 29 | targetCompatibility = 1.8 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation project(':library') 35 | implementation deps.appcompat 36 | } 37 | -------------------------------------------------------------------------------- /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/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 | 5 | 6 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import androidx.appcompat.app.AppCompatActivity; 21 | import com.github.pwittchen.reactivesensors.R; 22 | import com.github.pwittchen.reactivesensors.app.samples.AccelerometerActivity; 23 | import com.github.pwittchen.reactivesensors.app.samples.AmbientTemperatureActivity; 24 | import com.github.pwittchen.reactivesensors.app.samples.GravityActivity; 25 | import com.github.pwittchen.reactivesensors.app.samples.GyroscopeActivity; 26 | import com.github.pwittchen.reactivesensors.app.samples.LightActivity; 27 | import com.github.pwittchen.reactivesensors.app.samples.LinearAccelerationActivity; 28 | import com.github.pwittchen.reactivesensors.app.samples.MagneticFieldActivity; 29 | import com.github.pwittchen.reactivesensors.app.samples.OrientationActivity; 30 | import com.github.pwittchen.reactivesensors.app.samples.PressureActivity; 31 | import com.github.pwittchen.reactivesensors.app.samples.ProximityActivity; 32 | import com.github.pwittchen.reactivesensors.app.samples.RelativeHumidityActivity; 33 | import com.github.pwittchen.reactivesensors.app.samples.RotationVectorActivity; 34 | import com.github.pwittchen.reactivesensors.app.samples.TemperatureActivity; 35 | 36 | public class MainActivity extends AppCompatActivity { 37 | 38 | @Override protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_main); 41 | findViewAndSetOnClickListener(R.id.b_gyroscope, GyroscopeActivity.class); 42 | findViewAndSetOnClickListener(R.id.b_orientation, OrientationActivity.class); 43 | findViewAndSetOnClickListener(R.id.b_accelerometer, AccelerometerActivity.class); 44 | findViewAndSetOnClickListener(R.id.b_ambient_temperature, AmbientTemperatureActivity.class); 45 | findViewAndSetOnClickListener(R.id.b_gravity, GravityActivity.class); 46 | findViewAndSetOnClickListener(R.id.b_light, LightActivity.class); 47 | findViewAndSetOnClickListener(R.id.b_linear_acceleration, LinearAccelerationActivity.class); 48 | findViewAndSetOnClickListener(R.id.b_magnetic_field, MagneticFieldActivity.class); 49 | findViewAndSetOnClickListener(R.id.b_pressure, PressureActivity.class); 50 | findViewAndSetOnClickListener(R.id.b_proximity, ProximityActivity.class); 51 | findViewAndSetOnClickListener(R.id.b_relative_humidity, RelativeHumidityActivity.class); 52 | findViewAndSetOnClickListener(R.id.b_rotation_vector, RotationVectorActivity.class); 53 | findViewAndSetOnClickListener(R.id.b_temperature, TemperatureActivity.class); 54 | } 55 | 56 | private void findViewAndSetOnClickListener(int viewId, final Class cls) { 57 | findViewById(viewId).setOnClickListener(view -> { 58 | Intent intent = new Intent(MainActivity.this, cls); 59 | startActivity(intent); 60 | }); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/SensorActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.pwittchen.reactivesensors.app; 2 | 3 | import android.os.Bundle; 4 | import android.widget.TextView; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import com.github.pwittchen.reactivesensors.R; 7 | import com.github.pwittchen.reactivesensors.library.ReactiveSensors; 8 | import io.reactivex.rxjava3.disposables.Disposable; 9 | 10 | public abstract class SensorActivity extends AppCompatActivity { 11 | protected int sensorType; 12 | protected String sensorName; 13 | 14 | private Disposable subscription; 15 | private SensorHelper sensorHelper; 16 | 17 | @Override protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_sensor_sample); 20 | final TextView tvSensor = (TextView) findViewById(R.id.sensor); 21 | final ReactiveSensors reactiveSensors = new ReactiveSensors(getApplicationContext()); 22 | sensorHelper = new SensorHelper(reactiveSensors, sensorType, sensorName, tvSensor); 23 | } 24 | 25 | @Override protected void onResume() { 26 | super.onResume(); 27 | subscription = sensorHelper.createSubscription(); 28 | } 29 | 30 | @Override protected void onPause() { 31 | super.onPause(); 32 | sensorHelper.safelyDispose(subscription); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/SensorHelper.java: -------------------------------------------------------------------------------- 1 | package com.github.pwittchen.reactivesensors.app; 2 | 3 | import android.widget.TextView; 4 | import com.github.pwittchen.reactivesensors.library.ReactiveSensorEvent; 5 | import com.github.pwittchen.reactivesensors.library.ReactiveSensors; 6 | import com.github.pwittchen.reactivesensors.library.SensorNotFoundException; 7 | import com.github.pwittchen.reactivesensors.library.SensorsProxy; 8 | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; 9 | import io.reactivex.rxjava3.disposables.Disposable; 10 | import io.reactivex.rxjava3.schedulers.Schedulers; 11 | import java.util.Locale; 12 | 13 | class SensorHelper { 14 | private SensorsProxy reactiveSensors; 15 | private int sensorType; 16 | private String sensorName; 17 | private TextView textViewForMessage; 18 | 19 | SensorHelper(ReactiveSensors sensors, int type, String name, TextView textViewForMessage) { 20 | this.reactiveSensors = sensors; 21 | this.sensorType = type; 22 | this.sensorName = name; 23 | this.textViewForMessage = textViewForMessage; 24 | } 25 | 26 | Disposable createSubscription() { 27 | 28 | return reactiveSensors.observeSensor(sensorType) 29 | .subscribeOn(Schedulers.computation()) 30 | .observeOn(AndroidSchedulers.mainThread()) 31 | .filter(ReactiveSensorEvent::sensorChanged) 32 | .subscribe(event -> { 33 | float x = event.sensorValues()[0]; 34 | float y = event.sensorValues()[1]; 35 | float z = event.sensorValues()[2]; 36 | 37 | final String format = "%s readings:\n x = %f\n y = %f\n z = %f"; 38 | String message = String.format(Locale.getDefault(), format, event.sensorName(), x, y, z); 39 | textViewForMessage.setText(message); 40 | }, throwable -> { 41 | if (throwable instanceof SensorNotFoundException) { 42 | textViewForMessage.setText("Sorry, your device doesn't have required sensor."); 43 | } 44 | }); 45 | } 46 | 47 | void safelyDispose(Disposable disposable) { 48 | if (!reactiveSensors.hasSensor(sensorType)) { 49 | return; 50 | } 51 | 52 | if (disposable != null && !disposable.isDisposed()) { 53 | disposable.dispose(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/AccelerometerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class AccelerometerActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_ACCELEROMETER; 25 | sensorName = "accelerometer"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/AmbientTemperatureActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class AmbientTemperatureActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_AMBIENT_TEMPERATURE; 25 | sensorName = "ambient temperature"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/GravityActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class GravityActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_GRAVITY; 25 | sensorName = "gravity"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/GyroscopeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class GyroscopeActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_GYROSCOPE; 25 | sensorName = "gyroscope"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/LightActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class LightActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_LIGHT; 25 | sensorName = "light"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/LinearAccelerationActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class LinearAccelerationActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_LINEAR_ACCELERATION; 25 | sensorName = "linear acceleration"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/MagneticFieldActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class MagneticFieldActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_MAGNETIC_FIELD; 25 | sensorName = "magnetic field"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/OrientationActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class OrientationActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_ORIENTATION; 25 | sensorName = "orientation"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/PressureActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class PressureActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_PRESSURE; 25 | sensorName = "pressure"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/ProximityActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class ProximityActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_PROXIMITY; 25 | sensorName = "proximity"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/RelativeHumidityActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class RelativeHumidityActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_RELATIVE_HUMIDITY; 25 | sensorName = "relative humidity"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/RotationVectorActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class RotationVectorActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_ROTATION_VECTOR; 25 | sensorName = "rotation vector"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/pwittchen/reactivesensors/app/samples/TemperatureActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.reactivesensors.app.samples; 17 | 18 | import android.hardware.Sensor; 19 | import android.os.Bundle; 20 | import com.github.pwittchen.reactivesensors.app.SensorActivity; 21 | 22 | public class TemperatureActivity extends SensorActivity { 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | sensorType = Sensor.TYPE_TEMPERATURE; 25 | sensorName = "temperature"; 26 | super.onCreate(savedInstanceState); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 14 | 15 |