diff --git a/README.md b/README.md index 5be8d0b..d76d93e 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,29 @@ # LiveBattery +![Android](https://img.shields.io/badge/platform-Android-brightgreen.svg) +![Apache](https://img.shields.io/github/license/samelody/livebattery.svg) +![API](https://img.shields.io/badge/API-15%2B-brightgreen.svg) +[![Bintray](https://api.bintray.com/packages/belinwu/maven/livebattery/images/download.svg)](https://bintray.com/belinwu/maven/livebattery/_latestVersion) + A LiveData for monitoring Android battery. **DO NOT USE THIS LIBRARY IN PRODUCTION UNTIL V1.0.0 IS RELEASED.** -# Download +# Installation + +Add the following dependency to your `build.gradle` file: -Coming soon... +```groovy +dependencies { + implementation 'com.samelody.livebattery:livebattery:0.1.0' +} +``` -# Getting started +# Usage In your Activity/Fragment/Service, create and observe a BatteryLiveData. -## in Java +## Java ```java liveBattery = new BatteryLiveData(this); @@ -24,7 +35,7 @@ liveBattery.observe(this, new Observer() { }); ``` -## in Kotlin +## Kotlin ```kotlin liveBattery = BatteryLiveData(this) @@ -33,7 +44,9 @@ liveBattery.observe(this, Observer { }) ``` -# BatteryInfo +# Docs + +## BatteryInfo BatteryInfo is the data in a BatteryLiveData, it has following properties: @@ -62,7 +75,11 @@ private int voltage; Get the remaining battery percent using `BatteryInfo#getPercent()` method. -# Inspired by +# Dependencies + +`androidx.lifecycle:lifecycle-livedata-core:2.0.0` + +# Thanks [RxBattery](https://github.com/pwittchen/RxBattery) diff --git a/sample/build.gradle b/sample/build.gradle index 33feb67..0b159b0 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -24,6 +24,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation deps.kotlin_stdlib implementation project(':library') +// implementation "com.samelody.livebattery:livebattery:0.1.0" implementation deps.appcompat implementation deps.constraintlayout diff --git a/sample/src/main/java/com/samelody/samples/livebattery/MainActivity.kt b/sample/src/main/java/com/samelody/samples/livebattery/MainActivity.kt index bb92190..68628b3 100644 --- a/sample/src/main/java/com/samelody/samples/livebattery/MainActivity.kt +++ b/sample/src/main/java/com/samelody/samples/livebattery/MainActivity.kt @@ -4,6 +4,7 @@ import android.os.* import androidx.appcompat.app.* import androidx.lifecycle.* import com.samelody.livebattery.* +import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { @@ -15,7 +16,7 @@ class MainActivity : AppCompatActivity() { liveBattery = BatteryLiveData(this) liveBattery.observe(this, Observer { - println(it) + info.text = it.toString() }) } } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index b093aa0..16a37c4 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -8,6 +8,7 @@ tools:context=".MainActivity">