Skip to content

Commit 1b55914

Browse files
committed
Merge pull request kivy#205 from kivy/keyboard_height
Introduce method `get_keyboard_height` that returns current softkeyboard
2 parents ce48650 + df55cf7 commit 1b55914

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

recipes/android/src/android/_android.pyx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ def get_dpi():
170170
cdef extern void android_show_keyboard(int)
171171
cdef extern void android_hide_keyboard()
172172

173+
# get keyboard height
174+
def get_keyboard_height():
175+
from jnius import autoclass
176+
python_act = autoclass('org.renpy.android.PythonActivity')
177+
rctx = autoclass('android.graphics.Rect')()
178+
mActivity = python_act.mActivity
179+
mActivity.getWindow().getDecorView().\
180+
getWindowVisibleDisplayFrame(rctx)
181+
height = mActivity.getWindowManager().getDefaultDisplay().getHeight()
182+
return height - rctx.bottom
183+
184+
173185
# Flags for input_type, for requesting a particular type of keyboard
174186
#android FLAGS
175187
TYPE_CLASS_DATETIME = 4

src/src/org/renpy/android/SDLSurfaceView.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ public void run(){
11331133

11341134
public void dispatchCommand(String message){
11351135

1136-
Boolean ret = false;
11371136
int delay = 0;
11381137
while (message.length() > 50){
11391138
delayed_message(message.substring(0, 50), delay);
@@ -1147,7 +1146,7 @@ public void dispatchCommand(String message){
11471146

11481147
if (DEBUG) Log.d(TAG, String.format("dispatch :%s", message));
11491148
int keyCode = 45;
1150-
//send control sequence start \x01
1149+
//send control sequence start
11511150
nativeKey(keyCode, 1, 1);
11521151
nativeKey(keyCode, 0, 1);
11531152

@@ -1157,18 +1156,28 @@ public void dispatchCommand(String message){
11571156
nativeKey(keyCode, 0, (int) message.charAt(i));
11581157
}
11591158

1160-
//send control sequence start \x01
1159+
//send control sequence end \x02
11611160
nativeKey(keyCode, 1, 2);
11621161
nativeKey(keyCode, 0, 2);
11631162

11641163
}
11651164

11661165
@Override
11671166
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
1168-
// setting inputtype to TYPE_CLASS_TEXT is necessary for swiftkey to enable
11691167
outAttrs.inputType = inputType;
11701168
// ask IME to avoid taking full screen on landscape mode
11711169
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
1170+
1171+
// add a listener for the layout chnages to the IME view
1172+
final android.view.View activityRootView = mActivity.getWindow().getDecorView();
1173+
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
1174+
@Override
1175+
public void onGlobalLayout() {
1176+
//send control sequence start /x04 == kayboard layout changed
1177+
nativeKey(45, 1, 4);
1178+
nativeKey(45, 0, 4);
1179+
}
1180+
});
11721181
return new BaseInputConnection(this, false){
11731182

11741183
private void deleteLastText(){

0 commit comments

Comments
 (0)