Try to save keyboard height for moving screen with it later

This commit is contained in:
Benau 2019-05-19 17:41:51 +08:00
parent ede56a3cf8
commit 766c971339
3 changed files with 36 additions and 3 deletions

View File

@ -36,6 +36,7 @@
android:targetSdkVersion="26" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.software.leanback" android:required="false" />
<uses-feature android:name="android.software.input_methods" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

View File

@ -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

View File

@ -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