Skip to content

Commit 43f7f55

Browse files
committed
Fix Crash while rotating., pausing/resuming the app
1 parent 7c8d4ce commit 43f7f55

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

recipes/android/src/android/_android.pyx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,15 @@ python_act = autoclass('org.renpy.android.PythonActivity')
182182
Rect = autoclass('android.graphics.Rect')
183183
mActivity = python_act.mActivity
184184
if mActivity:
185-
class LayoutListener(PythonJavaClass):
186-
__javainterfaces__ = ['android/view/ViewTreeObserver$OnGlobalLayoutListener']
187-
188-
height = 0
189-
190-
@java_method('()V')
191-
def onGlobalLayout(self):
192-
rctx = Rect()
193-
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rctx)
194-
self.height = mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top)
195-
196-
ll = LayoutListener()
197-
python_act.mView.getViewTreeObserver().addOnGlobalLayoutListener(ll)
185+
# do not add a listener here, one is already implemented in the Hardware.java
186+
# that sends a event to kivy which makes a call to `get_keyboard_height`.
187+
decorview = mActivity.getWindow().getDecorView()
188+
default_display = mActivity.getWindowManager().getDefaultDisplay()
198189

199190
def get_keyboard_height():
200-
return ll.height
191+
rctx = Rect()
192+
decorview.getWindowVisibleDisplayFrame(rctx)
193+
return default_display.getHeight() - (rctx.bottom - rctx.top)
201194
else:
202195
def get_keyboard_height():
203196
return 0

0 commit comments

Comments
 (0)