Commit 47d87d39 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add KeyboardHelper.kt

parent 8fe4332c
package chat.rocket.android.app
import android.content.res.Configuration
import android.graphics.Rect
import android.view.View
/**
* @author Filipe de Lima Brito (filipedelimabrito@gmail.com)
*/
object KeyboardHelper {
/**
* Returns true if the soft keyboard is shown, false otherwise.
*
* @param rootView The rootView of a view (e.g. an EditText).
* @return true if the soft keyboard is shown, false otherwise.
*/
fun isSoftKeyboardShown(rootView: View): Boolean {
val softKeyboardHeight = 100
val rect = Rect()
rootView.getWindowVisibleDisplayFrame(rect)
val dm = rootView.resources.displayMetrics
val heightDiff = rootView.bottom - rect.bottom
return heightDiff > softKeyboardHeight * dm.density
}
/**
* Returns true if the hard keyboard is shown, false otherwise.
*
* @param newConfig The configuration.
* @return true if the hard keyboard is shown, false otherwise.
*/
fun isHardKeyboardShown(newConfig: Configuration?): Boolean {
if (newConfig?.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) return true
return false
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment