Skip to content

Commit 709d48e

Browse files
authored
Merge pull request #57 from anoop44/statusbar-height-better-api
Statusbar height calculation using a better api
2 parents 023a3ce + f97fe81 commit 709d48e

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

keyboardvisibilityevent/src/main/java/net/yslibrary/android/keyboardvisibilityevent/KeyboardVisibilityEvent.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,11 @@ object KeyboardVisibilityEvent {
100100

101101
val layoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
102102

103-
private val r = Rect()
104-
105103
private var wasOpened = false
106104

107105
override fun onGlobalLayout() {
108-
activityRoot.getWindowVisibleDisplayFrame(r)
109-
110-
val screenHeight = activityRoot.rootView.height
111-
val heightDiff = screenHeight - r.height()
112106

113-
val isOpen = heightDiff > screenHeight * KEYBOARD_MIN_HEIGHT_RATIO
107+
val isOpen = isKeyboardVisible(activity)
114108

115109
if (isOpen == wasOpened) {
116110
// keyboard state has not changed
@@ -140,8 +134,11 @@ object KeyboardVisibilityEvent {
140134

141135
activityRoot.getWindowVisibleDisplayFrame(r)
142136

137+
val location = IntArray(2)
138+
getContentRoot(activity).getLocationOnScreen(location)
139+
143140
val screenHeight = activityRoot.rootView.height
144-
val heightDiff = screenHeight - r.height() - getContentRoot(activity).top
141+
val heightDiff = screenHeight - r.height() - location[1]
145142

146143
return heightDiff > screenHeight * KEYBOARD_MIN_HEIGHT_RATIO
147144
}

0 commit comments

Comments
 (0)