Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions recipes/android/src/android/_android.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,33 @@ cdef extern void android_show_keyboard(int)
cdef extern void android_hide_keyboard()


from jnius import autoclass
from jnius import autoclass, PythonJavaClass, java_method

# API versions
api_version = autoclass('android.os.Build$VERSION').SDK_INT
version_codes = autoclass('android.os.Build$VERSION_CODES')


python_act = autoclass('org.renpy.android.PythonActivity')
rctx = autoclass('android.graphics.Rect')()
Rect = autoclass('android.graphics.Rect')
mActivity = python_act.mActivity
if mActivity:
decor_view = mActivity.getWindow().getDecorView()
default_display = mActivity.getWindowManager().getDefaultDisplay()
# get keyboard height
class LayoutListener(PythonJavaClass):
__javainterfaces__ = ['android/view/ViewTreeObserver$OnGlobalLayoutListener']

height = 0

@java_method('()V')
def onGlobalLayout(self):
rctx = Rect()
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rctx)
self.height = mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top)

ll = LayoutListener()
python_act.mView.getViewTreeObserver().addOnGlobalLayoutListener(ll)

def get_keyboard_height():
height = default_display.getHeight()
decor_view.getWindowVisibleDisplayFrame(rctx)
return height - rctx.bottom
return ll.height
else:
def get_keyboard_height():
return 0
Expand Down