KeyboardHeightProvider


Source link: https://github.com/Crysis21/KeyboardHeightProvider

Keyboard Height Provider

Getting keyboard height in android it's a pain in the ass. For activities where soft input mode is adjustResize, you can set up an OnGlobalLayoutListener and measure how the activity window is resized, to make room for the keyboard.

For other modes of soft input mode, you're out of luck. As the android brick-heads refuse to solve this problem even after 28 iterations of SDK development, someone came with a cool solution:

  • create a pop-up window and observe it's global layout changes
  • set it's soft input behaviour as adjustResize
  • attach this popup window to your activity and let it report the keyboard height, based on it's layout changes.

Set up

Add the following repo to your project

 repositories {

maven {

 url  "https://dl.bintray.com/crysis21/Android"

}

  
}

Add the following dependency to your project:

 implementation 'com.hold1:keyboardheightprovider:0.0.5'

Usage

  1. Keep a reference to KeyboardHeightProvider in your activity.
 private var keyboardHeightProvider: KeyboardHeightProvider? = null
  1. Create a KeyboardListener
 private fun getKeyboardListener() = object : KeyboardHeightProvider.KeyboardListener {

override fun onHeightChanged(height: Int) {

 sizeText.text = "$height"

}

  
}
  1. Create the height provider after your activity has been created

  keyboardHeightProvider = KeyboardHeightProvider(this)

baseView.post {

 keyboardHeightProvider?.start()

}
  1. Register for keyboard changes

  keyboardHeightProvider?.addKeyboardListener(getKeyboardListener())
  1. Clean up :)
 public override fun onDestroy() {

super.onDestroy()

keyboardHeightProvider?.close()
  
}

Also the KeyboardInfo object provides information about the current state of the keyboard, and it's cached height.

Credits

All credits for this project goes to Siebe Brouwer. He had a great idea of using an android PopupWindow in order to extract the keyboard height in activities where you don't want to use the adjustResize behaviour.

Resources

An extension to the Snackbar view available at the Android Design Support Library.

Restaurant wraps the Snackbar implementation to easily allow more customization. With Restaurant you can change the text and background color of the Snackbar just calling a method. Restaurant can also detect the correct view to attach the Snackbar just receiving the activity.

This project aims to provide an ultimate and flexible image cropping experience.

Be sure that your user is awake before disturbing it with soundy and vibrant notifications!

Before this library, QuitNow! and lots of apps were sending notifications when the user was sleeping... and HEY! That makes people angry.

Tiny and nice injections syntax sugar for Android. If you're using heavy injection frameworks just to inject views and resources try this.

A simple library for locking and unlocking Activities (e.g. child lock) with a PIN code.

Compress a signed apk without destroy its original signature.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes