File tree 1 file changed +17
-8
lines changed
recipes/android/src/android
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)
171
171
cdef extern void android_hide_keyboard()
172
172
173
173
174
- from jnius import autoclass
174
+ from jnius import autoclass, PythonJavaClass, java_method
175
175
176
176
# API versions
177
177
api_version = autoclass(' android.os.Build$VERSION' ).SDK_INT
178
178
version_codes = autoclass(' android.os.Build$VERSION_CODES' )
179
179
180
180
181
181
python_act = autoclass(' org.renpy.android.PythonActivity' )
182
- rctx = autoclass(' android.graphics.Rect' )( )
182
+ Rect = autoclass(' android.graphics.Rect' )
183
183
mActivity = python_act.mActivity
184
184
if 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
+
188
199
def get_keyboard_height ():
189
- height = default_display.getHeight()
190
- decor_view.getWindowVisibleDisplayFrame(rctx)
191
- return height - rctx.bottom
200
+ return ll.height
192
201
else :
193
202
def get_keyboard_height ():
194
203
return 0
You can’t perform that action at this time.
0 commit comments