Avoid updating editbox if hardware keyboard connected which discards all input
This commit is contained in:
parent
7174bcb741
commit
932f0f888e
@ -7,6 +7,7 @@ import android.content.ActivityNotFoundException;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -80,7 +81,7 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable edit)
|
public void afterTextChanged(Editable edit)
|
||||||
{
|
{
|
||||||
if (m_stk_edittext != null)
|
if (!isHardwareKeyboardConnected() && m_stk_edittext != null)
|
||||||
m_stk_edittext.updateSTKEditBox();
|
m_stk_edittext.updateSTKEditBox();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -146,7 +147,7 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
// Called when user change cursor / select all text in native android
|
// Called when user change cursor / select all text in native android
|
||||||
// keyboard
|
// keyboard
|
||||||
boolean ret = super.dispatchKeyEvent(event);
|
boolean ret = super.dispatchKeyEvent(event);
|
||||||
if (m_stk_edittext != null)
|
if (!isHardwareKeyboardConnected() && m_stk_edittext != null)
|
||||||
m_stk_edittext.updateSTKEditBox();
|
m_stk_edittext.updateSTKEditBox();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -265,4 +266,10 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
public boolean isHardwareKeyboardConnected()
|
||||||
|
{
|
||||||
|
return getResources().getConfiguration()
|
||||||
|
.keyboard == Configuration.KEYBOARD_QWERTY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1727,11 +1727,61 @@ bool CIrrDeviceAndroid::isGyroscopeAvailable()
|
|||||||
|
|
||||||
bool CIrrDeviceAndroid::hasHardwareKeyboard() const
|
bool CIrrDeviceAndroid::hasHardwareKeyboard() const
|
||||||
{
|
{
|
||||||
// This can happen when hosting server in android
|
|
||||||
if (!Android)
|
if (!Android)
|
||||||
return true;
|
return false;
|
||||||
int32_t keyboard = AConfiguration_getKeyboard(Android->config);
|
|
||||||
return (keyboard == ACONFIGURATION_KEYBOARD_QWERTY);
|
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 attach current thread in isHardwareKeyboardConnected.", ELL_DEBUG);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject native_activity = Android->activity->clazz;
|
||||||
|
jclass class_native_activity = env->GetObjectClass(native_activity);
|
||||||
|
|
||||||
|
if (class_native_activity == NULL)
|
||||||
|
{
|
||||||
|
os::Printer::log("isHardwareKeyboardConnected unable to find object class.", ELL_ERROR);
|
||||||
|
if (was_detached)
|
||||||
|
{
|
||||||
|
Android->activity->vm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
jmethodID method_id = env->GetMethodID(class_native_activity, "isHardwareKeyboardConnected", "()Z");
|
||||||
|
|
||||||
|
if (method_id == NULL)
|
||||||
|
{
|
||||||
|
os::Printer::log("isHardwareKeyboardConnected unable to find method id.", ELL_ERROR);
|
||||||
|
if (was_detached)
|
||||||
|
{
|
||||||
|
Android->activity->vm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = env->CallBooleanMethod(native_activity, method_id);
|
||||||
|
if (was_detached)
|
||||||
|
{
|
||||||
|
Android->activity->vm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user