{"id":18784471,"url":"https://github.com/pwittchen/rxbattery","last_synced_at":"2025-04-13T12:33:07.340Z","repository":{"id":57722231,"uuid":"95451576","full_name":"pwittchen/RxBattery","owner":"pwittchen","description":"monitors battery state of the Android device","archived":false,"fork":false,"pushed_at":"2020-08-19T08:52:27.000Z","size":522,"stargazers_count":64,"open_issues_count":1,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-27T03:41:29.960Z","etag":null,"topics":["android","battery","battery-level","battery-monitor","battery-status","broadcast-reciever","java","kotlin","kotlin-android","rxandroid","rxandroid2","rxjava","rxjava2","rxkotlin","rxkotlin-android"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwittchen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["pwittchen"],"custom":["https://paypal.me/pwittchen"]}},"created_at":"2017-06-26T13:53:16.000Z","updated_at":"2024-11-07T13:52:44.000Z","dependencies_parsed_at":"2022-08-29T23:01:13.562Z","dependency_job_id":null,"html_url":"https://github.com/pwittchen/RxBattery","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2FRxBattery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2FRxBattery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2FRxBattery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwittchen%2FRxBattery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwittchen","download_url":"https://codeload.github.com/pwittchen/RxBattery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248714730,"owners_count":21149956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","battery","battery-level","battery-monitor","battery-status","broadcast-reciever","java","kotlin","kotlin-android","rxandroid","rxandroid2","rxjava","rxjava2","rxkotlin","rxkotlin-android"],"created_at":"2024-11-07T20:43:07.790Z","updated_at":"2025-04-13T12:33:06.881Z","avatar_url":"https://github.com/pwittchen.png","language":"Kotlin","funding_links":["https://github.com/sponsors/pwittchen","https://paypal.me/pwittchen"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"logo.png\" alt=\"RxBattery\" height=\"150px\"\u003e\u003c/p\u003e\n\nRxBattery [![Build Status](https://img.shields.io/travis/pwittchen/RxBattery/master.svg?style=flat-square)](https://travis-ci.org/pwittchen/RxBattery)  ![Maven Central](https://img.shields.io/maven-central/v/com.github.pwittchen/rxbattery.svg?style=flat-square)\n=========\nAndroid library monitoring battery state of the device with RxJava and RxKotlin\n\nContents\n--------\n\n- [Usage](#usage)\n- [Examples](#examples)\n- [Download](#download)\n- [Tests](#tests)\n- [Code style](#code-style)\n- [Static code analysis](#static-code-analysis)\n- [JavaDoc](#javadoc)\n- [Changelog](#changelog)\n- [Releasing](#releasing)\n- [References](#references)\n- [Credits](#credits)\n- [License](#license)\n\nUsage\n-----\n\nIn the **Kotlin** application, you can use library as follows:\n\n```kotlin\nRxBattery\n  .observe(context)\n  .subscribeOn(Schedulers.io())\n  .observeOn(AndroidSchedulers.mainThread())\n  .subscribe { textView.text = it.toString() }\n```\n\nIn the **Java** application, you can use library as follows:\n\n```java\nRxBattery\n  .observe(context)\n  .subscribeOn(Schedulers.io())\n  .observeOn(AndroidSchedulers.mainThread())\n  .subscribe(batteryState -\u003e {\n    textView.setText(batteryState.toString());\n  });\n```\n\n`BatteryState` data class looks as follows:\n\n```kotlin\ndata class BatteryState(\n  val statusCode: Int,\n  val pluggedCode: Int,\n  val healthCode: Int,\n  val level: Int,\n  val temperature: Int,\n  val voltage: Int,\n) {\n  fun status(): Status { ... }\n  fun plugged(): Plugged { ... }\n  fun health(): Health { ... }\n}\n```\n\nAll `Integer` values returned by `BatteryState` object are reflected in constants of [`BatteryManager`](https://developer.android.com/reference/android/os/BatteryManager) class from the Android SDK. Enums `Status`, `Plugged` and `Health` represents battery state translated from integer codes from `BatteryManager` class.\n\nExamples\n--------\n\nExemplary Kotlin application is located in `app-kotlin` directory.\n\nDownload\n--------\n\nYou can depend on the library through Gradle:\n\n```groovy\ndependencies {\n  implementation 'com.github.pwittchen:rxbattery:0.1.0'\n}\n```\n\nTests\n-----\n\nTests 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:\n\n```\n./gradlew test\n```\n\nCode style\n----------\n\nCode style used in the project is called `SquareAndroid` from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.\n\nStatic code analysis\n--------------------\n\nStatic code analysis runs Checkstyle, FindBugs, PMD, Lint, KtLint and Detekt. It can be executed with command:\n\n```\n./gradlew check\n```\n\nReports from analysis are generated in `library/build/reports/` directory.\n\nJavaDoc\n-------\n\nDocumentation can be generated as follows:\n\n```\n./gradlew dokka\n```\n\nOutput will be generated in `library/build/javadoc`\n\nJavaDoc can be viewed on-line at https://pwittchen.github.io/RxBattery/library/\n\nChangelog\n---------\n\nSee [CHANGELOG.md](https://github.com/pwittchen/RxBattery/blob/master/CHANGELOG.md) file.\n\nReleasing\n---------\n\nSee [RELEASING.md](https://github.com/pwittchen/RxBattery/blob/master/RELEASING.md) file.\n\nReferences\n----------\n- https://developer.android.com/training/monitoring-device-state/index.html\n- https://developer.android.com/training/monitoring-device-state/battery-monitoring.html\n- https://developer.android.com/reference/android/os/BatteryManager\n- https://developer.android.com/studio/profile/battery-historian.html\n- https://stackoverflow.com/questions/3291655/get-battery-level-and-state-in-android\n- https://stackoverflow.com/questions/25932677/proper-optimized-way-to-monitor-battery-level-in-android\n- https://stackoverflow.com/questions/32608505/broadcast-receiver-monitoring-the-battery-level-and-charging-state\n- https://github.com/jaredsburrows/android-gradle-kotlin-app-template\n- http://wittchen.io/2018/08/19/writing-my-first-library-in-kotlin/\n\nCredits\n-------\n\nLogo of the project was created by [@Yasujizr](https://github.com/Yasujizr).\n\nLicense\n-------\n\n    Copyright 2018 Piotr Wittchen\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwittchen%2Frxbattery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwittchen%2Frxbattery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwittchen%2Frxbattery/lists"}