File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed
recipes/android/src/android Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -171,24 +171,33 @@ cdef extern void android_show_keyboard(int)
171171cdef extern void android_hide_keyboard()
172172
173173
174- from jnius import autoclass
174+ from jnius import autoclass, PythonJavaClass, java_method
175175
176176# API versions
177177api_version = autoclass(' android.os.Build$VERSION' ).SDK_INT
178178version_codes = autoclass(' android.os.Build$VERSION_CODES' )
179179
180180
181181python_act = autoclass(' org.renpy.android.PythonActivity' )
182- rctx = autoclass(' android.graphics.Rect' )( )
182+ Rect = autoclass(' android.graphics.Rect' )
183183mActivity = python_act.mActivity
184184if mActivity:
185- decor_view = mActivity.getWindow().getDecorView()
186- default_display = mActivity.getWindowManager().getDefaultDisplay()
187- # get keyboard height
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)
198+
188199 def get_keyboard_height ():
189- height = default_display.getHeight()
190- decor_view.getWindowVisibleDisplayFrame(rctx)
191- return height - rctx.bottom
200+ return ll.height
192201else :
193202 def get_keyboard_height ():
194203 return 0
You can’t perform that action at this time.
0 commit comments