From b1ba8dc3b3510188de52dd6186bc7c547dbf8a01 Mon Sep 17 00:00:00 2001 From: qua-non Date: Wed, 12 Feb 2014 08:56:22 +0530 Subject: [PATCH 1/2] Introduce method `get_keyboard_height` that returns current softkeyboard height if keyboard is active else 0. --- recipes/android/src/android/_android.pyx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/recipes/android/src/android/_android.pyx b/recipes/android/src/android/_android.pyx index 20973efb89..8cc2e6d8ae 100644 --- a/recipes/android/src/android/_android.pyx +++ b/recipes/android/src/android/_android.pyx @@ -170,6 +170,18 @@ def get_dpi(): cdef extern void android_show_keyboard(int) cdef extern void android_hide_keyboard() +# get keyboard height +def get_keyboard_height(): + from jnius import autoclass + python_act = autoclass('org.renpy.android.PythonActivity') + rctx = autoclass('android.graphics.Rect')() + mActivity = python_act.mActivity + mActivity.getWindow().getDecorView().\ + getWindowVisibleDisplayFrame(rctx) + height = mActivity.getWindowManager().getDefaultDisplay().getHeight() + return height - rctx.bottom + + # Flags for input_type, for requesting a particular type of keyboard #android FLAGS TYPE_CLASS_DATETIME = 4 From df55cf7f6b2b07dfba4633a7c3c4cd83eed502c6 Mon Sep 17 00:00:00 2001 From: qua-non Date: Wed, 26 Feb 2014 23:32:00 +0530 Subject: [PATCH 2/2] Listen to chnages in the gloabal layout for figuring out when the IME is activated. --- src/src/org/renpy/android/SDLSurfaceView.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/src/org/renpy/android/SDLSurfaceView.java b/src/src/org/renpy/android/SDLSurfaceView.java index 059006a3fe..9f8174be94 100644 --- a/src/src/org/renpy/android/SDLSurfaceView.java +++ b/src/src/org/renpy/android/SDLSurfaceView.java @@ -1132,7 +1132,6 @@ public void run(){ public void dispatchCommand(String message){ - Boolean ret = false; int delay = 0; while (message.length() > 50){ delayed_message(message.substring(0, 50), delay); @@ -1146,7 +1145,7 @@ public void dispatchCommand(String message){ if (DEBUG) Log.d(TAG, String.format("dispatch :%s", message)); int keyCode = 45; - //send control sequence start \x01 + //send control sequence start nativeKey(keyCode, 1, 1); nativeKey(keyCode, 0, 1); @@ -1156,7 +1155,7 @@ public void dispatchCommand(String message){ nativeKey(keyCode, 0, (int) message.charAt(i)); } - //send control sequence start \x01 + //send control sequence end \x02 nativeKey(keyCode, 1, 2); nativeKey(keyCode, 0, 2); @@ -1164,10 +1163,20 @@ public void dispatchCommand(String message){ @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { - // setting inputtype to TYPE_CLASS_TEXT is necessary for swiftkey to enable outAttrs.inputType = inputType; // ask IME to avoid taking full screen on landscape mode outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; + + // add a listener for the layout chnages to the IME view + final android.view.View activityRootView = mActivity.getWindow().getDecorView(); + activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + //send control sequence start /x04 == kayboard layout changed + nativeKey(45, 1, 4); + nativeKey(45, 0, 4); + } + }); return new BaseInputConnection(this, false){ private void deleteLastText(){