diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index 065297aa0..cf7e8f36a 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -1320,6 +1320,82 @@ void CIrrDeviceAndroid::hideNavBar(ANativeActivity* activity) } } +void CIrrDeviceAndroid::showKeyboard(bool show) +{ + bool was_detached = false; + JNIEnv* env = NULL; + + jint status = Android->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 = Android->activity->vm->AttachCurrentThread(&env, &args); + was_detached = true; + } + + if (status != JNI_OK) + { + os::Printer::log("Cannot show keyboard.", ELL_DEBUG); + return; + } + + jobject activity_obj = Android->activity->clazz; + jclass activity_class = env->GetObjectClass(activity_obj); + + jclass context = env->FindClass("android/content/Context"); + jfieldID im_service_field = env->GetStaticFieldID(context, + "INPUT_METHOD_SERVICE", "Ljava/lang/String;"); + jobject im_service_obj = env->GetStaticObjectField(context, + im_service_field); + + jclass im_manager = env->FindClass( + "android/view/inputmethod/InputMethodManager"); + jmethodID get_system_service = env->GetMethodID( activity_class, + "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); + jobject im_manager_obj = env->CallObjectMethod(activity_obj, + get_system_service, im_service_obj); + + jmethodID get_window = env->GetMethodID(activity_class, "getWindow", + "()Landroid/view/Window;"); + jobject window_obj = env->CallObjectMethod(activity_obj, get_window); + jclass window = env->FindClass("android/view/Window"); + jmethodID get_decor_view = env->GetMethodID(window, "getDecorView", + "()Landroid/view/View;"); + jobject decor_view_obj = env->CallObjectMethod(window_obj, get_decor_view); + + if (show) + { + jmethodID show_soft_input = env->GetMethodID(im_manager, + "showSoftInput", "(Landroid/view/View;I)Z"); + jint flags = 0; + jboolean result = env->CallBooleanMethod(im_manager_obj, + show_soft_input, decor_view_obj, flags); + } + else + { + jclass view = env->FindClass("android/view/View"); + jmethodID get_window_token = env->GetMethodID(view, "getWindowToken", + "()Landroid/os/IBinder;"); + jobject token = env->CallObjectMethod(decor_view_obj, get_window_token); + + jmethodID hide_soft_input = env->GetMethodID(im_manager, + "hideSoftInputFromWindow", "(Landroid/os/IBinder;I)Z"); + jint flags = 0; + jboolean result = env->CallBooleanMethod(im_manager_obj, + hide_soft_input, token, flags); + } + + if (was_detached) + { + Android->activity->vm->DetachCurrentThread(); + } +} + int CIrrDeviceAndroid::getRotation() { bool was_detached = false; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h index b3d8e2ff2..51f4a43ea 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h @@ -74,6 +74,7 @@ namespace irr virtual bool isGyroscopeActive(); virtual bool isGyroscopeAvailable(); virtual void setTextInputEnabled(bool enabled) {TextInputEnabled = enabled;} + virtual void showKeyboard(bool show); class CCursorControl : public gui::ICursorControl { diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 5df665ffa..26f5da36f 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -529,7 +529,7 @@ namespace UserConfigParams PARAM_DEFAULT( IntUserConfigParam(0, "screen_keyboard_mode", &m_multitouch_group, "Screen keyboard mode: 0 = disabled, 1 = enabled if no hardware " - "keyboard, 2 = always enabled") ); + "keyboard, 2 = always enabled, 3 = android keyboard (experimental)") ); PARAM_PREFIX BoolUserConfigParam m_hidpi_enabled PARAM_DEFAULT( BoolUserConfigParam(false, "hidpi_enabled", diff --git a/src/guiengine/screen_keyboard.cpp b/src/guiengine/screen_keyboard.cpp index 0a8230ce5..6da0e90a9 100644 --- a/src/guiengine/screen_keyboard.cpp +++ b/src/guiengine/screen_keyboard.cpp @@ -415,7 +415,7 @@ bool ScreenKeyboard::onEscapePressed() */ bool ScreenKeyboard::shouldUseScreenKeyboard() { - bool use_screen_keyboard = UserConfigParams::m_screen_keyboard > 1; + bool use_screen_keyboard = UserConfigParams::m_screen_keyboard == 2; #ifdef ANDROID if (UserConfigParams::m_screen_keyboard == 1) diff --git a/src/guiengine/widgets/CGUIEditBox.cpp b/src/guiengine/widgets/CGUIEditBox.cpp index f58314bd0..1d48b2da5 100644 --- a/src/guiengine/widgets/CGUIEditBox.cpp +++ b/src/guiengine/widgets/CGUIEditBox.cpp @@ -609,6 +609,15 @@ bool CGUIEditBox::processKey(const SEvent& event) } else { +#ifdef ANDROID + if (irr_driver->getDevice()->getType() == irr::EIDT_ANDROID && + UserConfigParams::m_screen_keyboard == 3) + { + CIrrDeviceAndroid* dl = dynamic_cast( + irr_driver->getDevice()); + dl->showKeyboard(false); + } +#endif sendGuiEvent( EGET_EDITBOX_ENTER ); } break; @@ -1296,6 +1305,17 @@ bool CGUIEditBox::processMouse(const SEvent& event) openScreenKeyboard(); return true; } +#ifdef ANDROID + else if (UserConfigParams::m_screen_keyboard == 3) + { + if (irr_driver->getDevice()->getType() == irr::EIDT_ANDROID) + { + CIrrDeviceAndroid* dl = dynamic_cast( + irr_driver->getDevice()); + dl->showKeyboard(true); + } + } +#endif else { // move cursor @@ -1756,9 +1776,12 @@ void CGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadW void CGUIEditBox::openScreenKeyboard() { + if (UserConfigParams::m_screen_keyboard == 3) + return; + if (GUIEngine::ScreenKeyboard::getCurrent() != NULL) return; - + CursorPos = Text.size(); setTextMarkers(CursorPos, CursorPos); calculateScrollPos();