Skip to content

Commit

Permalink
Added README
Browse files Browse the repository at this point in the history
  • Loading branch information
konifar committed Apr 6, 2018
1 parent 8768bca commit 73fac76
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 6 deletions.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Rx Keyboard Detector

[![Build Status](https://circleci.com/gh/Kyash/rx-keyboard-detector.svg?style=shield)](https://circleci.com/gh/Kyash/rx-keyboard-detector/tree/master)
[![JitPack](https://jitpack.io/v/Kyash/rx-keyboard-detector.svg)](https://jitpack.io/#Kyash/rx-keyboard-detector)

Simple Android library to detect Keyboard `opened`/`closed` status by using RxJava2.

![demo.gif](art/demo.gif)

## Download

### Project build.gradle

```groovy
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```

### App build.gradle

```groovy
dependencies {
...
compile 'com.github.Kyash:rx-keyboard-detector:LATEST_VERSION'
}
```

`LATEST_VERSION` is [![JitPack](https://jitpack.io/v/Kyash/rx-keyboard-detector.svg)](https://jitpack.io/#Kyash/rx-keyboard-detector)

## Usage
Super simple. Check example [MainActivity.kt](https://github.com/Kyash/rx-keyboard-detector/blob/master/example/src/main/java/co/kyash/rxkeyboarddetector/MainActivity.kt)

```kotlin
KeyboardDetector(this).observe().subscribe({ status ->
when(status) {
KeyboardStatus.OPENED -> {}
KeyboardStatus.CLOSED -> {}
}
})
```

## Dependencies
This library depends on RxJava2 and Kotlin

## Thanks
This library is inspired from these awesome code. Thank you so much!
- https://github.com/yshrsmz/KeyboardVisibilityEvent
- https://gist.github.com/andrewmunn/af4c15210dd376f69990eca672d2d0e7#file-keyboardmanager-kt

## Contributing
We are always welcome your contribution!
If you find a bug or want to add new feature, please raise issue.

## License

```
Copyright 2018 Kyash
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.
```
Binary file added art/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 24 additions & 3 deletions example/src/main/java/co/kyash/rxkeyboarddetector/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,38 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import co.kyash.rkd.KeyboardDetector
import co.kyash.rkd.KeyboardStatus
import io.reactivex.disposables.CompositeDisposable

class MainActivity : AppCompatActivity() {

private val compositeDisposable = CompositeDisposable()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val textView = findViewById<TextView>(R.id.status)

KeyboardDetector(this).observe().subscribe({
textView.text = it.name
})
compositeDisposable.add(
KeyboardDetector(this).observe().subscribe({ status ->
when (status) {
KeyboardStatus.OPENED -> {
textView.text = getString(R.string.opened)
}
KeyboardStatus.CLOSED -> {
textView.text = getString(R.string.closed)
}
else -> {
//
}
}
})
)
}

override fun onDestroy() {
compositeDisposable.clear()
super.onDestroy()
}
}
5 changes: 3 additions & 2 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:background="@color/theme"
android:elevation="4dp"
app:elevation="4dp"
app:title="@string/app_name" />
app:title="@string/app_name"
app:titleTextColor="@color/white" />

<ScrollView
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions example/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">RxKeyboardDetector</string>
<string name="opened">Opened</string>
<string name="closed">Closed</string>
</resources>
1 change: 0 additions & 1 deletion library/src/main/java/co/kyash/rkd/KeyboardDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.view.ViewTreeObserver
import android.view.WindowManager
import io.reactivex.Observable


class KeyboardDetector constructor(
private val activity: Activity?
) {
Expand Down

0 comments on commit 73fac76

Please sign in to comment.