diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index 7a0fd8622..d6a5ba225 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -36,6 +36,7 @@
android:targetSdkVersion="26" />
+
diff --git a/android/src/main/java/SuperTuxKartActivity.java b/android/src/main/java/SuperTuxKartActivity.java
index 615af04ec..28b399805 100644
--- a/android/src/main/java/SuperTuxKartActivity.java
+++ b/android/src/main/java/SuperTuxKartActivity.java
@@ -2,19 +2,38 @@ package org.supertuxkart.stk_dbg;
import android.app.NativeActivity;
import android.content.Context;
+import android.graphics.Rect;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;
import android.view.KeyEvent;
+import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+import android.view.View;
public class SuperTuxKartActivity extends NativeActivity
{
private native void saveFromJavaChars(String chars);
+ private native void saveKeyboardHeight(int height);
@Override
public void onCreate(Bundle instance)
{
super.onCreate(instance);
System.loadLibrary("main");
+ final View root = getWindow().getDecorView().findViewById(
+ android.R.id.content);
+ root.getViewTreeObserver().addOnGlobalLayoutListener(new
+ OnGlobalLayoutListener()
+ {
+ @Override
+ public void onGlobalLayout()
+ {
+ Rect r = new Rect();
+ root.getWindowVisibleDisplayFrame(r);
+ int screen_height = root.getRootView().getHeight();
+ int keyboard_height = screen_height - (r.bottom);
+ saveKeyboardHeight(keyboard_height);
+ }
+ });
}
@Override
diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp
index d7656fc47..793d6c1e6 100644
--- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp
+++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp
@@ -26,11 +26,11 @@ std::string g_from_java_chars;
#error
#endif
-#define MAKE_ANDROID_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_saveFromJavaChars(JNIEnv* env, jobject this_obj, jstring from_java_chars)
-#define ANDROID_CALLBACK(PKG_NAME) MAKE_ANDROID_CALLBACK(PKG_NAME)
+#define MAKE_ANDROID_SAVE_CHARS_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_saveFromJavaChars(JNIEnv* env, jobject this_obj, jstring from_java_chars)
+#define ANDROID_SAVE_CHARS_CALLBACK(PKG_NAME) MAKE_ANDROID_SAVE_CHARS_CALLBACK(PKG_NAME)
extern "C"
-ANDROID_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME)
+ANDROID_SAVE_CHARS_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME)
{
if (from_java_chars == NULL)
return;
@@ -41,6 +41,19 @@ ANDROID_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME)
env->ReleaseStringUTFChars(from_java_chars, chars);
}
+// Call when android keyboard is opened or close, and save its height for
+// moving screen
+int g_keyboard_height = 0;
+
+#define MAKE_ANDROID_SAVE_KBD_HEIGHT_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_saveKeyboardHeight(JNIEnv* env, jobject this_obj, jint height)
+#define ANDROID_SAVE_KBD_HEIGHT_CALLBACK(PKG_NAME) MAKE_ANDROID_SAVE_KBD_HEIGHT_CALLBACK(PKG_NAME)
+
+extern "C"
+ANDROID_SAVE_KBD_HEIGHT_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME)
+{
+ g_keyboard_height = (int)height;
+}
+
namespace irr
{
namespace video