Skip to content

Commit e4cf131

Browse files
authored
Merge pull request kivy#911 from kivy/keyboard_height
fix layout listener related issues. Closes kivy#890
2 parents 5ce57ca + f48feec commit e4cf131

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

pythonforandroid/recipes/android/src/android/_android.pyx

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,18 @@ python_act = autoclass(JAVA_NAMESPACE + '.PythonActivity')
179179
Rect = autoclass('android.graphics.Rect')
180180
mActivity = python_act.mActivity
181181
if mActivity:
182-
class LayoutListener(PythonJavaClass):
183-
__javainterfaces__ = ['android/view/ViewTreeObserver$OnGlobalLayoutListener']
184-
185-
height = 0
186-
187-
@java_method('()V')
188-
def onGlobalLayout(self):
189-
rctx = Rect()
190-
# print('rctx_bottom: {0}, top: {1}'.format(rctx.bottom, rctx.top))
191-
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rctx)
192-
# print('rctx_bottom: {0}, top: {1}'.format(rctx.bottom, rctx.top))
193-
# print('activity height: {0}'.format(mActivity.getWindowManager().getDefaultDisplay().getHeight()))
194-
# NOTE top should always be zero
195-
rctx.top = 0
196-
self.height = mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top)
197-
# print('final height: {0}'.format(self.height))
198-
199-
ll = LayoutListener()
200-
IF BOOTSTRAP == 'sdl2':
201-
python_act.getLayout().getViewTreeObserver().addOnGlobalLayoutListener(ll)
202-
ELSE:
203-
python_act.mView.getViewTreeObserver().addOnGlobalLayoutListener(ll)
204-
182+
# PyGame backend already has the listener so adding
183+
# one here leads to a crash/too much cpu usage.
184+
# SDL2 now does noe need the listener so there is
185+
# no point adding a processor intensive layout listenere here.
186+
height = 0
205187
def get_keyboard_height():
206-
return ll.height
188+
rctx = Rect()
189+
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rctx)
190+
# NOTE top should always be zero
191+
rctx.top = 0
192+
height = mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top)
193+
return height
207194
else:
208195
def get_keyboard_height():
209196
return 0

0 commit comments

Comments
 (0)