Skip to content

Commit

Permalink
Release initial public version: v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
belinwu committed Jan 23, 2019
1 parent 6421698 commit 5cd7045
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -24,7 +35,7 @@ liveBattery.observe(this, new Observer<BatteryInfo>() {
});
```

## in Kotlin
## Kotlin

```kotlin
liveBattery = BatteryLiveData(this)
Expand All @@ -33,7 +44,9 @@ liveBattery.observe(this, Observer {
})
```

# BatteryInfo
# Docs

## BatteryInfo

BatteryInfo is the data in a BatteryLiveData, it has following properties:

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -15,7 +16,7 @@ class MainActivity : AppCompatActivity() {

liveBattery = BatteryLiveData(this)
liveBattery.observe(this, Observer {
println(it)
info.text = it.toString()
})
}
}
1 change: 1 addition & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context=".MainActivity">

<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
Expand Down

0 comments on commit 5cd7045

Please sign in to comment.