Restore function for hardware keyboard on android
This commit is contained in:
parent
cecf5cffac
commit
8df28b07b1
@ -69,6 +69,7 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
|||||||
Gyroscope(0),
|
Gyroscope(0),
|
||||||
AccelerometerActive(false),
|
AccelerometerActive(false),
|
||||||
GyroscopeActive(false),
|
GyroscopeActive(false),
|
||||||
|
TextInputEnabled(false),
|
||||||
HasTouchDevice(false),
|
HasTouchDevice(false),
|
||||||
GamepadAxisX(0),
|
GamepadAxisX(0),
|
||||||
GamepadAxisY(0),
|
GamepadAxisY(0),
|
||||||
@ -682,6 +683,11 @@ s32 CIrrDeviceAndroid::handleKeyboard(AInputEvent* androidEvent)
|
|||||||
|
|
||||||
if (event.KeyInput.Key > 0)
|
if (event.KeyInput.Key > 0)
|
||||||
{
|
{
|
||||||
|
if (TextInputEnabled == true)
|
||||||
|
{
|
||||||
|
event.KeyInput.Char = getUnicodeChar(androidEvent);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.KeyInput.Char == 0)
|
if (event.KeyInput.Char == 0)
|
||||||
{
|
{
|
||||||
event.KeyInput.Char = getKeyChar(event);
|
event.KeyInput.Char = getKeyChar(event);
|
||||||
@ -1151,6 +1157,63 @@ wchar_t CIrrDeviceAndroid::getKeyChar(SEvent& event)
|
|||||||
return key_char;
|
return key_char;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wchar_t CIrrDeviceAndroid::getUnicodeChar(AInputEvent* event)
|
||||||
|
{
|
||||||
|
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 get unicode character.", ELL_DEBUG);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
jlong down_time = AKeyEvent_getDownTime(event);
|
||||||
|
jlong event_time = AKeyEvent_getEventTime(event);
|
||||||
|
jint action = AKeyEvent_getAction(event);
|
||||||
|
jint code = AKeyEvent_getKeyCode(event);
|
||||||
|
jint repeat = AKeyEvent_getRepeatCount(event);
|
||||||
|
jint meta_state = AKeyEvent_getMetaState(event);
|
||||||
|
jint device_id = AInputEvent_getDeviceId(event);
|
||||||
|
jint scan_code = AKeyEvent_getScanCode(event);
|
||||||
|
jint flags = AKeyEvent_getFlags(event);
|
||||||
|
jint source = AInputEvent_getSource(event);
|
||||||
|
|
||||||
|
jclass key_event = env->FindClass("android/view/KeyEvent");
|
||||||
|
jmethodID key_event_constructor = env->GetMethodID(key_event, "<init>",
|
||||||
|
"(JJIIIIIIII)V");
|
||||||
|
|
||||||
|
jobject key_event_obj = env->NewObject(key_event, key_event_constructor,
|
||||||
|
down_time, event_time, action, code,
|
||||||
|
repeat, meta_state, device_id,
|
||||||
|
scan_code, flags, source);
|
||||||
|
|
||||||
|
jmethodID get_unicode = env->GetMethodID(key_event, "getUnicodeChar", "(I)I");
|
||||||
|
|
||||||
|
wchar_t unicode_char = env->CallIntMethod(key_event_obj, get_unicode,
|
||||||
|
meta_state);
|
||||||
|
|
||||||
|
if (was_detached)
|
||||||
|
{
|
||||||
|
Android->activity->vm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
return unicode_char;
|
||||||
|
}
|
||||||
|
|
||||||
void CIrrDeviceAndroid::openURL(const std::string& url)
|
void CIrrDeviceAndroid::openURL(const std::string& url)
|
||||||
{
|
{
|
||||||
if (!Android)
|
if (!Android)
|
||||||
|
@ -72,6 +72,7 @@ namespace irr
|
|||||||
virtual bool deactivateGyroscope();
|
virtual bool deactivateGyroscope();
|
||||||
virtual bool isGyroscopeActive();
|
virtual bool isGyroscopeActive();
|
||||||
virtual bool isGyroscopeAvailable();
|
virtual bool isGyroscopeAvailable();
|
||||||
|
virtual void setTextInputEnabled(bool enabled) {TextInputEnabled = enabled;}
|
||||||
void fromSTKEditBox(int widget_id, const core::stringw& text, int selection_start, int selection_end, int type);
|
void fromSTKEditBox(int widget_id, const core::stringw& text, int selection_start, int selection_end, int type);
|
||||||
virtual void toggleOnScreenKeyboard(bool show, s32 type = 0);
|
virtual void toggleOnScreenKeyboard(bool show, s32 type = 0);
|
||||||
virtual bool supportsTouchDevice() const { return HasTouchDevice; }
|
virtual bool supportsTouchDevice() const { return HasTouchDevice; }
|
||||||
@ -101,6 +102,7 @@ namespace irr
|
|||||||
const ASensor* Gyroscope;
|
const ASensor* Gyroscope;
|
||||||
bool AccelerometerActive;
|
bool AccelerometerActive;
|
||||||
bool GyroscopeActive;
|
bool GyroscopeActive;
|
||||||
|
bool TextInputEnabled;
|
||||||
static AndroidApplicationInfo ApplicationInfo;
|
static AndroidApplicationInfo ApplicationInfo;
|
||||||
|
|
||||||
static bool IsPaused;
|
static bool IsPaused;
|
||||||
@ -131,6 +133,7 @@ namespace irr
|
|||||||
void createKeyMap();
|
void createKeyMap();
|
||||||
void createVideoModeList();
|
void createVideoModeList();
|
||||||
wchar_t getKeyChar(SEvent& event);
|
wchar_t getKeyChar(SEvent& event);
|
||||||
|
wchar_t getUnicodeChar(AInputEvent* event);
|
||||||
static void readApplicationInfo(ANativeActivity* activity);
|
static void readApplicationInfo(ANativeActivity* activity);
|
||||||
int getRotation();
|
int getRotation();
|
||||||
DeviceOrientation getDefaultOrientation();
|
DeviceOrientation getDefaultOrientation();
|
||||||
|
@ -244,6 +244,14 @@ CGUIEditBox::~CGUIEditBox()
|
|||||||
}
|
}
|
||||||
#elif defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
|
#elif defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
|
||||||
DestroyCaret();
|
DestroyCaret();
|
||||||
|
#endif
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (irr_driver->getDevice()->getType() == irr::EIDT_ANDROID)
|
||||||
|
{
|
||||||
|
CIrrDeviceAndroid* dl = dynamic_cast<CIrrDeviceAndroid*>(
|
||||||
|
irr_driver->getDevice());
|
||||||
|
dl->setTextInputEnabled(false);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (GUIEngine::ScreenKeyboard::shouldUseScreenKeyboard() &&
|
if (GUIEngine::ScreenKeyboard::shouldUseScreenKeyboard() &&
|
||||||
GUIEngine::ScreenKeyboard::hasSystemScreenKeyboard())
|
GUIEngine::ScreenKeyboard::hasSystemScreenKeyboard())
|
||||||
@ -361,6 +369,14 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
|
|||||||
}
|
}
|
||||||
#elif defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
|
#elif defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
|
||||||
DestroyCaret();
|
DestroyCaret();
|
||||||
|
#endif
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (irr_driver->getDevice()->getType() == irr::EIDT_ANDROID)
|
||||||
|
{
|
||||||
|
CIrrDeviceAndroid* dl = dynamic_cast<CIrrDeviceAndroid*>(
|
||||||
|
irr_driver->getDevice());
|
||||||
|
dl->setTextInputEnabled(false);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
m_from_android_edittext = false;
|
m_from_android_edittext = false;
|
||||||
m_composing_start = 0;
|
m_composing_start = 0;
|
||||||
@ -380,6 +396,13 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
|
|||||||
#endif
|
#endif
|
||||||
calculateScrollPos();
|
calculateScrollPos();
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
if (irr_driver->getDevice()->getType() == irr::EIDT_ANDROID)
|
||||||
|
{
|
||||||
|
CIrrDeviceAndroid* dl = dynamic_cast<CIrrDeviceAndroid*>(
|
||||||
|
irr_driver->getDevice());
|
||||||
|
dl->setTextInputEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (GUIEngine::ScreenKeyboard::shouldUseScreenKeyboard() &&
|
if (GUIEngine::ScreenKeyboard::shouldUseScreenKeyboard() &&
|
||||||
GUIEngine::ScreenKeyboard::hasSystemScreenKeyboard() &&
|
GUIEngine::ScreenKeyboard::hasSystemScreenKeyboard() &&
|
||||||
irr_driver->getDevice()->getType() == irr::EIDT_ANDROID)
|
irr_driver->getDevice()->getType() == irr::EIDT_ANDROID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user