diff --git a/README.md b/README.md new file mode 100644 index 0000000..d733291 --- /dev/null +++ b/README.md @@ -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. +``` diff --git a/art/demo.gif b/art/demo.gif new file mode 100644 index 0000000..eb6657b Binary files /dev/null and b/art/demo.gif differ diff --git a/example/src/main/java/co/kyash/rxkeyboarddetector/MainActivity.kt b/example/src/main/java/co/kyash/rxkeyboarddetector/MainActivity.kt index d69cf6e..7478f3b 100644 --- a/example/src/main/java/co/kyash/rxkeyboarddetector/MainActivity.kt +++ b/example/src/main/java/co/kyash/rxkeyboarddetector/MainActivity.kt @@ -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(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() } } diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index e58ddfd..2d93d20 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -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" /> RxKeyboardDetector + Opened + Closed diff --git a/library/src/main/java/co/kyash/rkd/KeyboardDetector.kt b/library/src/main/java/co/kyash/rkd/KeyboardDetector.kt index 4efd169..ab15f98 100644 --- a/library/src/main/java/co/kyash/rkd/KeyboardDetector.kt +++ b/library/src/main/java/co/kyash/rkd/KeyboardDetector.kt @@ -10,7 +10,6 @@ import android.view.ViewTreeObserver import android.view.WindowManager import io.reactivex.Observable - class KeyboardDetector constructor( private val activity: Activity? ) {