Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ca.foundrybc.foundryapp.presentation.util.extension
- import android.app.Activity
- import android.graphics.Rect
- import android.view.View
- import android.view.ViewGroup
- import android.view.Window
- import androidx.annotation.StringRes
- import com.google.android.material.snackbar.Snackbar
- fun Activity.showBottomSnackBar(@StringRes message: Int) {
- val view: View = findViewById(android.R.id.content)
- Snackbar.make(view, message, Snackbar.LENGTH_LONG)
- .show()
- }
- fun Activity.getRootView(): View = this.findViewById(Window.ID_ANDROID_CONTENT)
- fun Activity.getRootViewGroup(): ViewGroup = getRootView() as ViewGroup
- fun Activity.getViewBindingView(): View = getRootViewGroup().getChildAt(0)
- private const val KEYBOARD_MIN_HEIGHT_RATIO = 0.15
- fun Activity.isKeyboardOpen(): Boolean {
- val contentRoot = getRootViewGroup()
- val activityRoot = contentRoot.getChildAt(0)
- val rect = Rect()
- activityRoot.getWindowVisibleDisplayFrame(rect)
- val location = IntArray(2)
- contentRoot.getLocationOnScreen(location)
- val screenHeight = activityRoot.rootView.height
- val heightDiff = screenHeight - rect.height() - location[1]
- return heightDiff > screenHeight * KEYBOARD_MIN_HEIGHT_RATIO
- }
- fun Activity.isKeyboardClosed(): Boolean {
- return !this.isKeyboardOpen()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement