Move hideNavBar to java for native android keyboard
This commit is contained in:
parent
1814472214
commit
27f0f8c961
@ -3,6 +3,7 @@ package org.supertuxkart.stk_dbg;
|
||||
import android.app.NativeActivity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.KeyEvent;
|
||||
@ -14,6 +15,19 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
private native void saveFromJavaChars(String chars);
|
||||
private native void saveKeyboardHeight(int height);
|
||||
|
||||
private void hideNavBar(View decor_view)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < 19)
|
||||
return;
|
||||
decor_view.setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle instance)
|
||||
{
|
||||
@ -34,6 +48,18 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
saveKeyboardHeight(keyboard_height);
|
||||
}
|
||||
});
|
||||
|
||||
final View decor_view = getWindow().getDecorView();
|
||||
decor_view.setOnSystemUiVisibilityChangeListener(
|
||||
new View.OnSystemUiVisibilityChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility)
|
||||
{
|
||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
||||
hideNavBar(decor_view);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,6 +81,14 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean has_focus)
|
||||
{
|
||||
super.onWindowFocusChanged(has_focus);
|
||||
if (has_focus)
|
||||
hideNavBar(getWindow().getDecorView());
|
||||
}
|
||||
|
||||
public void showKeyboard()
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
|
@ -122,7 +122,7 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
||||
{
|
||||
Android->userData = this;
|
||||
Android->onAppCmd = handleAndroidCommand;
|
||||
Android->onAppCmdDirect = handleAndroidCommandDirect;
|
||||
Android->onAppCmdDirect = NULL;
|
||||
Android->onInputEvent = handleInput;
|
||||
|
||||
printConfig();
|
||||
@ -466,20 +466,6 @@ E_DEVICE_TYPE CIrrDeviceAndroid::getType() const
|
||||
return EIDT_ANDROID;
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::handleAndroidCommandDirect(ANativeActivity* activity,
|
||||
int32_t cmd)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case APP_CMD_RESUME:
|
||||
os::Printer::log("Android command direct APP_CMD_RESUME", ELL_DEBUG);
|
||||
hideNavBar(activity);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
|
||||
{
|
||||
CIrrDeviceAndroid* device = (CIrrDeviceAndroid *)app->userData;
|
||||
@ -1316,88 +1302,6 @@ wchar_t CIrrDeviceAndroid::getUnicodeChar(AInputEvent* event)
|
||||
return unicode_char;
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::hideNavBar(ANativeActivity* activity)
|
||||
{
|
||||
if (activity == NULL)
|
||||
return;
|
||||
|
||||
if (activity->sdkVersion < 19)
|
||||
return;
|
||||
|
||||
bool was_detached = false;
|
||||
JNIEnv* env = NULL;
|
||||
|
||||
jint status = activity->vm->GetEnv((void**)&env, JNI_VERSION_1_6);
|
||||
|
||||
if (status == JNI_EDETACHED)
|
||||
{
|
||||
JavaVMAttachArgs args;
|
||||
args.version = JNI_VERSION_1_6;
|
||||
args.name = "NativeThread";
|
||||
args.group = NULL;
|
||||
|
||||
status = activity->vm->AttachCurrentThread(&env, &args);
|
||||
was_detached = true;
|
||||
}
|
||||
|
||||
if (status != JNI_OK)
|
||||
{
|
||||
os::Printer::log("Cannot hide navbar.", ELL_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
jobject activity_obj = activity->clazz;
|
||||
|
||||
jclass activity_class = env->GetObjectClass(activity_obj);
|
||||
jclass window_class = env->FindClass("android/view/Window");
|
||||
jclass view_class = env->FindClass("android/view/View");
|
||||
|
||||
jmethodID get_window = env->GetMethodID(activity_class, "getWindow",
|
||||
"()Landroid/view/Window;");
|
||||
jmethodID get_decor_view = env->GetMethodID(window_class, "getDecorView",
|
||||
"()Landroid/view/View;");
|
||||
jmethodID set_system_ui_visibility = env->GetMethodID(view_class,
|
||||
"setSystemUiVisibility", "(I)V");
|
||||
|
||||
jobject window_obj = env->CallObjectMethod(activity_obj, get_window);
|
||||
jobject decor_view_obj = env->CallObjectMethod(window_obj, get_decor_view);
|
||||
|
||||
jfieldID fullscreen_field = env->GetStaticFieldID(view_class,
|
||||
"SYSTEM_UI_FLAG_FULLSCREEN", "I");
|
||||
jfieldID hide_navigation_field = env->GetStaticFieldID(view_class,
|
||||
"SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
|
||||
jfieldID immersive_sticky_field = env->GetStaticFieldID(view_class,
|
||||
"SYSTEM_UI_FLAG_IMMERSIVE_STICKY", "I");
|
||||
jfieldID layout_stable_field = env->GetStaticFieldID(view_class,
|
||||
"SYSTEM_UI_FLAG_LAYOUT_STABLE", "I");
|
||||
jfieldID layout_hide_navigation_field = env->GetStaticFieldID(view_class,
|
||||
"SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION", "I");
|
||||
jfieldID layout_fullscreen_field = env->GetStaticFieldID(view_class,
|
||||
"SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN", "I");
|
||||
|
||||
jint fullscreen = env->GetStaticIntField(view_class, fullscreen_field);
|
||||
jint hide_navigation = env->GetStaticIntField(view_class,
|
||||
hide_navigation_field);
|
||||
jint immersive_sticky = env->GetStaticIntField(view_class,
|
||||
immersive_sticky_field);
|
||||
jint layout_stable = env->GetStaticIntField(view_class,
|
||||
layout_stable_field);
|
||||
jint layout_hide_navigation = env->GetStaticIntField(view_class,
|
||||
layout_hide_navigation_field);
|
||||
jint layout_fullscreen = env->GetStaticIntField(view_class,
|
||||
layout_fullscreen_field);
|
||||
|
||||
jint flags = fullscreen | hide_navigation | immersive_sticky |
|
||||
layout_stable | layout_hide_navigation | layout_fullscreen;
|
||||
|
||||
env->CallVoidMethod(decor_view_obj, set_system_ui_visibility, flags);
|
||||
|
||||
if (was_detached)
|
||||
{
|
||||
activity->vm->DetachCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::toggleOnScreenKeyboard(bool show)
|
||||
{
|
||||
if (!Android)
|
||||
|
@ -174,14 +174,11 @@ namespace irr
|
||||
void createVideoModeList();
|
||||
wchar_t getKeyChar(SEvent& event);
|
||||
wchar_t getUnicodeChar(AInputEvent* event);
|
||||
static void hideNavBar(ANativeActivity* activity);
|
||||
static void readApplicationInfo(ANativeActivity* activity);
|
||||
int getRotation();
|
||||
DeviceOrientation getDefaultOrientation();
|
||||
video::SExposedVideoData& getExposedVideoData();
|
||||
|
||||
static void handleAndroidCommandDirect(ANativeActivity* activity,
|
||||
int32_t cmd);
|
||||
static void handleAndroidCommand(android_app* app, int32_t cmd);
|
||||
static s32 handleInput(android_app* app, AInputEvent* event);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user