rxbattery

Android library monitoring battery of the device with RxJava and RxKotlin

License

License

GroupId

GroupId

com.github.pwittchen
ArtifactId

ArtifactId

rxbattery
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

rxbattery
Android library monitoring battery of the device with RxJava and RxKotlin
Project URL

Project URL

https://github.com/pwittchen/RxBattery
Source Code Management

Source Code Management

https://github.com/pwittchen/RxBattery

Download rxbattery

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.pwittchen/rxbattery/ -->
<dependency>
    <groupId>com.github.pwittchen</groupId>
    <artifactId>rxbattery</artifactId>
    <version>0.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.pwittchen/rxbattery/
implementation 'com.github.pwittchen:rxbattery:0.1.0'
// https://jarcasting.com/artifacts/com.github.pwittchen/rxbattery/
implementation ("com.github.pwittchen:rxbattery:0.1.0")
'com.github.pwittchen:rxbattery:aar:0.1.0'
<dependency org="com.github.pwittchen" name="rxbattery" rev="0.1.0">
  <artifact name="rxbattery" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.pwittchen', module='rxbattery', version='0.1.0')
)
libraryDependencies += "com.github.pwittchen" % "rxbattery" % "0.1.0"
[com.github.pwittchen/rxbattery "0.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
io.reactivex.rxjava2 : rxjava jar 2.2.0
io.reactivex.rxjava2 : rxandroid jar 2.0.2
io.reactivex.rxjava2 : rxkotlin jar 2.3.0
com.android.support » support-annotations jar 28.0.0-rc01

Project Modules

There are no modules declared in this project.

RxBattery

RxBattery Build Status Maven Central

Android library monitoring battery state of the device with RxJava and RxKotlin

Contents

Usage

In the Kotlin application, you can use library as follows:

RxBattery
  .observe(context)
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe { textView.text = it.toString() }

In the Java 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 class BatteryState(
  val statusCode: Int,
  val pluggedCode: Int,
  val healthCode: Int,
  val level: Int,
  val temperature: Int,
  val voltage: Int,
) {
  fun status(): Status { ... }
  fun plugged(): Plugged { ... }
  fun health(): Health { ... }
}

All Integer values returned by BatteryState object are reflected in constants of BatteryManager class from the Android SDK. Enums Status, Plugged and Health represents battery state translated from integer codes from BatteryManager class.

Examples

Exemplary Kotlin application is located in app-kotlin directory.

Download

You can depend on the library through Gradle:

dependencies {
  implementation 'com.github.pwittchen:rxbattery:0.1.0'
}

Tests

Tests are available in library/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

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

Static code analysis

Static code analysis runs Checkstyle, FindBugs, PMD, Lint, KtLint and Detekt. It can be executed with command:

./gradlew check

Reports from analysis are generated in library/build/reports/ directory.

JavaDoc

Documentation can be generated as follows:

./gradlew dokka

Output will be generated in library/build/javadoc

JavaDoc can be viewed on-line at https://pwittchen.github.io/RxBattery/library/

Changelog

See CHANGELOG.md file.

Releasing

See RELEASING.md file.

References

Credits

Logo of the project was created by @Yasujizr.

License

Copyright 2018 Piotr Wittchen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
0.1.0
0.0.1