- Notifications
You must be signed in to change notification settings - Fork10
monitors battery state of the Android device
License
pwittchen/RxBattery
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Android library monitoring battery state of the device with RxJava and RxKotlin
- Usage
- Examples
- Download
- Tests
- Code style
- Static code analysis
- JavaDoc
- Changelog
- Releasing
- References
- Credits
- License
In theKotlin application, you can use library as follows:
RxBattery .observe(context) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe { textView.text= it.toString() }
In theJava application, you can use library as follows:
RxBattery .observe(context) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(batteryState -> {textView.setText(batteryState.toString()); });
BatteryState
data class looks as follows:
data classBatteryState(valstatusCode:Int,valpluggedCode:Int,valhealthCode:Int,vallevel:Int,valtemperature:Int,valvoltage:Int,) {funstatus():Status {... }funplugged():Plugged {... }funhealth():Health {... }}
AllInteger
values returned byBatteryState
object are reflected in constants ofBatteryManager
class from the Android SDK. EnumsStatus
,Plugged
andHealth
represents battery state translated from integer codes fromBatteryManager
class.
Exemplary Kotlin application is located inapp-kotlin
directory.
You can depend on the library through Gradle:
dependencies { implementation'com.github.pwittchen:rxbattery:0.1.0'}
Tests are available inlibrary/src/test/kotlin/
directory and can be executed on JVM without any emulator or Android device from Android Studio or CLI with the following command:
./gradlew test
Code style used in the project is calledSquareAndroid
from Java Code Styles repository by Square available at:https://github.com/square/java-code-styles.
Static code analysis runs Checkstyle, FindBugs, PMD, Lint, KtLint and Detekt. It can be executed with command:
./gradlew check
Reports from analysis are generated inlibrary/build/reports/
directory.
Documentation can be generated as follows:
./gradlew dokka
Output will be generated inlibrary/build/javadoc
JavaDoc can be viewed on-line athttps://pwittchen.github.io/RxBattery/library/
SeeCHANGELOG.md file.
SeeRELEASING.md file.
- https://developer.android.com/training/monitoring-device-state/index.html
- https://developer.android.com/training/monitoring-device-state/battery-monitoring.html
- https://developer.android.com/reference/android/os/BatteryManager
- https://developer.android.com/studio/profile/battery-historian.html
- https://stackoverflow.com/questions/3291655/get-battery-level-and-state-in-android
- https://stackoverflow.com/questions/25932677/proper-optimized-way-to-monitor-battery-level-in-android
- https://stackoverflow.com/questions/32608505/broadcast-receiver-monitoring-the-battery-level-and-charging-state
- https://github.com/jaredsburrows/android-gradle-kotlin-app-template
- http://wittchen.io/2018/08/19/writing-my-first-library-in-kotlin/
Logo of the project was created by@Yasujizr.
Copyright 2018 Piotr WittchenLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
About
monitors battery state of the Android device